2 #include "c4/yml/detail/dbgprint.hpp"
10 if((tag.len > 2) && (tag.str[0] ==
'!'))
12 size_t pos = tag.find(
'!', 1);
13 return pos !=
npos && pos > 1 && tag.str[1] !=
'<';
23 if(tag.begins_with(
"!<"))
25 if(tag.begins_with(
"<!"))
35 if(tag.begins_with(
"!<"))
37 if(tag.begins_with(
"<!"))
45 if(result.begins_with(
"!!"))
48 const csubstr pfx =
"<tag:yaml.org,2002:";
49 const size_t len = pfx.len + tag.len + 1;
52 memcpy(output.str , pfx.str, pfx.len);
53 memcpy(output.str + pfx.len, tag.str, tag.len);
54 output[pfx.len + tag.len] =
'>';
55 result = output.first(len);
68 if(tag.begins_with(
"!<"))
70 if(tag.begins_with(
"!!"))
72 else if(tag.begins_with(
'!'))
74 else if(tag.begins_with(
"tag:yaml.org,2002:"))
76 RYML_ASSERT(csubstr(
"tag:yaml.org,2002:").len == 18);
79 else if(tag.begins_with(
"<tag:yaml.org,2002:"))
81 RYML_ASSERT(csubstr(
"<tag:yaml.org,2002:").len == 19);
90 else if(tag ==
"omap")
92 else if(tag ==
"pairs")
98 else if(tag ==
"binary")
100 else if(tag ==
"bool")
102 else if(tag ==
"float")
104 else if(tag ==
"int")
106 else if(tag ==
"merge")
108 else if(tag ==
"null")
110 else if(tag ==
"str")
112 else if(tag ==
"timestamp")
114 else if(tag ==
"value")
116 else if(tag ==
"yaml")
127 return {
"<tag:yaml.org,2002:map>"};
129 return {
"<tag:yaml.org,2002:omap>"};
131 return {
"<tag:yaml.org,2002:pairs>"};
133 return {
"<tag:yaml.org,2002:set>"};
135 return {
"<tag:yaml.org,2002:seq>"};
137 return {
"<tag:yaml.org,2002:binary>"};
139 return {
"<tag:yaml.org,2002:bool>"};
141 return {
"<tag:yaml.org,2002:float>"};
143 return {
"<tag:yaml.org,2002:int>"};
145 return {
"<tag:yaml.org,2002:merge>"};
147 return {
"<tag:yaml.org,2002:null>"};
149 return {
"<tag:yaml.org,2002:str>"};
151 return {
"<tag:yaml.org,2002:timestamp>"};
153 return {
"<tag:yaml.org,2002:value>"};
155 return {
"<tag:yaml.org,2002:yaml>"};
191 return {
"!!timestamp"};
205 csubstr directive = directive_;
206 directive = directive.sub(4);
207 if(!directive.begins_with(
' '))
209 directive = directive.triml(
' ');
210 size_t pos = directive.find(
' ');
213 handle = directive.first(pos);
214 directive = directive.sub(
handle.len).triml(
' ');
215 pos = directive.find(
' ');
217 directive = directive.first(pos);
227 _RYML_CB_ASSERT(callbacks, tag.len >=
handle.len);
228 csubstr rest = tag.sub(
handle.len);
229 _c4dbgpf(
"%TAG: rest={}", rest);
230 if(rest.begins_with(
'<'))
232 _c4dbgpf(
"%TAG: begins with <. rest={}", rest);
233 if(C4_UNLIKELY(!rest.ends_with(
'>')))
234 _RYML_CB_ERR(callbacks,
"malformed tag");
235 rest = rest.offs(1, 1);
236 if(rest.begins_with(
prefix))
238 _c4dbgpf(
"%TAG: already transformed! actual={}", rest.sub(
prefix.len));
242 size_t len =
prefix.len + rest.len;
245 size_t numpc = rest.count(
'%');
248 if(len <= output.len)
254 memcpy(1u + output.str +
prefix.len, rest.str, rest.len);
255 output.str[1u +
prefix.len + rest.len] =
'>';
260 memcpy(output.str +
prefix.len, rest.str, rest.len);
267 size_t pos = rest.find(
'%');
268 _RYML_CB_ASSERT(callbacks, pos !=
npos);
270 size_t next = rest.first_not_of(
"0123456789abcdefABCDEF", pos+1);
273 _RYML_CB_CHECK(callbacks, pos+1 < next);
274 _RYML_CB_CHECK(callbacks, pos+1 + 2 <= next);
275 size_t delta = next - (pos+1);
277 pos = rest.find(
'%', pos+1);
278 }
while(pos !=
npos);
279 if(len <= output.len)
281 size_t prev = 0, wpos = 0;
282 auto appendstr = [&](csubstr s) { memcpy(output.str + wpos, s.str, s.len); wpos += s.len; };
283 auto appendchar = [&](
char c) { output.str[wpos++] = c; };
287 pos = rest.find(
'%');
288 _RYML_CB_ASSERT(callbacks, pos !=
npos);
290 size_t next = rest.first_not_of(
"0123456789abcdefABCDEF", pos+1);
293 _RYML_CB_CHECK(callbacks, pos+1 < next);
294 _RYML_CB_CHECK(callbacks, pos+1 + 2 <= next);
296 if(C4_UNLIKELY(!
read_hex(rest.range(pos+1, next), &val) || val > 127))
297 _RYML_CB_ERR(callbacks,
"invalid URI character");
298 appendstr(rest.range(prev, pos));
299 appendchar(
static_cast<char>(val));
301 pos = rest.find(
'%', pos+1);
302 }
while(pos !=
npos);
303 _RYML_CB_ASSERT(callbacks, pos ==
npos);
304 _RYML_CB_ASSERT(callbacks, prev > 0);
305 _RYML_CB_ASSERT(callbacks, rest.len >= prev);
306 appendstr(rest.sub(prev));
309 _RYML_CB_ASSERT(callbacks, wpos == len);
bool read_hex(csubstr s, I *v) noexcept
read an hexadecimal integer from a string.
csubstr from_tag_long(YamlTag_e tag)
bool is_custom_tag(csubstr tag)
csubstr normalize_tag_long(csubstr tag)
YamlTag_e
a bit mask for marking tags for types
csubstr normalize_tag(csubstr tag)
csubstr from_tag(YamlTag_e tag)
YamlTag_e to_tag(csubstr tag)
@ TAG_SET
!!set Unordered set of non-equal values.
@ TAG_MERGE
!!merge Specify one or more mapping to be merged with the current one.
@ TAG_INT
!!float Mathematical integers.
@ TAG_SEQ
!!seq Sequence of arbitrary values.
@ TAG_NULL
!!null Devoid of value.
@ TAG_YAML
!!yaml Specify the default value of a mapping https://yaml.org/type/yaml.html
@ TAG_TIMESTAMP
!!timestamp A point in time https://yaml.org/type/timestamp.html
@ TAG_STR
!!str A sequence of zero or more Unicode characters.
@ TAG_BOOL
!!bool Mathematical Booleans.
@ TAG_MAP
!!map Unordered set of key: value pairs without duplicates.
@ TAG_BINARY
!!binary A sequence of zero or more octets (8 bit values).
@ TAG_PAIRS
!!pairs Ordered sequence of key: value pairs allowing duplicates.
@ TAG_VALUE
!!value Specify the default value of a mapping https://yaml.org/type/value.html
@ TAG_OMAP
!!omap Ordered sequence of key: value pairs without duplicates.
@ TAG_FLOAT
!!float Floating-point approximation to real numbers.
@ npos
a null string position
a c-style callbacks class.
bool create_from_str(csubstr directive_)
leaves next_node_id unfilled
id_type next_node_id
The next node to which this tag directive applies.
size_t transform(csubstr tag, substr output, Callbacks const &callbacks, bool with_brackets=true) const