3#include "c4/yml/detail/dbgprint.hpp"
10C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH(
"-Wold-style-cast")
19C4_ALWAYS_INLINE
bool _is_idchar(
char c)
21 return (c >=
'a' && c <=
'z')
22 || (c >=
'A' && c <=
'Z')
23 || (c >=
'0' && c <=
'9')
24 || (c ==
'_' || c ==
'-' || c ==
'~' || c ==
'$');
27enum _ppstate :
int { kReadPending = 0, kKeyPending = 1, kValPending = 2 };
28C4_ALWAYS_INLINE _ppstate _next(_ppstate s)
31 return (_ppstate)(n <= (int)kValPending ? n : 0);
40 detail::_SubstrWriter writer(buf);
41 _ppstate state = kReadPending;
52 for(
size_t i = 0; i < s.
len; ++i)
54 const char curr = s[i];
55 const char next = i+1 < s.
len ? s[i+1] :
'\0';
57 if(curr ==
'\'' || curr ==
'"')
60 i +=
static_cast<size_t>(ss.
end() - (s.
str + i));
63 else if(state == kReadPending && _is_idchar(curr))
72 if(curr ==
':' && next ==
' ')
76 else if(curr ==
',' && next ==
' ')
78 writer.append(s.
range(last, i));
79 writer.append(
": 1, ");
86 if(curr ==
'[' || curr ==
'{' || curr ==
'(')
89 i +=
static_cast<size_t>(ss.
end() - (s.
str + i));
92 else if(curr ==
',' && next ==
' ')
104 writer.append(s.
sub(last));
105 if(state == kKeyPending)
106 writer.append(
": 1");
113C4_SUPPRESS_WARNING_GCC_CLANG_POP
Error utilities used by ryml.
size_t preprocess_rxmap(csubstr s, substr buf)
Write into a given output buffer.
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...
Functions for preprocessing YAML prior to parsing.
basic_substring range(size_t first, size_t last=npos) const noexcept
return [first,last[.
bool begins_with(const C c) const noexcept
true if the first character of the string is c
basic_substring offs(size_t left, size_t right) const noexcept
offset from the ends: return [left,len-right[ ; ie, trim a number of characters from the left and rig...
basic_substring pair_range_esc(CC open_close, CC escape=CC('\\'))
get the range delimited by a single open-close character (eg, quotes).
size_t len
the length of the substring
bool ends_with(const C c) const noexcept
true if the last character of the string is c
basic_substring pair_range_nested(CC open, CC close) const
get the range delimited by an open-close pair of characters, with possibly nested occurrences.
basic_substring sub(size_t first) const noexcept
return [first,len[
C * str
a restricted pointer to the first character of the substring