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)); \
141 for(
size_t i = 0; i < s.len; ++i)
143 if(s.str[i] ==
'\n' && i + 1 < s.len)
145 char next = s.str[i + 1];
146 if(next ==
' ' || next ==
'\t')
154 bool _is_wsnl(
char c) noexcept
156 return c ==
' ' || c ==
'\n' || c ==
'\t' || c ==
'\r';
158 bool _is_valid_bulk(csubstr s,
size_t i)
160 C4_ASSERT(i >= 1 && i+1 < s.len);
161 C4_ASSERT(s.str[i] ==
':' || s.str[i] ==
'#');
164 case ':':
return !_is_wsnl(s.str[i+1]);
165 case '#':
return !_is_wsnl(s.str[i-1]);
178 case ' ':
case '\n':
case '\t':
case '\r':
179 case '!':
case '&':
case '*':
case ',':
180 case '"':
case '\'':
case '|':
case '>':
181 case '{':
case '}':
case '[':
case ']':
182 case '#':
case '`':
case '%':
case '@':
184 case '-':
case ':':
case '?':
185 if(s.len == 1 || (s.str[1] ==
' ' || s.str[1] ==
'\t'))
190 for(
size_t i = 1; i + 1 < s.len; ++i)
194 case ',':
case '{':
case '}':
case '[':
case ']':
197 if(!_is_valid_bulk(s, i))
207 case ' ':
case '\n':
case '\t':
case '\r':
226 case ' ':
case '\n':
case '\t':
case '\r':
227 case '!':
case '&':
case '*':
case ',':
228 case '"':
case '\'':
case '|':
case '>':
229 case '{':
case '}':
case '[':
case ']':
230 case '#':
case '`':
case '%':
case '@':
232 case '-':
case ':':
case '?':
233 if (s.len == 1 || (s.str[1] ==
' ' || s.str[1] ==
'\t'))
238 for(
size_t i = 1; i + 1 < s.len; ++i)
243 if(!_is_valid_bulk(s, i))
253 case ' ':
case '\n':
case '\t':
case '\r':
282 &&
"if this assertion fires, please submit an issue!");
291 return s.str ==
nullptr ||
292 (s.len == 1 && (s.str[0] ==
'~')) ||
293 (s.len == 4 && ((0 == memcmp(
"null", s.str, 4))
294 || (0 == memcmp(
"Null", s.str, 4))
295 || (0 == memcmp(
"NULL", s.str, 4))));
303 #define rest_is(c1, c2) ((s.str[1] == (c1)) && (s.str[2] == (c2)))
304 bool is_inf_or_nan(csubstr s) noexcept
306 _RYML_ASSERT_BASIC(!s.begins_with(
"-."));
307 _RYML_ASSERT_BASIC(!s.begins_with(
"+."));
308 _RYML_ASSERT_BASIC(!s.begins_with(
"."));
309 _RYML_ASSERT_BASIC(s.len == 3);
312 case 'i':
return rest_is(
'n',
'f');
314 case 'n':
return rest_is(
'a',
'n');
319 bool is_inf(csubstr s) noexcept
321 _RYML_ASSERT_BASIC(!s.begins_with(
"-."));
322 _RYML_ASSERT_BASIC(!s.begins_with(
"+."));
323 _RYML_ASSERT_BASIC(!s.begins_with(
"."));
324 _RYML_ASSERT_BASIC(s.len == 3);
327 case 'i':
return rest_is(
'n',
'f');
334 bool json_is_plain_number(csubstr s) noexcept
341 (!(s.len > 1 && s.begins_with(
'0')))
347 bool json_is_special_scalar(csubstr s) noexcept
350 return 0 == memcmp(
"true", s.str, 4)
351 || 0 == memcmp(
"null", s.str, 4)
352 || (s[0] ==
'.' && is_inf_or_nan(s.sub(1)));
354 return 0 == memcmp(
"false", s.str, 5)
355 || ((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
@ VAL_FOLDED
mark val scalar as multiline, block folded >
@ KEYTAG
the key has a tag
@ FLOW_SL
mark container with single-line flow style (seqs as '[val1,val2], maps as '{key: val,...
@ FLOW_ML
mark container with multi-line flow style (seqs as '[ val1, val2 ], maps as '{ key: val,...
@ 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
@ SEQ
a seq: a parent of VAL/SEQ/MAP nodes
@ 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 (seqs as '- val ', maps as 'key: val')
@ 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)
@ KEY_FOLDED
mark key scalar as multiline, block folded >
@ KEYNIL
the key is null (eg { : b} results in a null key)
@ npos
a null string position
(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