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

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(), c4::yml::normalize_tag_long(), and sample::sample_tags().

◆ from_tag()

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

Definition at line 163 of file tag.cpp.

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

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 sample::sample_tags().

◆ from_tag_long()

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

Definition at line 123 of file tag.cpp.

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

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(), and sample::sample_tags().

◆ 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:163
YamlTag_e to_tag(csubstr tag)
Definition: tag.cpp:67

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

Referenced by sample::sample_tags().

◆ 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:123

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

Referenced by c4::yml::normalize_tag_long(), and sample::sample_tags().

◆ 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:267

References c4::yml::npos.

Referenced by c4::yml::Tree::resolve_tag().