rapidyaml  0.13.0
parse and emit YAML, and do it fast
Node types

Classes

struct  c4::yml::NodeType
 wraps a NodeType_e element with some syntactic sugar and predicates More...
 

Typedefs

using c4::yml::type_bits = uint32_t
 the integral type necessary to cover all the bits for NodeType_e More...
 

Enumerations

enum  c4::yml::NodeType_e : type_bits {
  c4::yml::NOTYPE = 0 , c4::yml::KEY = __(0) , c4::yml::VAL = __(1) , c4::yml::MAP = __(2) ,
  c4::yml::SEQ = __(3) , c4::yml::DOC = __(4) , c4::yml::STREAM = __(5)|SEQ , c4::yml::KEYREF = __(6) ,
  c4::yml::VALREF = __(7) , c4::yml::KEYANCH = __(8) , c4::yml::VALANCH = __(9) , c4::yml::KEYTAG = __(10) ,
  c4::yml::VALTAG = __(11) , c4::yml::KEYNIL = __(12) , c4::yml::VALNIL = __(13) , c4::yml::_TYMASK = __(14)-1 ,
  c4::yml::KEY_UNFILT = __(14) , c4::yml::VAL_UNFILT = __(15) , c4::yml::FLOW_SL = __(16) , c4::yml::FLOW_ML = __(17) ,
  c4::yml::BLOCK = __(18) , c4::yml::KEY_LITERAL = __(19) , c4::yml::VAL_LITERAL = __(20) , c4::yml::KEY_FOLDED = __(21) ,
  c4::yml::VAL_FOLDED = __(22) , c4::yml::KEY_SQUO = __(23) , c4::yml::VAL_SQUO = __(24) , c4::yml::KEY_DQUO = __(25) ,
  c4::yml::VAL_DQUO = __(26) , c4::yml::KEY_PLAIN = __(27) , c4::yml::VAL_PLAIN = __(28) , c4::yml::KEYVAL = KEY|VAL ,
  c4::yml::KEYSEQ = KEY|SEQ , c4::yml::KEYMAP = KEY|MAP , c4::yml::DOCMAP = DOC|MAP , c4::yml::DOCSEQ = DOC|SEQ ,
  c4::yml::DOCVAL = DOC|VAL , c4::yml::SCALAR_LITERAL = KEY_LITERAL|VAL_LITERAL , c4::yml::SCALAR_FOLDED = KEY_FOLDED|VAL_FOLDED , c4::yml::SCALAR_SQUO = KEY_SQUO|VAL_SQUO ,
  c4::yml::SCALAR_DQUO = KEY_DQUO|VAL_DQUO , c4::yml::SCALAR_PLAIN = KEY_PLAIN|VAL_PLAIN , c4::yml::KEYQUO = KEY_SQUO|KEY_DQUO|KEY_FOLDED|KEY_LITERAL , c4::yml::VALQUO = VAL_SQUO|VAL_DQUO|VAL_FOLDED|VAL_LITERAL ,
  c4::yml::KEY_STYLE = KEY_LITERAL|KEY_FOLDED|KEY_SQUO|KEY_DQUO|KEY_PLAIN , c4::yml::VAL_STYLE = VAL_LITERAL|VAL_FOLDED|VAL_SQUO|VAL_DQUO|VAL_PLAIN , c4::yml::SCALAR_STYLE = KEY_STYLE|VAL_STYLE , c4::yml::CONTAINER_STYLE_FLOW = FLOW_SL|FLOW_ML ,
  c4::yml::CONTAINER_STYLE_BLOCK = BLOCK , c4::yml::CONTAINER_STYLE = FLOW_SL|FLOW_ML|BLOCK , c4::yml::STYLE = SCALAR_STYLE | CONTAINER_STYLE , c4::yml::_KEYMASK = KEY | KEYQUO | KEYANCH | KEYREF | KEYTAG ,
  c4::yml::_VALMASK = VAL | VALQUO | VALANCH | VALREF | VALTAG
}
 a bit mask for marking node types and styles More...
 

