Ensure that the buffer contains at least `length` characters. Return true on success, false on failure. The length is supposed to be significantly less that the buffer size.
(parser *yaml_parser_t, length int)
| 111 | // |
| 112 | // The length is supposed to be significantly less that the buffer size. |
| 113 | func yaml_parser_update_buffer(parser *yaml_parser_t, length int) bool { |
| 114 | if parser.read_handler == nil { |
| 115 | panic("read handler must be set") |
| 116 | } |
| 117 | |
| 118 | // [Go] This function was changed to guarantee the requested length size at EOF. |
| 119 | // The fact we need to do this is pretty awful, but the description above implies |
| 120 | // for that to be the case, and there are tests |
| 121 | |
| 122 | // If the EOF flag is set and the raw buffer is empty, do nothing. |
| 123 | if parser.eof && parser.raw_buffer_pos == len(parser.raw_buffer) { |
| 124 | // [Go] ACTUALLY! Read the documentation of this function above. |
| 125 | // This is just broken. To return true, we need to have the |
| 126 | // given length in the buffer. Not doing that means every single |
| 127 | // check that calls this function to make sure the buffer has a |
| 128 | // given length is Go) panicking; or C) accessing invalid memory. |
| 129 | //return true |
| 130 | } |
| 131 | |
| 132 | // Return if the buffer contains enough characters. |
| 133 | if parser.unread >= length { |
| 134 | return true |
| 135 | } |
| 136 | |
| 137 | // Determine the input encoding if it is not known yet. |
| 138 | if parser.encoding == yaml_ANY_ENCODING { |
| 139 | if !yaml_parser_determine_encoding(parser) { |
| 140 | return false |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | // Move the unread characters to the beginning of the buffer. |
| 145 | buffer_len := len(parser.buffer) |
| 146 | if parser.buffer_pos > 0 && parser.buffer_pos < buffer_len { |
| 147 | copy(parser.buffer, parser.buffer[parser.buffer_pos:]) |
| 148 | buffer_len -= parser.buffer_pos |
| 149 | parser.buffer_pos = 0 |
| 150 | } else if parser.buffer_pos == buffer_len { |
| 151 | buffer_len = 0 |
| 152 | parser.buffer_pos = 0 |
| 153 | } |
| 154 | |
| 155 | // Open the whole buffer for writing, and cut it before returning. |
| 156 | parser.buffer = parser.buffer[:cap(parser.buffer)] |
| 157 | |
| 158 | // Fill the buffer until it has enough characters. |
| 159 | first := true |
| 160 | for parser.unread < length { |
| 161 | |
| 162 | // Fill the raw buffer if necessary. |
| 163 | if !first || parser.raw_buffer_pos == len(parser.raw_buffer) { |
| 164 | if !yaml_parser_update_raw_buffer(parser) { |
| 165 | parser.buffer = parser.buffer[:buffer_len] |
| 166 | return false |
| 167 | } |
| 168 | } |
| 169 | first = false |
| 170 |
no test coverage detected