9 yaml_parser_set_reader_error(
yaml_parser_t *parser,
const char *problem,
10 size_t offset,
int value);
26 yaml_parser_set_reader_error(
yaml_parser_t *parser,
const char *problem,
27 size_t offset,
int value)
41 #define BOM_UTF8 "\xef\xbb\xbf" 42 #define BOM_UTF16LE "\xff\xfe" 43 #define BOM_UTF16BE "\xfe\xff" 57 if (!yaml_parser_update_raw_buffer(parser)) {
106 if (parser->
eof)
return 1;
123 return yaml_parser_set_reader_error(parser,
"input error",
155 if (parser->
unread >= length)
161 if (!yaml_parser_determine_encoding(parser))
181 while (parser->
unread < length)
186 if (!yaml_parser_update_raw_buffer(parser))
return 0;
194 unsigned int value = 0, value2 = 0;
197 unsigned int width = 0;
231 width = (octet & 0x80) == 0x00 ? 1 :
232 (octet & 0xE0) == 0xC0 ? 2 :
233 (octet & 0xF0) == 0xE0 ? 3 :
234 (octet & 0xF8) == 0xF0 ? 4 : 0;
239 return yaml_parser_set_reader_error(parser,
240 "invalid leading UTF-8 octet",
245 if (width > raw_unread) {
247 return yaml_parser_set_reader_error(parser,
248 "incomplete UTF-8 octet sequence",
257 value = (octet & 0x80) == 0x00 ? octet & 0x7F :
258 (octet & 0xE0) == 0xC0 ? octet & 0x1F :
259 (octet & 0xF0) == 0xE0 ? octet & 0x0F :
260 (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0;
264 for (k = 1; k < width; k ++)
270 if ((octet & 0xC0) != 0x80)
271 return yaml_parser_set_reader_error(parser,
272 "invalid trailing UTF-8 octet",
277 value = (value << 6) + (octet & 0x3F);
282 if (!((width == 1) ||
283 (width == 2 && value >= 0x80) ||
284 (width == 3 && value >= 0x800) ||
285 (width == 4 && value >= 0x10000)))
286 return yaml_parser_set_reader_error(parser,
287 "invalid length of a UTF-8 sequence",
292 if ((value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF)
293 return yaml_parser_set_reader_error(parser,
294 "invalid Unicode character",
333 if (raw_unread < 2) {
335 return yaml_parser_set_reader_error(parser,
336 "incomplete UTF-16 character",
350 if ((value & 0xFC00) == 0xDC00)
351 return yaml_parser_set_reader_error(parser,
352 "unexpected low surrogate area",
357 if ((value & 0xFC00) == 0xD800) {
363 if (raw_unread < 4) {
365 return yaml_parser_set_reader_error(parser,
366 "incomplete UTF-16 surrogate pair",
380 if ((value2 & 0xFC00) != 0xDC00)
381 return yaml_parser_set_reader_error(parser,
382 "expected low surrogate area",
383 parser->
offset+2, value2);
387 value = 0x10000 + ((value & 0x3FF) << 10) + (value2 & 0x3FF);
402 if (incomplete)
break;
411 if (! (value == 0x09 || value == 0x0A || value == 0x0D
412 || (value >= 0x20 && value <= 0x7E)
413 || (value == 0x85) || (value >= 0xA0 && value <= 0xD7FF)
414 || (value >= 0xE000 && value <= 0xFFFD)
415 || (value >= 0x10000 && value <= 0x10FFFF)))
416 return yaml_parser_set_reader_error(parser,
417 "control characters are not allowed",
432 else if (value <= 0x7FF) {
433 *(parser->
buffer.
last++) = 0xC0 + (value >> 6);
434 *(parser->
buffer.
last++) = 0x80 + (value & 0x3F);
437 else if (value <= 0xFFFF) {
438 *(parser->
buffer.
last++) = 0xE0 + (value >> 12);
439 *(parser->
buffer.
last++) = 0x80 + ((value >> 6) & 0x3F);
440 *(parser->
buffer.
last++) = 0x80 + (value & 0x3F);
444 *(parser->
buffer.
last++) = 0xF0 + (value >> 18);
445 *(parser->
buffer.
last++) = 0x80 + ((value >> 12) & 0x3F);
446 *(parser->
buffer.
last++) = 0x80 + ((value >> 6) & 0x3F);
447 *(parser->
buffer.
last++) = 0x80 + (value & 0x3F);
464 return yaml_parser_set_reader_error(parser,
"input is too long",
yaml_char_t * last
The last filled position of the buffer.
The UTF-16-BE encoding with BOM.
int problem_value
The problematic value (-1 is none).
yaml_encoding_t encoding
The input encoding.
const unsigned char * end
The string end pointer.
struct yaml_parser_s::@36 raw_buffer
The raw buffer.
void * read_handler_data
A pointer for passing to the read handler.
const unsigned char * start
The string start pointer.
yaml_char_t * pointer
The current position of the buffer.
The UTF-16-LE encoding with BOM.
yaml_read_handler_t * read_handler
Read handler.
Cannot read or decode the input stream.
#define YAML_DECLARE(type)
The public API declaration.
yaml_error_type_t error
Error type.
struct yaml_parser_s::@35 buffer
The working buffer.
size_t offset
The offset of the current position (in bytes).
The default UTF-8 encoding.
size_t problem_offset
The byte about which the problem occured.
const char * problem
Error description.
yaml_parser_update_buffer(yaml_parser_t *parser, size_t length)