rapidyaml  0.10.0
parse and emit YAML, and do it fast
Tag utilities

Classes

struct  c4::yml::TagDirective
 
struct  c4::yml::TagDirectiveRange
 

Macros

#define RYML_MAX_TAG_DIRECTIVES   4
 the maximum number of tag directives in a Tree More...
 

Typedefs

using c4::yml::tag_bits = uint16_t
 the integral type necessary to cover all the bits marking node tags More...
 

Enumerations

enum  c4::yml::YamlTag_e : tag_bits {
  c4::yml::TAG_NONE = 0 , c4::yml::TAG_MAP = 1 , c4::yml::TAG_OMAP = 2 , c4::yml::TAG_PAIRS = 3 ,
  c4::yml::TAG_SET = 4 , c4::yml::TAG_SEQ = 5 , c4::yml::TAG_BINARY = 6 , c4::yml::TAG_BOOL = 7 ,
  c4::yml::TAG_FLOAT = 8 , c4::yml::TAG_INT = 9 , c4::yml::TAG_MERGE = 10 , c4::yml::TAG_NULL = 11 ,
  c4::yml::TAG_STR = 12 , c4::yml::TAG_TIMESTAMP = 13 , c4::yml::TAG_VALUE = 14 , c4::yml::TAG_YAML = 15
}
 a bit mask for marking tags for types More...
 

Functions

YamlTag_e c4::yml::to_tag (csubstr tag)
 
csubstr c4::yml::from_tag (YamlTag_e tag)
 
csubstr c4::yml::from_tag_long (YamlTag_e tag)
 
csubstr c4::yml::normalize_tag (csubstr tag)
 
csubstr c4::yml::normalize_tag_long (csubstr tag)
 
csubstr c4::yml::normalize_tag_long (csubstr tag, substr output)
 
bool c4::yml::is_custom_tag (csubstr tag)
 

Detailed Description

See also
sample::sample_tags

Macro Definition Documentation

◆ RYML_MAX_TAG_DIRECTIVES

#define RYML_MAX_TAG_DIRECTIVES   4

the maximum number of tag directives in a Tree

Definition at line 19 of file tag.hpp.

Typedef Documentation

◆ tag_bits

using c4::yml::tag_bits = typedef uint16_t

the integral type necessary to cover all the bits marking node tags

Definition at line 23 of file tag.hpp.

Enumeration Type Documentation

◆ YamlTag_e

a bit mask for marking tags for types

Enumerator
TAG_NONE 
TAG_MAP 

!!map Unordered set of key: value pairs without duplicates.

See also
https://yaml.org/type/map.html
TAG_OMAP 

!!omap Ordered sequence of key: value pairs without duplicates.

See also
https://yaml.org/type/omap.html
TAG_PAIRS 

!!pairs Ordered sequence of key: value pairs allowing duplicates.

See also
https://yaml.org/type/pairs.html
TAG_SET 

!!set Unordered set of non-equal values.

See also
https://yaml.org/type/set.html
TAG_SEQ 

!!seq Sequence of arbitrary values.

See also
https://yaml.org/type/seq.html
TAG_BINARY 

!!binary A sequence of zero or more octets (8 bit values).

See also
https://yaml.org/type/binary.html
TAG_BOOL 

!!bool Mathematical Booleans.

See also
https://yaml.org/type/bool.html
TAG_FLOAT 

!!float Floating-point approximation to real numbers.

https://yaml.org/type/float.html

TAG_INT 

!!float Mathematical integers.

https://yaml.org/type/int.html

TAG_MERGE 

!!merge Specify one or more mapping to be merged with the current one.

https://yaml.org/type/merge.html

TAG_NULL 

!!null Devoid of value.

https://yaml.org/type/null.html

TAG_STR 

!!str A sequence of zero or more Unicode characters.

https://yaml.org/type/str.html

TAG_TIMESTAMP 

!!timestamp A point in time https://yaml.org/type/timestamp.html

TAG_VALUE 

!!value Specify the default value of a mapping https://yaml.org/type/value.html

TAG_YAML 

!!yaml Specify the default value of a mapping https://yaml.org/type/yaml.html

Definition at line 26 of file tag.hpp.