Functions

constexpr C4_CONST NodeType_e c4::yml::operator| (NodeType_e lhs, NodeType_e rhs) noexcept
 
constexpr C4_CONST NodeType_e c4::yml::operator& (NodeType_e lhs, NodeType_e rhs) noexcept
 
constexpr C4_CONST NodeType_e c4::yml::operator>> (NodeType_e bits, uint32_t n) noexcept
 
constexpr C4_CONST NodeType_e c4::yml::operator<< (NodeType_e bits, uint32_t n) noexcept
 
constexpr C4_CONST NodeType_e c4::yml::operator~ (NodeType_e bits) noexcept
 
NodeType_ec4::yml::operator&= (NodeType_e &subject, NodeType_e bits) noexcept
 
NodeType_ec4::yml::operator|= (NodeType_e &subject, NodeType_e bits) noexcept
 

scalar style helpers

NodeType_e c4::yml::scalar_style_choose_flow (csubstr scalar) noexcept
 choose a YAML scalar style based on the scalar's contents, while in flow mode. More...
 
NodeType_e c4::yml::scalar_style_choose_block (csubstr scalar) noexcept
 choose a YAML scalar style based on the scalar's contents, while in block mode. More...
 
NodeType_e c4::yml::scalar_style_choose (csubstr s, bool flow=true) noexcept
 choose a YAML emitting style based on the scalar's contents. More...
 
NodeType_e c4::yml::scalar_style_choose_json (csubstr scalar) noexcept
 choose a json scalar style based on the scalar's contents More...
 
bool c4::yml::scalar_style_query_squo (csubstr s) noexcept
 query whether a scalar can be encoded using single quotes. More...
 
bool c4::yml::scalar_style_query_plain_flow (csubstr s) noexcept
 query whether a scalar can be encoded using plain style while in flow mode. More...
 
bool c4::yml::scalar_style_query_plain_block (csubstr s) noexcept
 query whether a scalar can be encoded using plain style while in block mode. More...
 
bool c4::yml::scalar_style_query_plain (csubstr s, bool flow=true) noexcept
 query whether a scalar can be encoded using plain style. More...
 
bool c4::yml::scalar_is_null (csubstr s) noexcept
 YAML-sense query of nullity. More...
 

Detailed Description

Typedef Documentation

◆ type_bits

using c4::yml::type_bits = typedef uint32_t

the integral type necessary to cover all the bits for NodeType_e

Definition at line 30 of file node_type.hpp.

Enumeration Type Documentation

◆ NodeType_e

a bit mask for marking node types and styles

Enumerator
NOTYPE 

no node type or style is set

KEY 

is member of a map

VAL 

a scalar: has a scalar (ie string) value, possibly empty. must be a leaf node, and cannot be MAP or SEQ

MAP 

a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes

SEQ 

a seq: a parent of VAL/SEQ/MAP nodes

DOC 

a document

STREAM 

a stream: a seq of docs

KEYREF 

a *reference: the key references an &anchor

VALREF 

a *reference: the val references an &anchor

KEYANCH 

the key has an &anchor

VALANCH 

the val has an &anchor

KEYTAG 

the key has a tag

VALTAG 

the val has a tag

KEYNIL 

the key is null (eg { : b} results in a null key)

VALNIL 

the val is null (eg {a : } results in a null val)

_TYMASK 

all the bits up to here

KEY_UNFILT 

the key scalar was left unfiltered; the parser was set not to filter.

See also
ParserOptions
VAL_UNFILT 

the val scalar was left unfiltered; the parser was set not to filter.

See also
ParserOptions
FLOW_SL 

mark container with single-line flow style (seqs as '[val1,val2], maps as '{key: val,key2: val2}')

FLOW_ML 

mark container with multi-line flow style (seqs as '[
val1,
val2
], maps as '{
key: val,
key2: val2
}')

BLOCK 

