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));
163C4_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))
244 C4_ASSERT(!buffer.
overlaps(scalar));
245 auto append_ = [&pos, &buffer](
csubstr repl){
246 if(repl.len && (pos + repl.len <= buffer.
len))
247 memcpy(buffer.
str + pos, repl.str, repl.len);
269template<
class SinkPfn>
278C4_SUPPRESS_WARNING_GCC_POP
Common utilities and infrastructure used by ryml.
basic_substring< char > substr
a mutable string view
basic_substring< const char > csubstr
an immutable string view
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...
basic_substring range(size_t first, size_t last=npos) const noexcept
return [first,last[.
size_t len
the length of the substring
bool overlaps(ro_substr const that) const noexcept
true if there is overlap of at least one element between that and *this
basic_substring sub(size_t first) const noexcept
return [first,len[
C * str
a restricted pointer to the first character of the substring
formatting helper to escape a scalar with escape_scalar_fn()
escaped_scalar(csubstr s, bool keep_newl=false)