26  : tag_bits {
27  TAG_NONE = 0,
28  // container types
29  TAG_MAP = 1, /**< !!map Unordered set of key: value pairs without duplicates. @see https://yaml.org/type/map.html */
30  TAG_OMAP = 2, /**< !!omap Ordered sequence of key: value pairs without duplicates. @see https://yaml.org/type/omap.html */
31  TAG_PAIRS = 3, /**< !!pairs Ordered sequence of key: value pairs allowing duplicates. @see https://yaml.org/type/pairs.html */
32  TAG_SET = 4, /**< !!set Unordered set of non-equal values. @see https://yaml.org/type/set.html */
33  TAG_SEQ = 5, /**< !!seq Sequence of arbitrary values. @see https://yaml.org/type/seq.html */
34  // scalar types
35  TAG_BINARY = 6, /**< !!binary A sequence of zero or more octets (8 bit values). @see https://yaml.org/type/binary.html */
36  TAG_BOOL = 7, /**< !!bool Mathematical Booleans. @see https://yaml.org/type/bool.html */
37  TAG_FLOAT = 8, /**< !!float Floating-point approximation to real numbers. https://yaml.org/type/float.html */
38  TAG_INT = 9, /**< !!float Mathematical integers. https://yaml.org/type/int.html */
39  TAG_MERGE = 10, /**< !!merge Specify one or more mapping to be merged with the current one. https://yaml.org/type/merge.html */
40  TAG_NULL = 11, /**< !!null Devoid of value. https://yaml.org/type/null.html */
41  TAG_STR = 12, /**< !!str A sequence of zero or more Unicode characters. https://yaml.org/type/str.html */
42  TAG_TIMESTAMP = 13, /**< !!timestamp A point in time https://yaml.org/type/timestamp.html */
43  TAG_VALUE = 14, /**< !!value Specify the default value of a mapping https://yaml.org/type/value.html */
44  TAG_YAML = 15, /**< !!yaml Specify the default value of a mapping https://yaml.org/type/yaml.html */
45 } YamlTag_e;
YamlTag_e
a bit mask for marking tags for types
Definition: tag.hpp:26
uint16_t tag_bits
the integral type necessary to cover all the bits marking node tags
Definition: tag.hpp:23
@ TAG_SET
!!set Unordered set of non-equal values.
Definition: tag.hpp:32
@ TAG_MERGE
!!merge Specify one or more mapping to be merged with the current one.
Definition: tag.hpp:39
@ TAG_INT
!!float Mathematical integers.
Definition: tag.hpp:38
@ TAG_SEQ
!!seq Sequence of arbitrary values.
Definition: tag.hpp:33
@ TAG_NULL
!!null Devoid of value.
Definition: tag.hpp:40
@ TAG_YAML
!!yaml Specify the default value of a mapping https://yaml.org/type/yaml.html
Definition: tag.hpp:44
@ TAG_TIMESTAMP
!!timestamp A point in time https://yaml.org/type/timestamp.html
Definition: tag.hpp:42
@ TAG_NONE
Definition: tag.hpp:27
@ TAG_STR
!!str A sequence of zero or more Unicode characters.
Definition: tag.hpp:41
@ TAG_BOOL
!!bool Mathematical Booleans.
Definition: tag.hpp:36
@ TAG_MAP
!!map Unordered set of key: value pairs without duplicates.
Definition: tag.hpp:29
@ TAG_BINARY
!!binary A sequence of zero or more octets (8 bit values).
Definition: tag.hpp:35
@ TAG_PAIRS
!!pairs Ordered sequence of key: value pairs allowing duplicates.
Definition: tag.hpp:31
@ TAG_VALUE
!!value Specify the default value of a mapping https://yaml.org/type/value.html
Definition: tag.hpp:43
@ TAG_OMAP
!!omap Ordered sequence of key: value pairs without duplicates.
Definition: tag.hpp:30
@ TAG_FLOAT
!!float Floating-point approximation to real numbers.
Definition: tag.hpp:37

Function Documentation

◆ to_tag()

YamlTag_e c4::yml::to_tag ( csubstr  tag)

Definition at line 66 of file tag.cpp.

