1 #ifndef _C4_YML_ESCAPE_SCALAR_HPP_
2 #define _C4_YML_ESCAPE_SCALAR_HPP_
4 #ifndef _C4_YML_COMMON_HPP_
58 uint8_t
const* C4_RESTRICT s =
reinterpret_cast<uint8_t const*
>(scalar.str);
60 for(
size_t i = 0; i < scalar.len; ++i)
109 if(s[i+1] == UINT8_C(0xa0))
115 else if(s[i+1] == UINT8_C(0x85))
126 if(s[i+1] == UINT8_C(0x80))
128 if(s[i+2] == UINT8_C(0xa8))
134 else if(s[i+2] == UINT8_C(0xa9))
147 std::forward<Fn>(fn)(scalar.range(prev, i));
148 std::forward<Fn>(fn)(repl);
151 std::forward<Fn>(fn)(
"\n");
157 if(scalar.len > prev)
158 std::forward<Fn>(fn)(scalar.sub(prev));
163 C4_SUPPRESS_WARNING_GCC_WITH_PUSH(
"-Wattributes")
176 uint8_t
const* C4_RESTRICT s =
reinterpret_cast<uint8_t const*
>(scalar.str);
177 const size_t newbump = keep_newlines ? 2 : 1;
179 size_t excess = pos > scalar.len ? pos - scalar.len : 0;
180 pos = pos < scalar.len ? pos : scalar.len;
181 for(
size_t i = 0; i < pos; ++i)
203 if(s[i+1] == UINT8_C(0xa0)
205 s[i+1] == UINT8_C(0x85))
215 if(s[i+1] == UINT8_C(0x80))
217 if(s[i+2] == UINT8_C(0xa8)
219 s[i+2] == UINT8_C(0xa9))
241 inline C4_NO_INLINE
size_t escape_scalar(substr buffer, csubstr scalar,
bool keep_newlines=
false)
244 auto append_ = [&pos, &buffer](csubstr repl){
245 if(repl.len && (pos + repl.len <= buffer.len))
246 memcpy(buffer.str + pos, repl.str, repl.len);
252 C4_SUPPRESS_WARNING_GCC_POP
269 template<
class SinkPfn>
273 C4_ASSERT(!buf.overlaps(e.
scalar));
Common utilities and infrastructure used by ryml.
size_t adjust_pos_with_escapes(csubstr scalar, size_t pos, bool keep_newlines=false)
Adjust a position in a scalar, increasing it to account for any escaped characters.
size_t to_chars(substr buf, escaped_scalar e)
formatting implementation to escape a scalar with escape_scalar()
size_t escape_scalar(substr buffer, csubstr scalar, bool keep_newlines=false)
Escape a scalar to an existing buffer, using escape_scalar_fn.
void escape_scalar_fn(Fn &&fn, csubstr scalar, bool keep_newlines=false)
Iterate through a scalar and escape special characters in it.
size_t dump(SinkPfn &&sinkfn, substr buf, escaped_scalar const &e)
dumping implementation to escape a scalar with escape_scalar_fn()
(Undefined by default) Use shorter error message from checks/asserts: do not show the check condition...
formatting helper to escape a scalar with escape_scalar()
escaped_scalar(csubstr s, bool keep_newl=false)