rapidyaml  0.11.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 67 of file tag.cpp.

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

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.

◆ from_tag()

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

Definition at line 168 of file tag.cpp.

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

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.

◆ from_tag_long()

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

Definition at line 128 of file tag.cpp.

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

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.

◆ normalize_tag()

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

Definition at line 19 of file tag.cpp.

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

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 31 of file tag.cpp.

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

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

◆ normalize_tag_long() [2/2]

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

Definition at line 43 of file tag.cpp.

44 {
45  csubstr result = normalize_tag_long(tag);
46  if(result.begins_with("!!"))
47  {
48  tag = tag.sub(2);
49  const csubstr pfx = "<tag:yaml.org,2002:";
50  const size_t len = pfx.len + tag.len + 1;
51  if(len <= output.len)
52  {
53  memcpy(output.str , pfx.str, pfx.len);
54  memcpy(output.str + pfx.len, tag.str, tag.len);
55  output[pfx.len + tag.len] = '>';
56  result = output.first(len);
57  }
58  else
59  {
60  result.str = nullptr;
61  result.len = len;
62  }
63  }
64  return result;
65 }
csubstr normalize_tag_long(csubstr tag, substr output)
Definition: tag.cpp:43

References c4::yml::normalize_tag_long().

◆ is_custom_tag()

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

Definition at line 9 of file tag.cpp.

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

References c4::yml::npos.