67 {
68  if(tag.begins_with("!<"))
69  tag = tag.sub(1);
70  if(tag.begins_with("!!"))
71  tag = tag.sub(2);
72  else if(tag.begins_with('!'))
73  return TAG_NONE;
74  else if(tag.begins_with("tag:yaml.org,2002:"))
75  {
76  RYML_ASSERT(csubstr("tag:yaml.org,2002:").len == 18);
77  tag = tag.sub(18);
78  }
79  else if(tag.begins_with("<tag:yaml.org,2002:"))
80  {
81  RYML_ASSERT(csubstr("<tag:yaml.org,2002:").len == 19);
82  tag = tag.sub(19);
83  if(!tag.len)
84  return TAG_NONE;
85  tag = tag.offs(0, 1);
86  }
87 
88  if(tag == "map")
89  return TAG_MAP;
90  else if(tag == "omap")
91  return TAG_OMAP;
92  else if(tag == "pairs")
93  return TAG_PAIRS;
94  else if(tag == "set")
95  return TAG_SET;
96  else if(tag == "seq")
97  return TAG_SEQ;
98  else if(tag == "binary")
99  return TAG_BINARY;
100  else if(tag == "bool")
101  return TAG_BOOL;
102  else if(tag == "float")
103  return TAG_FLOAT;
104  else if(tag == "int")
105  return TAG_INT;
106  else if(tag == "merge")
107  return TAG_MERGE;
108  else if(tag == "null")
109  return TAG_NULL;
110  else if(tag == "str")
111  return TAG_STR;
112  else if(tag == "timestamp")
113  return TAG_TIMESTAMP;
114  else if(tag == "value")
115  return TAG_VALUE;
116  else if(tag == "yaml")
117  return TAG_YAML;
118 
119  return TAG_NONE;
120 }

References c4::yml::TAG_BINARY, c4::yml::TAG_BOOL, c4::yml::TAG_FLOAT, c4::yml::TAG_INT, c4::yml::TAG_MAP, c4::yml::TAG_MERGE, c4::yml::TAG_NONE, c4::yml::TAG_NULL, c4::yml::TAG_OMAP, c4::yml::TAG_PAIRS, c4::yml::TAG_SEQ, c4::yml::TAG_SET, c4::yml::TAG_STR, c4::yml::TAG_TIMESTAMP, c4::yml::TAG_VALUE, and c4::yml::TAG_YAML.

Referenced by c4::yml::normalize_tag(), and c4::yml::normalize_tag_long().

◆ from_tag()

csubstr c4::yml::from_tag ( YamlTag_e  tag)

Definition at line 162 of file tag.cpp.

163 {
164  switch(tag)
165  {
166  case TAG_MAP:
167  return {"!!map"};
168  case TAG_OMAP:
169  return {"!!omap"};
170  case TAG_PAIRS:
171  return {"!!pairs"};
172  case TAG_SET:
173  return {"!!set"};
174  case TAG_SEQ:
175  return {"!!seq"};
176  case TAG_BINARY:
177  return {"!!binary"};
178  case TAG_BOOL:
179  return {"!!bool"};
180  case TAG_FLOAT:
181  return {"!!float"};
182  case TAG_INT:
183  return {"!!int"};
184  case TAG_MERGE:
185  return {"!!merge"};
186  case TAG_NULL:
187  return {"!!null"};
188  case TAG_STR:
189  return {"!!str"};
190  case TAG_TIMESTAMP:
191  return {"!!timestamp"};
192  case TAG_VALUE:
193  return {"!!value"};
194  case TAG_YAML:
195  return {"!!yaml"};
196  case TAG_NONE:
197  default:
198  return {""};
199  }
200 }

References c4::yml::TAG_BINARY, c4::yml::TAG_BOOL, c4::yml::TAG_FLOAT, c4::yml::TAG_INT, c4::yml::TAG_MAP, c4::yml::TAG_MERGE, c4::yml::TAG_NONE, c4::yml::TAG_NULL, c4::yml::TAG_OMAP, c4::yml::TAG_PAIRS, c4::yml::TAG_SEQ, c4::yml::TAG_SET, c4::yml::TAG_STR, c4::yml::TAG_TIMESTAMP, c4::yml::TAG_VALUE, and c4::yml::TAG_YAML.

Referenced by c4::yml::normalize_tag().

◆ from_tag_long()

csubstr c4::yml::from_tag_long ( YamlTag_e  tag)

Definition at line 122 of file tag.cpp.

