1#ifndef _C4_YML_NODE_TYPE_HPP_
4#ifndef _C4_YML_ERROR_HPP_
74 #define _prflag(fl, txt) \
76 if((flags & (fl)) == (fl)) \
80 if(pos + 1 < buf.len) \
84 csubstr fltxt = txt; \
85 if(pos + fltxt.len <= buf.len) \
86 memcpy(buf.str + pos, fltxt.str, fltxt.len); \
89 flags = (flags & ~(fl)); \
143 for(
size_t i = 0; i < s.len; ++i)
145 if(s.str[i] ==
'\n' && i + 1 < s.len)
147 char next = s.str[i + 1];
148 if(next ==
' ' || next ==
'\t')
156bool _is_wsnl(
char c)
noexcept
158 return c ==
' ' || c ==
'\n' || c ==
'\t' || c ==
'\r';
160bool _is_valid_bulk(
csubstr s,
size_t i)
162 C4_ASSERT(i >= 1 && i+1 < s.len);
163 C4_ASSERT(s.str[i] ==
':' || s.str[i] ==
'#');
166 case ':':
return !_is_wsnl(s.str[i+1]);
167 case '#':
return !_is_wsnl(s.str[i-1]);
180 case ' ':
case '\n':
case '\t':
case '\r':
181 case '!':
case '&':
case '*':
case ',':
182 case '"':
case '\'':
case '|':
case '>':
183 case '{':
case '}':
case '[':
case ']':
184 case '#':
case '`':
case '%':
case '@':
186 case '-':
case ':':
case '?':
187 if(s.len == 1 || (s.str[1] ==
' ' || s.str[1] ==
'\t'))
192 for(
size_t i = 1; i + 1 < s.len; ++i)
196 case ',':
case '{':
case '}':
case '[':
case ']':
199 if(!_is_valid_bulk(s, i))
209 case ' ':
case '\n':
case '\t':
case '\r':
228 case ' ':
case '\n':
case '\t':
case '\r':
229 case '!':
case '&':
case '*':
case ',':
230 case '"':
case '\'':
case '|':
case '>':
231 case '{':
case '}':
case '[':
case ']':
232 case '#':
case '`':
case '%':
case '@':
234 case '-':
case ':':
case '?':
235 if (s.len == 1 || (s.str[1] ==
' ' || s.str[1] ==
'\t'))
240 for(
size_t i = 1; i + 1 < s.len; ++i)
245 if(!_is_valid_bulk(s, i))
255 case ' ':
case '\n':
case '\t':
case '\r':
284 &&
"if this assertion fires, please submit an issue!");
293 return s.str ==
nullptr ||
294 (s.len == 1 && (s.str[0] ==
'~')) ||
295 (s.len == 4 && ((0 == memcmp(
"null", s.str, 4))
296 || (0 == memcmp(
"Null", s.str, 4))
297 || (0 == memcmp(
"NULL", s.str, 4))));
305#define rest_is(c1, c2) ((s.str[1] == (c1)) && (s.str[2] == (c2)))
306bool is_inf_or_nan(
csubstr s)
noexcept
308 _RYML_ASSERT_BASIC(!s.begins_with(
"-."));
309 _RYML_ASSERT_BASIC(!s.begins_with(
"+."));
310 _RYML_ASSERT_BASIC(!s.begins_with(
"."));
311 _RYML_ASSERT_BASIC(s.len == 3);
314 case 'i':
return rest_is(
'n',
'f');
316 case 'n':
return rest_is(
'a',
'n');
323 _RYML_ASSERT_BASIC(!s.begins_with(
"-."));
324 _RYML_ASSERT_BASIC(!s.begins_with(
"+."));
325 _RYML_ASSERT_BASIC(!s.begins_with(
"."));
326 _RYML_ASSERT_BASIC(s.len == 3);
329 case 'i':
return rest_is(
'n',
'f');
336bool json_is_plain_number(
csubstr s)
noexcept
343 (!(s.len > 1 && s.begins_with(
'0')))
349bool json_is_special_scalar(
csubstr s)
noexcept
352 return 0 == memcmp(
"true", s.str, 4)
353 || 0 == memcmp(
"null", s.str, 4)
354 || (s[0] ==
'.' && is_inf_or_nan(s.sub(1)));
356 return 0 == memcmp(
"false", s.str, 5)
357 || ((s[0] ==
'-' || s[0] ==
'+') && s[1] ==
'.' && is_inf(s.sub(2)));
Error utilities used by ryml.
bool scalar_style_query_plain_block(csubstr s) noexcept
query whether a scalar can be encoded using plain style while in block mode.
bool scalar_is_null(csubstr s) noexcept
YAML-sense query of nullity.
bool scalar_style_query_squo(csubstr s) noexcept
query whether a scalar can be encoded using single quotes.
NodeType_e scalar_style_choose_flow(csubstr s) noexcept
choose a YAML scalar style based on the scalar's contents, while in flow mode.
NodeType_e scalar_style_choose_block(csubstr s) noexcept
choose a YAML scalar style based on the scalar's contents, while in block mode.
bool scalar_style_query_plain_flow(csubstr s) noexcept
query whether a scalar can be encoded using plain style while in flow mode.
NodeType_e
a bit mask for marking node types and styles
NodeType_e scalar_style_choose_json(csubstr s) noexcept
choose a json scalar style based on the scalar's contents
@ VALANCH
the val has an &anchor
@ NOTYPE
no node type or style is set
@ KEY_DQUO
mark key scalar as double quoted "
@ VALREF
a *reference: the val references an &anchor
@ VALNIL
the val is null (eg {a : } results in a null val)
@ MAP
a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
@ STREAM
a stream: a seq of docs
@ KEY
the scalar to the left of : in a map's member
@ FLOW_ML1
mark container with multi-line flow style, 1 element per line
@ VAL_FOLDED
mark val scalar as multiline, block folded >
@ KEYTAG
the key has a tag
@ SCALAR_SQUO
mask of KEY_SQUO|VAL_SQUO,
@ FLOW_SL
mark container with single-line flow style
@ VAL_UNFILT
the val scalar was left unfiltered; the parser was set not to filter.
@ VAL
a scalar: has a scalar (ie string) value, possibly empty. must be a leaf node, and cannot be MAP or S...
@ VALTAG
the val has a tag
@ _TYMASK
all the bits up to here
@ FLOW_MLN
mark container with multi-line flow style, n elements per line, wrapped (as set by EmitOptions::max_c...
@ SEQ
a seq: a parent of VAL/SEQ/MAP nodes
@ SCALAR_DQUO
mask of KEY_DQUO|VAL_DQUO,
@ VAL_SQUO
mark val scalar as single quoted '
@ VAL_PLAIN
mark val scalar as plain scalar (unquoted, even when multiline)
@ KEYREF
a *reference: the key references an &anchor
@ BLOCK
mark container with block style
@ FLOW_SPC
mark container with spaces after comma when in flow mode. Applies to both FLOW_SL and FLOW_MLN (but n...
@ KEYANCH
the key has an &anchor
@ VAL_DQUO
mark val scalar as double quoted "
@ KEY_UNFILT
the key scalar was left unfiltered; the parser was set not to filter.
@ KEY_SQUO
mark key scalar as single quoted '
@ VAL_LITERAL
mark val scalar as multiline, block literal |
@ KEY_LITERAL
mark key scalar as multiline, block literal |
@ KEY_PLAIN
mark key scalar as plain scalar (unquoted, even when multiline)
@ SCALAR_PLAIN
mask of KEY_PLAIN|VAL_PLAIN,
@ KEY_FOLDED
mark key scalar as multiline, block folded >
@ KEYNIL
the key is null (eg { : b} results in a null key)
basic_substring< char > substr
a mutable string view
basic_substring< const char > csubstr
an immutable string view
(Undefined by default) Use shorter error message from checks/asserts: do not show the check condition...
const char * type_str() const noexcept
return a preset string based on the node type