2 #include "c4/yml/detail/parser_dbg.hpp"
9 C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH(
"-Wold-style-cast")
16 C4_ALWAYS_INLINE
bool _is_idchar(
char c)
18 return (c >=
'a' && c <=
'z')
19 || (c >=
'A' && c <=
'Z')
20 || (c >=
'0' && c <=
'9')
21 || (c ==
'_' || c ==
'-' || c ==
'~' || c ==
'$');
24 typedef enum { kReadPending = 0, kKeyPending = 1, kValPending = 2 } _ppstate;
25 C4_ALWAYS_INLINE _ppstate _next(_ppstate s)
28 return (_ppstate)(n <= (int)kValPending ? n : 0);
37 detail::_SubstrWriter writer(buf);
38 _ppstate state = kReadPending;
41 if(s.begins_with(
'{'))
43 RYML_CHECK(s.ends_with(
'}'));
49 for(
size_t i = 0; i < s.len; ++i)
51 const char curr = s[i];
52 const char next = i+1 < s.len ? s[i+1] :
'\0';
54 if(curr ==
'\'' || curr ==
'"')
56 csubstr ss = s.sub(i).pair_range_esc(curr,
'\\');
57 i +=
static_cast<size_t>(ss.end() - (s.str + i));
60 else if(state == kReadPending && _is_idchar(curr))
69 if(curr ==
':' && next ==
' ')
73 else if(curr ==
',' && next ==
' ')
75 writer.append(s.range(last, i));
76 writer.append(
": 1, ");
83 if(curr ==
'[' || curr ==
'{' || curr ==
'(')
85 csubstr ss = s.sub(i).pair_range_nested(curr,
'\\');
86 i +=
static_cast<size_t>(ss.end() - (s.str + i));
89 else if(curr ==
',' && next ==
' ')
101 writer.append(s.sub(last));
102 if(state == kKeyPending)
103 writer.append(
": 1");
109 C4_SUPPRESS_WARNING_GCC_CLANG_POP
size_t preprocess_rxmap(csubstr s, substr buf)
Write into a given output buffer.
Functions for preprocessing YAML prior to parsing.