rapidyaml 0.15.2
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
node_type.hpp
Go to the documentation of this file.
1#ifndef _C4_YML_NODE_TYPE_HPP_
2#define _C4_YML_NODE_TYPE_HPP_
3
4#ifndef _C4_YML_COMMON_HPP_
5#include "c4/yml/common.hpp"
6#endif
7
8C4_SUPPRESS_WARNING_MSVC_PUSH
9C4_SUPPRESS_WARNING_GCC_CLANG_PUSH
10C4_SUPPRESS_WARNING_GCC_CLANG("-Wold-style-cast")
11#if defined(__GNUC__) && __GNUC__ >= 6
12C4_SUPPRESS_WARNING_GCC("-Wnull-dereference")
13#endif
14// NOLINTBEGIN(modernize-avoid-c-style-cast)
15
16namespace c4 {
17namespace yml {
18
19/** @addtogroup doc_node_type
20 *
21 * @{
22 */
23
24//-----------------------------------------------------------------------------
25//-----------------------------------------------------------------------------
26//-----------------------------------------------------------------------------
27
28
29/** the integral type necessary to cover all the bits for NodeType_e */
30using type_bits = uint32_t;
31
32
33/** a bit mask for marking node types and styles */
34typedef enum : 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), ///< the scalar to the left of `:` in a map's member
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 @ref ParserOptions::scalar_filtering()
56 VAL_UNFILT = __(15), ///< the val scalar was left unfiltered; the parser was set not to filter. @see @ref ParserOptions::scalar_filtering()
57 //
58 // style flags:
59 //
60 FLOW_SL = __(16), ///< mark container with single-line flow style
61 ///< - seqs as
62 ///< @code{yaml}
63 ///< [val1,val2]
64 ///< @endcode
65 ///< when @ref FLOW_SPC is not set, or
66 ///< @code{yaml}
67 ///< [val1, val2]
68 ///< @endcode
69 ///< when @ref FLOW_SPC is set (or @ref EmitOptions::force_flow_spc() is set)
70 ///< - maps as
71 ///< @code{yaml}
72 ///< {key1: val1,key2: val2}
73 ///< @endcode
74 ///< when @ref FLOW_SPC is not set, or
75 ///< @code{yaml}
76 ///< {key1: val1, key2: val2}
77 ///< @endcode
78 ///< when @ref FLOW_SPC is set (or @ref EmitOptions::force_flow_spc() is set)
79 FLOW_ML1 = __(17), ///< mark container with multi-line flow style, 1 element per line
80 ///< - seqs as
81 ///< @code{yaml}
82 ///< [
83 ///< val1,
84 ///< val2
85 ///< ]
86 ///< @endcode
87 ///< - maps as
88 ///< @code{yaml}
89 ///< {
90 ///< key: val,
91 ///< key2: val2
92 ///< }
93 ///< @endcode
94 FLOW_MLN = __(18), ///< mark container with multi-line flow style, n elements per line,
95 ///< wrapped (as set by @ref EmitOptions::max_cols()):
96 ///< - seqs as
97 ///< @code{yaml}
98 ///< [
99 ///< val,val,...
100 ///< val,val,...
101 ///< val,val,...
102 ///< ...
103 ///< val
104 ///< ]
105 ///< @endcode
106 ///< when @ref FLOW_SPC is not set, or
107 ///< @code{yaml}
108 ///< [
109 ///< val, val,...
110 ///< val, val,...
111 ///< val, val,...
112 ///< ...
113 ///< val
114 ///< ]
115 ///< @endcode
116 ///< when @ref FLOW_SPC is set (or @ref EmitOptions::force_flow_spc() is set)
117 ///< - maps as
118 ///< @code{yaml}
119 ///< {
120 ///< key: val,key: val,...
121 ///< key: val,key: val,...
122 ///< ...
123 ///< key: val
124 ///< }
125 ///< @endcode
126 ///< when @ref FLOW_SPC is not set, or
127 ///< @code{yaml}
128 ///< {
129 ///< key: val, key: val,...
130 ///< key: val, key: val,...
131 ///< ...
132 ///< key: val
133 ///< }
134 ///< @endcode
135 ///< when @ref FLOW_SPC is set (or @ref EmitOptions::force_flow_spc() is set)
136 FLOW_SPC = __(19), ///< mark container with spaces after comma when in flow mode.
137 ///< Applies to both @ref FLOW_SL and @ref FLOW_MLN (but not
138 ///< to @ref FLOW_ML1), and can be overriden globally by
139 ///< @ref EmitOptions::force_flow_spc().
140 BLOCK = __(20), ///< mark container with block style
141 ///< - seqs as
142 ///< @code{yaml}
143 ///< - val1
144 ///< - val2
145 ///< @endcode
146 ///< - maps as
147 ///< @code{yaml}
148 ///< key1: val1
149 ///< key2: val2
150 ///< @endcode
151 KEY_LITERAL = __(21), ///< mark key scalar as multiline, block literal |
152 VAL_LITERAL = __(22), ///< mark val scalar as multiline, block literal |
153 KEY_FOLDED = __(23), ///< mark key scalar as multiline, block folded >
154 VAL_FOLDED = __(24), ///< mark val scalar as multiline, block folded >
155 KEY_SQUO = __(25), ///< mark key scalar as single quoted '
156 VAL_SQUO = __(26), ///< mark val scalar as single quoted '
157 KEY_DQUO = __(27), ///< mark key scalar as double quoted "
158 VAL_DQUO = __(28), ///< mark val scalar as double quoted "
159 KEY_PLAIN = __(29), ///< mark key scalar as plain scalar (unquoted, even when multiline)
160 VAL_PLAIN = __(30), ///< mark val scalar as plain scalar (unquoted, even when multiline)
161 //
162 // type combination masks:
163 //
164 KEYVAL = KEY|VAL, ///< mask of @ref KEY|@ref VAL
165 KEYSEQ = KEY|SEQ, ///< mask of @ref KEY|@ref SEQ
166 KEYMAP = KEY|MAP, ///< mask of @ref KEY|@ref MAP
167 DOCMAP = DOC|MAP, ///< mask of @ref DOC|@ref MAP
168 DOCSEQ = DOC|SEQ, ///< mask of @ref DOC|@ref SEQ
169 DOCVAL = DOC|VAL, ///< mask of @ref DOC|@ref VAL
170 //
171 // style combination masks:
172 //
173 SCALAR_LITERAL = KEY_LITERAL|VAL_LITERAL, ///< mask of @ref KEY_LITERAL|@ref VAL_LITERAL,
174 SCALAR_FOLDED = KEY_FOLDED|VAL_FOLDED, ///< mask of @ref KEY_FOLDED|@ref VAL_FOLDED,
175 SCALAR_SQUO = KEY_SQUO|VAL_SQUO, ///< mask of @ref KEY_SQUO|@ref VAL_SQUO,
176 SCALAR_DQUO = KEY_DQUO|VAL_DQUO, ///< mask of @ref KEY_DQUO|@ref VAL_DQUO,
177 SCALAR_PLAIN = KEY_PLAIN|VAL_PLAIN, ///< mask of @ref KEY_PLAIN|@ref VAL_PLAIN,
178 KEYQUO = KEY_SQUO|KEY_DQUO|KEY_FOLDED|KEY_LITERAL, ///< key style is one of `'">|`. mask of @ref KEY_SQUO|@ref KEY_DQUO|@ref KEY_FOLDED|@ref KEY_LITERAL
179 VALQUO = VAL_SQUO|VAL_DQUO|VAL_FOLDED|VAL_LITERAL, ///< val style is one of `'">|`. mask of @ref VAL_SQUO|@ref VAL_DQUO|@ref VAL_FOLDED|@ref VAL_LITERAL
180 KEY_STYLE = KEYQUO|KEY_PLAIN, ///< mask of @ref KEYQUO|@ref KEY_PLAIN : all the key scalar styles for key (not container styles!)
181 VAL_STYLE = VALQUO|VAL_PLAIN, ///< mask of @ref VALQUO|@ref VAL_PLAIN : all the val scalar styles for val (not container styles!)
182 SCALAR_STYLE = KEY_STYLE|VAL_STYLE, ///< mask of @ref KEY_STYLE|@ref VAL_STYLE : all the key+val scalar styles
183 FLOW_MLX = FLOW_ML1|FLOW_MLN, ///< mask of @ref FLOW_ML1|@ref FLOW_MLN : all the flow multiline styles
184 CONTAINER_STYLE_FLOW = FLOW_SL|FLOW_MLX|FLOW_SPC, ///< mask of @ref FLOW_SL|@ref FLOW_MLX|@ref FLOW_SPC : all flow flags
185 CONTAINER_STYLE_BLOCK = BLOCK, ///< alias to @ref BLOCK
186 CONTAINER_STYLE = CONTAINER_STYLE_FLOW|CONTAINER_STYLE_BLOCK, ///< mask of @ref CONTAINER_STYLE_FLOW|@ref CONTAINER_STYLE_BLOCK : all container style flags
187 STYLE = SCALAR_STYLE | CONTAINER_STYLE, ///< mask of @ref SCALAR_STYLE | @ref CONTAINER_STYLE : all style flags
188 /** @cond dev */
189 //
190 // mixed masks
191 _KEYMASK = KEY | KEYQUO | KEYANCH | KEYREF | KEYTAG,
192 _VALMASK = VAL | VALQUO | VALANCH | VALREF | VALTAG,
193 #undef __
194 #if C4_CPP >= 17 \
195 || (defined(__GNUC__) && __GNUC__ >= 6) \
196 || (defined(_MSC_VER) && !defined(__clang__))
197 #define RYML_HAS_DEPRECATED_ENUMS__
198 FLOW_ML RYML_DEPRECATED("use one of FLOW_ML{1,N,X}") = FLOW_ML1,
199 #endif
200 /** @endcond */
201} NodeType_e;
202/** @cond dev */
203#if !defined(RYML_HAS_DEPRECATED_ENUMS__)
204// defined here because the current c++ standard / compiler cannot
205// handle deprecated enums
206RYML_DEPRECATED("use one of FLOW_ML{1,N,X}")
207constexpr const NodeType_e FLOW_ML = FLOW_ML1;
208#endif
209/** @endcond */
210
211constexpr C4_ALWAYS_INLINE C4_CONST NodeType_e operator| (NodeType_e lhs, NodeType_e rhs) noexcept { return (NodeType_e)(((type_bits)lhs) | ((type_bits)rhs)); }
212constexpr C4_ALWAYS_INLINE C4_CONST NodeType_e operator& (NodeType_e lhs, NodeType_e rhs) noexcept { return (NodeType_e)(((type_bits)lhs) & ((type_bits)rhs)); }
213constexpr C4_ALWAYS_INLINE C4_CONST NodeType_e operator>> (NodeType_e bits, uint32_t n) noexcept { return (NodeType_e)(((type_bits)bits) >> n); }
214constexpr C4_ALWAYS_INLINE C4_CONST NodeType_e operator<< (NodeType_e bits, uint32_t n) noexcept { return (NodeType_e)(((type_bits)bits) << n); }
215constexpr C4_ALWAYS_INLINE C4_CONST NodeType_e operator~ (NodeType_e bits) noexcept { return (NodeType_e)(~(type_bits)bits); }
216C4_ALWAYS_INLINE NodeType_e& operator&= (NodeType_e &subject, NodeType_e bits) noexcept { subject = (NodeType_e)((type_bits)subject & (type_bits)bits); return subject; }
217C4_ALWAYS_INLINE NodeType_e& operator|= (NodeType_e &subject, NodeType_e bits) noexcept { subject = (NodeType_e)((type_bits)subject | (type_bits)bits); return subject; }
218
219
220//-----------------------------------------------------------------------------
221//-----------------------------------------------------------------------------
222//-----------------------------------------------------------------------------
223
224/** wraps a NodeType_e element with some syntactic sugar and predicates */
226{
227public:
228
230
231public:
232
233 C4_ALWAYS_INLINE NodeType() noexcept : type(NOTYPE) {}
234 C4_ALWAYS_INLINE NodeType(NodeType_e t) noexcept : type(t) {}
235 C4_ALWAYS_INLINE NodeType(type_bits t) noexcept : type((NodeType_e)t) {}
236
237 C4_ALWAYS_INLINE bool has_any(NodeType_e t) const noexcept { return (type & t) != 0u; }
238 C4_ALWAYS_INLINE bool has_all(NodeType_e t) const noexcept { return (type & t) == t; }
239 C4_ALWAYS_INLINE bool has_none(NodeType_e t) const noexcept { return (type & t) == 0; }
240
241 C4_ALWAYS_INLINE void set(NodeType_e t) noexcept { type = t; }
242 C4_ALWAYS_INLINE void add(NodeType_e t) noexcept { type = (type|t); }
243 C4_ALWAYS_INLINE void rem(NodeType_e t) noexcept { type = (type & ~t); }
244 C4_ALWAYS_INLINE void addrem(NodeType_e bits_to_add, NodeType_e bits_to_remove) noexcept { type |= bits_to_add; type &= ~bits_to_remove; }
245
246 C4_ALWAYS_INLINE void clear() noexcept { type = NOTYPE; }
247
248public:
249
250 C4_ALWAYS_INLINE operator NodeType_e & C4_RESTRICT () noexcept { return type; }
251 C4_ALWAYS_INLINE operator NodeType_e const& C4_RESTRICT () const noexcept { return type; }
252
253public:
254
255 /** @name node type queries
256 * @{ */
257
258 /** return a preset string based on the node type */
259 C4_ALWAYS_INLINE const char *type_str() const noexcept { return type_str(type); }
260 /** return a preset string based on the node type */
261 static const char* type_str(NodeType_e t) noexcept;
262
263 /** fill a string with the node type flags. */
264 C4_ALWAYS_INLINE size_t type_str(substr buf) const noexcept { return type_str(buf, type); }
265 /** fill a string with the node type flags. */
266 static size_t type_str(substr buf, NodeType_e t) noexcept;
267
268 /** fill a string with the node type flags. If the string is small, returns {null, len} */
269 C4_ALWAYS_INLINE csubstr type_str_sub(substr buf) const noexcept { return type_str_sub(buf, type); }
270 /** fill a string with the node type flags. If the string is small, returns {null, len} */
271 static csubstr type_str_sub(substr buf, NodeType_e t) noexcept
272 {
273 csubstr ret;
274 ret.len = type_str(buf, t);
275 ret.str = ret.len < buf.len ? buf.str : nullptr;
276 return ret;
277 }
278
279public:
280
281 /** @name node type queries
282 * @{ */
283
284 C4_ALWAYS_INLINE bool is_notype() const noexcept { return type == NOTYPE; }
285 C4_ALWAYS_INLINE bool is_stream() const noexcept { return ((type & STREAM) == STREAM) != 0; }
286 C4_ALWAYS_INLINE bool is_doc() const noexcept { return (type & DOC) != 0; }
287 C4_ALWAYS_INLINE bool is_container() const noexcept { return (type & (MAP|SEQ|STREAM)) != 0; }
288 C4_ALWAYS_INLINE bool is_map() const noexcept { return (type & MAP) != 0; }
289 C4_ALWAYS_INLINE bool is_seq() const noexcept { return (type & SEQ) != 0; }
290 C4_ALWAYS_INLINE bool has_key() const noexcept { return (type & KEY) != 0; }
291 C4_ALWAYS_INLINE bool has_val() const noexcept { return (type & VAL) != 0; }
292 C4_ALWAYS_INLINE bool is_val() const noexcept { return (type & KEYVAL) == VAL; }
293 C4_ALWAYS_INLINE bool is_keyval() const noexcept { return (type & KEYVAL) == KEYVAL; }
294 C4_ALWAYS_INLINE bool key_is_null() const noexcept { return (type & KEYNIL) != 0; }
295 C4_ALWAYS_INLINE bool val_is_null() const noexcept { return (type & VALNIL) != 0; }
296 C4_ALWAYS_INLINE bool has_key_tag() const noexcept { return (type & KEYTAG) != 0; }
297 C4_ALWAYS_INLINE bool has_val_tag() const noexcept { return (type & VALTAG) != 0; }
298 C4_ALWAYS_INLINE bool has_key_anchor() const noexcept { return (type & KEYANCH) != 0; }
299 C4_ALWAYS_INLINE bool has_val_anchor() const noexcept { return (type & VALANCH) != 0; }
300 C4_ALWAYS_INLINE bool has_anchor() const noexcept { return (type & (KEYANCH|VALANCH)) != 0; }
301 C4_ALWAYS_INLINE bool is_key_ref() const noexcept { return (type & KEYREF) != 0; }
302 C4_ALWAYS_INLINE bool is_val_ref() const noexcept { return (type & VALREF) != 0; }
303 C4_ALWAYS_INLINE bool is_ref() const noexcept { return (type & (KEYREF|VALREF)) != 0; }
304
305 C4_ALWAYS_INLINE bool is_key_unfiltered() const noexcept { return (type & (KEY_UNFILT)) != 0; }
306 C4_ALWAYS_INLINE bool is_val_unfiltered() const noexcept { return (type & (VAL_UNFILT)) != 0; }
307
308 /** @} */
309
310public:
311
312 /** @name style functions
313 * @{ */
314
315 C4_ALWAYS_INLINE bool is_container_styled() const noexcept { return (type & (CONTAINER_STYLE)) != 0; }
316 C4_ALWAYS_INLINE bool is_block() const noexcept { return (type & (BLOCK)) != 0; }
317 C4_ALWAYS_INLINE bool is_flow_sl() const noexcept { return (type & (FLOW_SL)) != 0; }
318 C4_ALWAYS_INLINE bool is_flow_ml1() const noexcept { return (type & (FLOW_ML1)) != 0; }
319 C4_ALWAYS_INLINE bool is_flow_mln() const noexcept { return (type & (FLOW_MLN)) != 0; }
320 C4_ALWAYS_INLINE bool is_flow_mlx() const noexcept { return (type & (FLOW_ML1|FLOW_MLN)) != 0; }
321 C4_ALWAYS_INLINE bool is_flow() const noexcept { return (type & (FLOW_ML1|FLOW_MLN|FLOW_SL)) != 0; }
322 C4_ALWAYS_INLINE bool has_flow_space() const noexcept { return (type & (FLOW_SPC)) != 0; }
323
324 C4_ALWAYS_INLINE bool is_key_styled() const noexcept { return (type & (KEY_STYLE)) != 0; }
325 C4_ALWAYS_INLINE bool is_val_styled() const noexcept { return (type & (VAL_STYLE)) != 0; }
326 C4_ALWAYS_INLINE bool is_key_literal() const noexcept { return (type & (KEY_LITERAL)) != 0; }
327 C4_ALWAYS_INLINE bool is_val_literal() const noexcept { return (type & (VAL_LITERAL)) != 0; }
328 C4_ALWAYS_INLINE bool is_key_folded() const noexcept { return (type & (KEY_FOLDED)) != 0; }
329 C4_ALWAYS_INLINE bool is_val_folded() const noexcept { return (type & (VAL_FOLDED)) != 0; }
330 C4_ALWAYS_INLINE bool is_key_squo() const noexcept { return (type & (KEY_SQUO)) != 0; }
331 C4_ALWAYS_INLINE bool is_val_squo() const noexcept { return (type & (VAL_SQUO)) != 0; }
332 C4_ALWAYS_INLINE bool is_key_dquo() const noexcept { return (type & (KEY_DQUO)) != 0; }
333 C4_ALWAYS_INLINE bool is_val_dquo() const noexcept { return (type & (VAL_DQUO)) != 0; }
334 C4_ALWAYS_INLINE bool is_key_plain() const noexcept { return (type & (KEY_PLAIN)) != 0; }
335 C4_ALWAYS_INLINE bool is_val_plain() const noexcept { return (type & (VAL_PLAIN)) != 0; }
336 C4_ALWAYS_INLINE bool is_key_quoted() const noexcept { return (type & KEYQUO) != 0; }
337 C4_ALWAYS_INLINE bool is_val_quoted() const noexcept { return (type & VALQUO) != 0; }
338 C4_ALWAYS_INLINE bool is_quoted() const noexcept { return (type & (KEYQUO|VALQUO)) != 0; }
339
340 C4_ALWAYS_INLINE NodeType key_style() const noexcept { return (type & (KEY_STYLE)); }
341 C4_ALWAYS_INLINE NodeType val_style() const noexcept { return (type & (VAL_STYLE)); }
342
343 C4_ALWAYS_INLINE void set_container_style(NodeType_e style) noexcept { type = ((style & CONTAINER_STYLE) | (type & ~CONTAINER_STYLE)); }
344 C4_ALWAYS_INLINE void set_key_style(NodeType_e style) noexcept { type = ((style & KEY_STYLE) | (type & ~KEY_STYLE)); }
345 C4_ALWAYS_INLINE void set_val_style(NodeType_e style) noexcept { type = ((style & VAL_STYLE) | (type & ~VAL_STYLE)); }
346 C4_ALWAYS_INLINE void clear_style() noexcept { type &= ~STYLE; }
347
348 /** @} */
349
350public: // deprecated methods
351
352 /** @cond dev */ // LCOV_EXCL_START
353 RYML_DEPRECATED("use has_key_anchor()") bool is_key_anchor() const noexcept { return has_key_anchor(); }
354 RYML_DEPRECATED("use has_val_anchor()") bool is_val_anchor() const noexcept { return has_val_anchor(); }
355 RYML_DEPRECATED("use has_anchor()") bool is_anchor() const noexcept { return has_anchor(); }
356 RYML_DEPRECATED("use has_anchor() || is_ref()") bool is_anchor_or_ref() const noexcept { return has_anchor() || is_ref(); }
357
358 RYML_DEPRECATED("use one of .is_flow_ml{1,n,x}()")
359 bool is_flow_ml() const noexcept { return (type & (FLOW_ML1)) != 0; }
360 /** @endcond */ // LCOV_EXCL_STOP
361};
362
363
364//-----------------------------------------------------------------------------
365//-----------------------------------------------------------------------------
366//-----------------------------------------------------------------------------
367
368/** @name scalar style helpers
369 * @{ */
370
371/** choose a YAML scalar style based on the scalar's contents, while
372 * in flow mode. Plain scalars [have more constraints in flow mode
373 * than in block
374 * mode](https://www.yaml.info/learn/quote.html#noplain). @ref
375 * scalar_style_choose_block() is the block mode analogous
376 * function. */
378/** choose a YAML scalar style based on the scalar's contents, while
379 * in block mode. Plain scalars [have more constraints in flow mode
380 * than in block
381 * mode](https://www.yaml.info/learn/quote.html#noplain). @ref
382 * scalar_style_choose_block() is the flow mode analogous function. */
384/** choose a YAML emitting style based on the scalar's
385 * contents. Legacy compatibility function: assumes flow mode which is
386 * more constraining, and delegates to either @ref
387 * scalar_style_choose_flow() or @ref scalar_style_choose_block(). */
388inline NodeType_e scalar_style_choose(csubstr s, bool flow=true) noexcept
389{
391}
392
393
394/** choose a json scalar style based on the scalar's contents */
396/** @cond dev */ // LCOV_EXCL_START
397RYML_DEPRECATED("use scalar_style_choose_json()")
398inline NodeType_e scalar_style_json_choose(csubstr scalar) noexcept
399{
400 return scalar_style_choose_json(scalar);
401}
402/** @endcond */ // LCOV_EXCL_STOP
403
404
405/** query whether a scalar can be encoded using single quotes.
406 * It may not be possible, notably when there is leading
407 * whitespace after a newline. */
409
410/** query whether a scalar can be encoded using plain style while in
411 * flow mode. Plain scalars [have more constraints in flow mode than
412 * in block
413 * mode](https://www.yaml.info/learn/quote.html#noplain). @ref
414 * scalar_style_query_plain_block() is the block mode analogous function.*/
416/** query whether a scalar can be encoded using plain style while in
417 * block mode. Plain scalars [have more constraints in flow mode than
418 * in block
419 * mode](https://www.yaml.info/learn/quote.html#noplain). @ref
420 * scalar_style_query_plain_flow() is the flow mode analogous function.*/
422/** query whether a scalar can be encoded using plain style. Legacy
423 * compatibility function: assumes flow mode which is more
424 * constraining, and delegates to either @ref
425 * scalar_style_query_plain_flow() or @ref
426 * scalar_style_query_plain_block(). */
427inline bool scalar_style_query_plain(csubstr s, bool flow=true) noexcept
428{
430}
431
432/** YAML-sense query of nullity. returns true if the scalar points
433 * to `nullptr` or is otherwise equal to one of the strings
434 * `"~"`,`"null"`,`"Null"`,`"NULL"` */
435RYML_EXPORT bool scalar_is_null(csubstr s) noexcept;
436
437/** @} */
438
439/** @} */
440
441} // namespace yml
442} // namespace c4
443
444// NOLINTEND(modernize-avoid-c-style-cast)
445C4_SUPPRESS_WARNING_MSVC_POP
446C4_SUPPRESS_WARNING_GCC_CLANG_POP
447
448#endif /* _C4_YML_NODE_TYPE_HPP_ */
Common utilities and infrastructure used by ryml.
#define RYML_EXPORT
Definition export.hpp:18
OStream & operator<<(OStream &s, Tree const &t)
emit YAML to an STL-like ostream
Definition emit.hpp:633
constexpr C4_CONST NodeType_e operator&(NodeType_e lhs, NodeType_e rhs) noexcept
bool scalar_style_query_plain_block(csubstr s) noexcept
query whether a scalar can be encoded using plain style while in block mode.
constexpr C4_CONST NodeType_e operator|(NodeType_e lhs, NodeType_e rhs) noexcept
NodeType_e & operator|=(NodeType_e &subject, NodeType_e bits) noexcept
bool scalar_is_null(csubstr s) noexcept
YAML-sense query of nullity.
constexpr C4_CONST NodeType_e operator>>(NodeType_e bits, uint32_t n) noexcept
bool scalar_style_query_squo(csubstr s) noexcept
query whether a scalar can be encoded using single quotes.
NodeType_e scalar_style_choose(csubstr s, bool flow=true) noexcept
choose a YAML emitting style based on the scalar's contents.
NodeType_e & operator&=(NodeType_e &subject, NodeType_e bits) noexcept
NodeType_e scalar_style_choose_flow(csubstr s) noexcept
choose a YAML scalar style based on the scalar's contents, while in flow mode.
NodeType_e scalar_style_choose_block(csubstr s) noexcept
choose a YAML scalar style based on the scalar's contents, while in block mode.
bool scalar_style_query_plain_flow(csubstr s) noexcept
query whether a scalar can be encoded using plain style while in flow mode.
constexpr C4_CONST NodeType_e operator~(NodeType_e bits) noexcept
NodeType_e
a bit mask for marking node types and styles
Definition node_type.hpp:34
NodeType_e scalar_style_choose_json(csubstr s) noexcept
choose a json scalar style based on the scalar's contents
uint32_t type_bits
the integral type necessary to cover all the bits for NodeType_e
Definition node_type.hpp:30
bool scalar_style_query_plain(csubstr s, bool flow=true) noexcept
query whether a scalar can be encoded using plain style.
@ 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
mask of KEY_FOLDED|VAL_FOLDED,
@ KEY_DQUO
mark key scalar as double quoted "
@ 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
@ FLOW_MLX
mask of FLOW_ML1|FLOW_MLN : all the flow multiline styles
@ STREAM
a stream: a seq of docs
Definition node_type.hpp:42
@ KEY
the scalar to the left of : in a map's member
Definition node_type.hpp:37
@ KEYQUO
key style is one of '">|. mask of KEY_SQUO|KEY_DQUO|KEY_FOLDED|KEY_LITERAL
@ FLOW_ML1
mark container with multi-line flow style, 1 element per line
Definition node_type.hpp:79
@ VAL_FOLDED
mark val scalar as multiline, block folded >
@ CONTAINER_STYLE_BLOCK
alias to BLOCK
@ VAL_STYLE
mask of VALQUO|VAL_PLAIN : all the val scalar styles for val (not container styles!...
@ KEYTAG
the key has a tag
Definition node_type.hpp:47
@ CONTAINER_STYLE_FLOW
mask of FLOW_SL|FLOW_MLX|FLOW_SPC : all flow flags
@ SCALAR_SQUO
mask of KEY_SQUO|VAL_SQUO,
@ FLOW_SL
mark container with single-line flow style
Definition node_type.hpp:60
@ 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
@ KEYMAP
mask of KEY|MAP
@ VALTAG
the val has a tag
Definition node_type.hpp:48
@ SCALAR_STYLE
mask of KEY_STYLE|VAL_STYLE : all the key+val scalar styles
@ KEYSEQ
mask of KEY|SEQ
@ _TYMASK
all the bits up to here
Definition node_type.hpp:51
@ FLOW_MLN
mark container with multi-line flow style, n elements per line, wrapped (as set by EmitOptions::max_c...
Definition node_type.hpp:94
@ SCALAR_LITERAL
mask of KEY_LITERAL|VAL_LITERAL,
@ SEQ
a seq: a parent of VAL/SEQ/MAP nodes
Definition node_type.hpp:40
@ SCALAR_DQUO
mask of KEY_DQUO|VAL_DQUO,
@ VAL_SQUO
mark val scalar as single quoted '
@ DOCSEQ
mask of DOC|SEQ
@ KEY_STYLE
mask of KEYQUO|KEY_PLAIN : all the key scalar styles for key (not container styles!...
@ VAL_PLAIN
mark val scalar as plain scalar (unquoted, even when multiline)
@ KEYREF
a *reference: the key references an &anchor
Definition node_type.hpp:43
@ DOCMAP
mask of DOC|MAP
@ BLOCK
mark container with block style
@ FLOW_SPC
mark container with spaces after comma when in flow mode. Applies to both FLOW_SL and FLOW_MLN (but n...
@ DOCVAL
mask of DOC|VAL
@ STYLE
mask of SCALAR_STYLE | CONTAINER_STYLE : all style flags
@ KEYVAL
mask of KEY|VAL
@ KEYANCH
the key has an &anchor
Definition node_type.hpp:45
@ VALQUO
val style is one of '">|. mask of VAL_SQUO|VAL_DQUO|VAL_FOLDED|VAL_LITERAL
@ VAL_DQUO
mark val scalar as double quoted "
@ CONTAINER_STYLE
mask of CONTAINER_STYLE_FLOW|CONTAINER_STYLE_BLOCK : all container style flags
@ 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 '
@ VAL_LITERAL
mark val scalar as multiline, block literal |
@ KEY_LITERAL
mark key scalar as multiline, block literal |
@ KEY_PLAIN
mark key scalar as plain scalar (unquoted, even when multiline)
@ SCALAR_PLAIN
mask of KEY_PLAIN|VAL_PLAIN,
@ KEY_FOLDED
mark key scalar as multiline, block folded >
@ 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
basic_substring< char > substr
a mutable string view
Definition substr.hpp:2356
basic_substring< const char > csubstr
an immutable string view
Definition substr.hpp:2357
(Undefined by default) Use shorter error message from checks/asserts: do not show the check condition...
Definition common.cpp:14
#define __(v)
Definition node_type.hpp:35
size_t len
the length of the substring
Definition substr.hpp:218
C * str
a restricted pointer to the first character of the substring
Definition substr.hpp:216
bool has_all(NodeType_e t) const noexcept
bool is_val_squo() const noexcept
bool is_key_plain() const noexcept
bool is_flow_mln() const noexcept
bool has_key() const noexcept
bool is_quoted() const noexcept
bool is_val_folded() const noexcept
bool has_none(NodeType_e t) const noexcept
bool has_key_tag() const noexcept
bool is_ref() const noexcept
NodeType(NodeType_e t) noexcept
bool has_flow_space() const noexcept
void set_container_style(NodeType_e style) noexcept
bool is_key_ref() const noexcept
void set_key_style(NodeType_e style) noexcept
bool key_is_null() const noexcept
bool has_any(NodeType_e t) const noexcept
bool is_key_dquo() const noexcept
bool is_doc() const noexcept
bool is_seq() const noexcept
bool is_val_plain() const noexcept
bool is_notype() const noexcept
bool is_key_quoted() const noexcept
bool is_flow_mlx() const noexcept
void rem(NodeType_e t) noexcept
bool has_val_anchor() const noexcept
static csubstr type_str_sub(substr buf, NodeType_e t) noexcept
fill a string with the node type flags.
bool is_key_unfiltered() const noexcept
bool has_val_tag() const noexcept
bool is_key_literal() const noexcept
bool is_key_squo() const noexcept
bool has_anchor() const noexcept
NodeType(type_bits t) noexcept
bool has_key_anchor() const noexcept
bool has_val() const noexcept
void clear() noexcept
bool is_val_unfiltered() const noexcept
bool is_flow_ml1() const noexcept
bool is_flow_sl() const noexcept
const char * type_str() const noexcept
return a preset string based on the node type
bool is_map() const noexcept
bool is_val_styled() const noexcept
bool is_key_folded() const noexcept
bool is_container() const noexcept
bool is_container_styled() const noexcept
bool is_val_literal() const noexcept
bool is_key_styled() const noexcept
bool is_block() const noexcept
NodeType val_style() const noexcept
bool val_is_null() const noexcept
void set_val_style(NodeType_e style) noexcept
void addrem(NodeType_e bits_to_add, NodeType_e bits_to_remove) noexcept
void add(NodeType_e t) noexcept
size_t type_str(substr buf) const noexcept
fill a string with the node type flags.
void set(NodeType_e t) noexcept
bool is_keyval() const noexcept
bool is_val() const noexcept
void clear_style() noexcept
bool is_val_ref() const noexcept
bool is_val_quoted() const noexcept
bool is_val_dquo() const noexcept
NodeType key_style() const noexcept
bool is_stream() const noexcept
NodeType() noexcept
bool is_flow() const noexcept
csubstr type_str_sub(substr buf) const noexcept
fill a string with the node type flags.