mark container with block style (seqs as '- val
', maps as 'key: val')

KEY_LITERAL 

mark key scalar as multiline, block literal |

VAL_LITERAL 

mark val scalar as multiline, block literal |

KEY_FOLDED 

mark key scalar as multiline, block folded >

VAL_FOLDED 

mark val scalar as multiline, block folded >

KEY_SQUO 

mark key scalar as single quoted '

VAL_SQUO 

mark val scalar as single quoted '

KEY_DQUO 

mark key scalar as double quoted "

VAL_DQUO 

mark val scalar as double quoted "

KEY_PLAIN 

mark key scalar as plain scalar (unquoted, even when multiline)

VAL_PLAIN 

mark val scalar as plain scalar (unquoted, even when multiline)

KEYVAL 
KEYSEQ 
KEYMAP 
DOCMAP 
DOCSEQ 
DOCVAL 
SCALAR_LITERAL 
SCALAR_FOLDED 
SCALAR_SQUO 
SCALAR_DQUO 
SCALAR_PLAIN 
KEYQUO 

key style is one of ', ", > or |

VALQUO 

val style is one of ', ", > or |

KEY_STYLE 

mask of all the scalar styles for key (not container styles!)

VAL_STYLE 

mask of all the scalar styles for val (not container styles!)

SCALAR_STYLE 
CONTAINER_STYLE_FLOW 
CONTAINER_STYLE_BLOCK 
CONTAINER_STYLE 
STYLE 
_KEYMASK 
_VALMASK 

Definition at line 34 of file node_type.hpp.

34  : type_bits { // NOLINT
35  #define __(v) (type_bits(1) << v) // a convenience define, undefined below // NOLINT
36  NOTYPE = 0, ///< no node type or style is set
37  KEY = __(0), ///< is member of a map
38  VAL = __(1), ///< a scalar: has a scalar (ie string) value, possibly empty. must be a leaf node, and cannot be MAP or SEQ
39  MAP = __(2), ///< a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
40  SEQ = __(3), ///< a seq: a parent of VAL/SEQ/MAP nodes
41  DOC = __(4), ///< a document
42  STREAM = __(5)|SEQ, ///< a stream: a seq of docs
43  KEYREF = __(6), ///< a *reference: the key references an &anchor
44  VALREF = __(7), ///< a *reference: the val references an &anchor
45  KEYANCH = __(8), ///< the key has an &anchor
46  VALANCH = __(9), ///< the val has an &anchor
47  KEYTAG = __(10), ///< the key has a tag
48  VALTAG = __(11), ///< the val has a tag
49  KEYNIL = __(12), ///< the key is null (eg `{ : b}` results in a null key)
50  VALNIL = __(13), ///< the val is null (eg `{a : }` results in a null val)
51  _TYMASK = __(14)-1, ///< all the bits up to here
52  //
53  // unfiltered flags:
54  //
55  KEY_UNFILT = __(14), ///< the key scalar was left unfiltered; the parser was set not to filter. @see ParserOptions
56  VAL_UNFILT = __(15), ///< the val scalar was left unfiltered; the parser was set not to filter. @see ParserOptions
57  //
58  // style flags:
59  //
60  FLOW_SL = __(16), ///< mark container with single-line flow style (seqs as '[val1,val2], maps as '{key: val,key2: val2}')
61  FLOW_ML = __(17), ///< mark container with multi-line flow style (seqs as '[\n val1,\n val2\n], maps as '{\n key: val,\n key2: val2\n}')
62  BLOCK = __(18), ///< mark container with block style (seqs as '- val\n', maps as 'key: val')
63  KEY_LITERAL = __(19), ///< mark key scalar as multiline, block literal |
64  VAL_LITERAL = __(20), ///< mark val scalar as multiline, block literal |
65  KEY_FOLDED = __(21), ///< mark key scalar as multiline, block folded >
66  VAL_FOLDED = __(22), ///< mark val scalar as multiline, block folded >
67  KEY_SQUO = __(23), ///< mark key scalar as single quoted '
68  VAL_SQUO = __(24), ///< mark val scalar as single quoted '
69  KEY_DQUO = __(25), ///< mark key scalar as double quoted "
70  VAL_DQUO = __(26), ///< mark val scalar as double quoted "
71  KEY_PLAIN = __(27), ///< mark key scalar as plain scalar (unquoted, even when multiline)
72  VAL_PLAIN = __(28), ///< mark val scalar as plain scalar (unquoted, even when multiline)
73  //
74  // type combination masks:
75  //
76  KEYVAL = KEY|VAL,
77  KEYSEQ = KEY|SEQ,
78  KEYMAP = KEY|MAP,
79  DOCMAP = DOC|MAP,
80  DOCSEQ = DOC|SEQ,
81  DOCVAL = DOC|VAL,
82  //
83  // style combination masks:
84  //
90  KEYQUO = KEY_SQUO|KEY_DQUO|KEY_FOLDED|KEY_LITERAL, ///< key style is one of ', ", > or |
91  VALQUO = VAL_SQUO|VAL_DQUO|VAL_FOLDED|VAL_LITERAL, ///< val style is one of ', ", > or |
92  KEY_STYLE = KEY_LITERAL|KEY_FOLDED|KEY_SQUO|KEY_DQUO|KEY_PLAIN, ///< mask of all the scalar styles for key (not container styles!)
93  VAL_STYLE = VAL_LITERAL|VAL_FOLDED|VAL_SQUO|VAL_DQUO|VAL_PLAIN, ///< mask of all the scalar styles for val (not container styles!)
99  //
100  // mixed masks
103  #undef __
104 } NodeType_e;
uint32_t type_bits
the integral type necessary to cover all the bits for NodeType_e
Definition: node_type.hpp:30
NodeType_e
a bit mask for marking node types and styles
Definition: node_type.hpp:34
@ VALANCH
the val has an &anchor
Definition: node_type.hpp:46
@ NOTYPE
no node type or style is set
Definition: node_type.hpp:36
@ SCALAR_FOLDED
Definition: node_type.hpp:86
@ KEY_DQUO
mark key scalar as double quoted "
Definition: node_type.hpp:69
@ VALREF
a *reference: the val references an &anchor
Definition: node_type.hpp:44
@ VALNIL
the val is null (eg {a : } results in a null val)
Definition: node_type.hpp:50
@ MAP
a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
Definition: node_type.hpp:39
@ STREAM
a stream: a seq of docs
Definition: node_type.hpp:42
@ KEY
is member of a map
Definition: node_type.hpp:37
@ KEYQUO
key style is one of ', ", > or |
Definition: node_type.hpp:90
@ VAL_FOLDED
mark val scalar as multiline, block folded >
Definition: node_type.hpp:66
@ CONTAINER_STYLE_BLOCK
Definition: node_type.hpp:96
@ VAL_STYLE
mask of all the scalar styles for val (not container styles!)
Definition: node_type.hpp:93
@ KEYTAG
the key has a tag
Definition: node_type.hpp:47
@ CONTAINER_STYLE_FLOW
Definition: node_type.hpp:95
@ SCALAR_SQUO
Definition: node_type.hpp:87
@ FLOW_SL
mark container with single-line flow style (seqs as '[val1,val2], maps as '{key: val,...
Definition: node_type.hpp:60
@ FLOW_ML
mark container with multi-line flow style (seqs as '[ val1, val2 ], maps as '{ key: val,...
Definition: node_type.hpp:61
@ VAL_UNFILT
the val scalar was left unfiltered; the parser was set not to filter.
Definition: node_type.hpp:56
@ VAL
a scalar: has a scalar (ie string) value, possibly empty. must be a leaf node, and cannot be MAP or S...
Definition: node_type.hpp:38
@ VALTAG
the val has a tag
Definition: node_type.hpp:48
@ SCALAR_STYLE
Definition: node_type.hpp:94
@ _TYMASK
all the bits up to here
Definition: node_type.hpp:51
@ SCALAR_LITERAL
Definition: node_type.hpp:85
@ SEQ
a seq: a parent of VAL/SEQ/MAP nodes
Definition: node_type.hpp:40
@ SCALAR_DQUO
Definition: node_type.hpp:88
@ VAL_SQUO
mark val scalar as single quoted '
Definition: node_type.hpp:68
@ KEY_STYLE
mask of all the scalar styles for key (not container styles!)
Definition: node_type.hpp:92
@ VAL_PLAIN
mark val scalar as plain scalar (unquoted, even when multiline)
Definition: node_type.hpp:72
@ KEYREF
a *reference: the key references an &anchor
Definition: node_type.hpp:43
@ BLOCK
mark container with block style (seqs as '- val ', maps as 'key: val')
Definition: node_type.hpp:62
@ KEYANCH
the key has an &anchor
Definition: node_type.hpp:45
@ VALQUO
val style is one of ', ", > or |
Definition: node_type.hpp:91
@ VAL_DQUO
mark val scalar as double quoted "
Definition: node_type.hpp:70
@ CONTAINER_STYLE
Definition: node_type.hpp:97
@ KEY_UNFILT
the key scalar was left unfiltered; the parser was set not to filter.
Definition: node_type.hpp:55
@ KEY_SQUO
mark key scalar as single quoted '
Definition: node_type.hpp:67
@ VAL_LITERAL
mark val scalar as multiline, block literal |
Definition: node_type.hpp:64
@ KEY_LITERAL
mark key scalar as multiline, block literal |
Definition: node_type.hpp:63
@ KEY_PLAIN
mark key scalar as plain scalar (unquoted, even when multiline)
Definition: node_type.hpp:71
@ SCALAR_PLAIN
Definition: node_type.hpp:89
@ KEY_FOLDED
mark key scalar as multiline, block folded >
Definition: node_type.hpp:65
@ KEYNIL
the key is null (eg { : b} results in a null key)
Definition: node_type.hpp:49
@ DOC
a document
Definition: node_type.hpp:41
#define __(v)
Definition: node_type.hpp:35

Function Documentation

◆ operator|()

constexpr C4_CONST NodeType_e c4::yml::operator| ( NodeType_e  lhs,
NodeType_e  rhs 
)
inlineconstexprnoexcept

Definition at line 106 of file node_type.hpp.

106 { return (NodeType_e)(((type_bits)lhs) | ((type_bits)rhs)); }

◆ operator&()

constexpr C4_CONST NodeType_e c4::yml::operator& ( NodeType_e  lhs,
NodeType_e  rhs 
)
inlineconstexprnoexcept

Definition at line 107 of file node_type.hpp.

107 { return (NodeType_e)(((type_bits)lhs) & ((type_bits)rhs)); }

◆ operator>>()

constexpr C4_CONST NodeType_e c4::yml::operator>> ( NodeType_e  bits,
uint32_t  n 
)
inlineconstexprnoexcept

Definition at line 108 of file node_type.hpp.

108 { return (NodeType_e)(((type_bits)bits) >> n); }

◆ operator<<()

constexpr C4_CONST NodeType_e c4::yml::operator<< ( NodeType_e  bits,
uint32_t  n 
)
inlineconstexprnoexcept

Definition at line 109 of file node_type.hpp.

109 { return (NodeType_e)(((type_bits)bits) << n); }

◆ operator~()

constexpr C4_CONST NodeType_e c4::yml::operator~ ( NodeType_e  bits)
inlineconstexprnoexcept

Definition at line 110 of file node_type.hpp.

110 { return (NodeType_e)(~(type_bits)bits); }

◆ operator&=()

NodeType_e& c4::yml::operator&= ( NodeType_e subject,
NodeType_e  bits 
)
inlinenoexcept

Definition at line 111 of file node_type.hpp.

111 { subject = (NodeType_e)((type_bits)subject & (type_bits)bits); return subject; }

◆ operator|=()

NodeType_e& c4::yml::operator|= ( NodeType_e subject,
NodeType_e  bits 
)
inlinenoexcept

Definition at line 112 of file node_type.hpp.

112 { subject = (NodeType_e)((type_bits)subject | (type_bits)bits); return subject; }

◆ scalar_style_choose_flow()

NodeType_e c4::yml::scalar_style_choose_flow ( csubstr  scalar)
noexcept

choose a YAML scalar style based on the scalar's contents, while in flow mode.

Plain scalars [have more constraints in flow mode than in block mode](https://www.yaml.info/learn/quote.html#noplain). scalar_style_choose_block() is the block mode analogous function.

Definition at line 262 of file node_type.cpp.

263 {
264  if(s.len)
265  {
267  return SCALAR_PLAIN;
268  else if(scalar_style_query_squo(s))
269  return SCALAR_SQUO;
270  return SCALAR_DQUO;
271  }
272  return s.str ? SCALAR_SQUO : SCALAR_PLAIN;
273 }
bool scalar_style_query_squo(csubstr s) noexcept
query whether a scalar can be encoded using single quotes.
Definition: node_type.cpp:138
bool scalar_style_query_plain_flow(csubstr s) noexcept
query whether a scalar can be encoded using plain style while in flow mode.
Definition: node_type.cpp:171

◆ scalar_style_choose_block()

NodeType_e c4::yml::scalar_style_choose_block ( csubstr  scalar)
noexcept

choose a YAML scalar style based on the scalar's contents, while in block mode.

Plain scalars [have more constraints in flow mode than in block mode](https://www.yaml.info/learn/quote.html#noplain). scalar_style_choose_block() is the flow mode analogous function.

Definition at line 275 of file node_type.cpp.

276 {
277  if(s.len)
278  {
280  return SCALAR_PLAIN;
281  _RYML_ASSERT_BASIC(scalar_style_query_squo(s)
282  && "if this assertion fires, please submit an issue!");
283  return SCALAR_SQUO;
284  }
285  return s.str ? SCALAR_SQUO : SCALAR_PLAIN;
286 }
bool scalar_style_query_plain_block(csubstr s) noexcept
query whether a scalar can be encoded using plain style while in block mode.
Definition: node_type.cpp:219

◆ scalar_style_choose()

NodeType_e c4::yml::scalar_style_choose ( csubstr  s,
bool  flow = true 
)
inlinenoexcept

choose a YAML emitting style based on the scalar's contents.

Legacy compatibility function: assumes flow mode which is more constraining, and delegates to either scalar_style_choose_flow() or scalar_style_choose_block().

Definition at line 273 of file node_type.hpp.

274 {
276 }
NodeType_e scalar_style_choose_flow(csubstr s) noexcept
choose a YAML scalar style based on the scalar's contents, while in flow mode.
Definition: node_type.cpp:262
NodeType_e scalar_style_choose_block(csubstr s) noexcept
choose a YAML scalar style based on the scalar's contents, while in block mode.
Definition: node_type.cpp:275

◆ scalar_style_choose_json()

NodeType_e c4::yml::scalar_style_choose_json ( csubstr  s)
noexcept

choose a json scalar style based on the scalar's contents

Definition at line 359 of file node_type.cpp.

360 {
361  // do not quote numbers or special scalars
362  return json_is_plain_number(s) || json_is_special_scalar(s) ? SCALAR_PLAIN : SCALAR_DQUO;
363 }

◆ scalar_style_query_squo()

bool c4::yml::scalar_style_query_squo ( csubstr  s)
noexcept

query whether a scalar can be encoded using single quotes.

It may not be possible, notably when there is leading whitespace after a newline.

Definition at line 138 of file node_type.cpp.

139 {
140  // cannot have leading whitespace after a newline
141  for(size_t i = 0; i < s.len; ++i)
142  {
143  if(s.str[i] == '\n' && i + 1 < s.len)
144  {
145  char next = s.str[i + 1];
146  if(next == ' ' || next == '\t')
147  return false;
148  }
149  }
150  return true;
151 }

◆ scalar_style_query_plain_flow()

bool c4::yml::scalar_style_query_plain_flow ( csubstr  s)
noexcept

query whether a scalar can be encoded using plain style while in flow mode.

Plain scalars [have more constraints in flow mode than in block mode](https://www.yaml.info/learn/quote.html#noplain). scalar_style_query_plain_block() is the block mode analogous function.

Definition at line 171 of file node_type.cpp.

172 {
173  if(!s.len)
174  return !s.str;
175  // first
176  switch(s.str[0])
177  {
178  case ' ': case '\n': case '\t': case '\r':
179  case '!': case '&': case '*': case ',':
180  case '"': case '\'': case '|': case '>':
181  case '{': case '}': case '[': case ']':
182  case '#': case '`': case '%': case '@':
183  return false;
184  case '-': case ':': case '?':
185  if(s.len == 1 || (s.str[1] == ' ' || s.str[1] == '\t'))
186  return false;
187  break;
188  }
189  // bulk
190  for(size_t i = 1; i + 1 < s.len; ++i)
191  {
192  switch(s.str[i])
193  {
194  case ',': case '{': case '}': case '[': case ']':
195  return false;
196  case ':': case '#':
197  if(!_is_valid_bulk(s, i))
198  return false;
199  break;
200  }
201  }
202  // last
203  if(s.len > 1)
204  {
205  switch(s.back())
206  {
207  case ' ': case '\n': case '\t': case '\r':
208  case ',':
209  case '{': case '}':
210  case '[': case ']':
211  case '#':
212  case ':':
213  return false;
214  }
215  }
216  return true;
217 }

◆ scalar_style_query_plain_block()

bool c4::yml::scalar_style_query_plain_block ( csubstr  s)
noexcept

query whether a scalar can be encoded using plain style while in block mode.

Plain scalars [have more constraints in flow mode than in block mode](https://www.yaml.info/learn/quote.html#noplain). scalar_style_query_plain_flow() is the flow mode analogous function.

Definition at line 219 of file node_type.cpp.

220 {
221  if(!s.len)
222  return !s.str;
223  // first
224  switch(s.str[0])
225  {
226  case ' ': case '\n': case '\t': case '\r':
227  case '!': case '&': case '*': case ',':
228  case '"': case '\'': case '|': case '>':
229  case '{': case '}': case '[': case ']':
230  case '#': case '`': case '%': case '@':
231  return false;
232  case '-': case ':': case '?':
233  if (s.len == 1 || (s.str[1] == ' ' || s.str[1] == '\t'))
234  return false;
235  break;
236  }
237  // bulk
238  for(size_t i = 1; i + 1 < s.len; ++i)
239  {
240  switch(s.str[i])
241  {
242  case ':': case '#':
243  if(!_is_valid_bulk(s, i))
244  return false;
245  break;
246  }
247  }
248  // last
249  if(s.len > 1)
250  {
251  switch(s.back())
252  {
253  case ' ': case '\n': case '\t': case '\r':
254  case '#':
255  case ':':
256  return false;
257  }
258  }
259  return true;
260 }

◆ scalar_style_query_plain()

bool c4::yml::scalar_style_query_plain ( csubstr  s,
bool  flow = true 
)
inlinenoexcept

query whether a scalar can be encoded using plain style.

Legacy compatibility function: assumes flow mode which is more constraining, and delegates to either scalar_style_query_plain_flow() or scalar_style_query_plain_block().

Definition at line 314 of file node_type.hpp.

315 {
317 }

◆ scalar_is_null()

bool c4::yml::scalar_is_null ( csubstr  s)
noexcept

YAML-sense query of nullity.

returns true if the scalar points to nullptr or is otherwise equal to one of the strings "~","null","Null","NULL"

Definition at line 289 of file node_type.cpp.

290 {
291  return s.str == nullptr ||
292  (s.len == 1 && (s.str[0] == '~')) ||
293  (s.len == 4 && ((0 == memcmp("null", s.str, 4))
294  || (0 == memcmp("Null", s.str, 4))
295  || (0 == memcmp("NULL", s.str, 4))));
296 }