123 {
124  switch(tag)
125  {
126  case TAG_MAP:
127  return {"<tag:yaml.org,2002:map>"};
128  case TAG_OMAP:
129  return {"<tag:yaml.org,2002:omap>"};
130  case TAG_PAIRS:
131  return {"<tag:yaml.org,2002:pairs>"};
132  case TAG_SET:
133  return {"<tag:yaml.org,2002:set>"};
134  case TAG_SEQ:
135  return {"<tag:yaml.org,2002:seq>"};
136  case TAG_BINARY:
137  return {"<tag:yaml.org,2002:binary>"};
138  case TAG_BOOL:
139  return {"<tag:yaml.org,2002:bool>"};
140  case TAG_FLOAT:
141  return {"<tag:yaml.org,2002:float>"};
142  case TAG_INT:
143  return {"<tag:yaml.org,2002:int>"};
144  case TAG_MERGE:
145  return {"<tag:yaml.org,2002:merge>"};
146  case TAG_NULL:
147  return {"<tag:yaml.org,2002:null>"};
148  case TAG_STR:
149  return {"<tag:yaml.org,2002:str>"};
150  case TAG_TIMESTAMP:
151  return {"<tag:yaml.org,2002:timestamp>"};
152  case TAG_VALUE:
153  return {"<tag:yaml.org,2002:value>"};
154  case TAG_YAML:
155  return {"<tag:yaml.org,2002:yaml>"};
156  case TAG_NONE:
157  default:
158  return {""};
159  }
160 }

References c4::yml::TAG_BINARY, c4::yml::TAG_BOOL, c4::yml::TAG_FLOAT, c4::yml::TAG_INT, c4::yml::TAG_MAP, c4::yml::TAG_MERGE, c4::yml::TAG_NONE, c4::yml::TAG_NULL, c4::yml::TAG_OMAP, c4::yml::TAG_PAIRS, c4::yml::TAG_SEQ, c4::yml::TAG_SET, c4::yml::TAG_STR, c4::yml::TAG_TIMESTAMP, c4::yml::TAG_VALUE, and c4::yml::TAG_YAML.

Referenced by c4::yml::normalize_tag_long().

◆ normalize_tag()

csubstr c4::yml::normalize_tag ( csubstr  tag)

Definition at line 18 of file tag.cpp.

19 {
20  YamlTag_e t = to_tag(tag);
21  if(t != TAG_NONE)
22  return from_tag(t);
23  if(tag.begins_with("!<"))
24  tag = tag.sub(1);
25  if(tag.begins_with("<!"))
26  return tag;
27  return tag;
28 }
csubstr from_tag(YamlTag_e tag)
Definition: tag.cpp:162
YamlTag_e to_tag(csubstr tag)
Definition: tag.cpp:66

References c4::yml::from_tag(), c4::yml::TAG_NONE, and c4::yml::to_tag().

◆ normalize_tag_long() [1/2]

csubstr c4::yml::normalize_tag_long ( csubstr  tag)

Definition at line 30 of file tag.cpp.

31 {
32  YamlTag_e t = to_tag(tag);
33  if(t != TAG_NONE)
34  return from_tag_long(t);
35  if(tag.begins_with("!<"))
36  tag = tag.sub(1);
37  if(tag.begins_with("<!"))
38  return tag;
39  return tag;
40 }
csubstr from_tag_long(YamlTag_e tag)
Definition: tag.cpp:122

References c4::yml::from_tag_long(), c4::yml::TAG_NONE, and c4::yml::to_tag().

Referenced by c4::yml::normalize_tag_long().

◆ normalize_tag_long() [2/2]

csubstr c4::yml::normalize_tag_long ( csubstr  tag,
substr  output 
)

Definition at line 42 of file tag.cpp.

43 {
44  csubstr result = normalize_tag_long(tag);
45  if(result.begins_with("!!"))
46  {
47  tag = tag.sub(2);
48  const csubstr pfx = "<tag:yaml.org,2002:";
49  const size_t len = pfx.len + tag.len + 1;
50  if(len <= output.len)
51  {
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);
56  }
57  else
58  {
59  result.str = nullptr;
60  result.len = len;
61  }
62  }
63  return result;
64 }
csubstr normalize_tag_long(csubstr tag, substr output)
Definition: tag.cpp:42

References c4::yml::normalize_tag_long().

◆ is_custom_tag()

bool c4::yml::is_custom_tag ( csubstr  tag)

Definition at line 8 of file tag.cpp.

9 {
10  if((tag.len > 2) && (tag.str[0] == '!'))
11  {
12  size_t pos = tag.find('!', 1);
13  return pos != npos && pos > 1 && tag.str[1] != '<';
14  }
15  return false;
16 }
@ npos
a null string position
Definition: common.hpp:267

References c4::yml::npos.

Referenced by c4::yml::extra::EventHandlerInts::_transform_directive(), and c4::yml::Tree::resolve_tag().