rapidyaml 0.15.2
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
node_type.cpp
Go to the documentation of this file.
1#ifndef C4_YML_NODE_TYPE_HPP_
3#endif
4#ifndef C4_YML_ERROR_HPP_
5#include "c4/yml/error.hpp"
6#endif
7
8
9namespace c4 {
10namespace yml {
11
12const char* NodeType::type_str(type_bits ty) noexcept
13{
14 switch(ty & TYMASK_)
15 {
16 case KEYVAL:
17 return "KEYVAL";
18 case KEY:
19 return "KEY";
20 case VAL:
21 return "VAL";
22 case MAP:
23 return "MAP";
24 case SEQ:
25 return "SEQ";
26 case KEYMAP:
27 return "KEYMAP";
28 case KEYSEQ:
29 return "KEYSEQ";
30 case DOCSEQ:
31 return "DOCSEQ";
32 case DOCMAP:
33 return "DOCMAP";
34 case DOCVAL:
35 return "DOCVAL";
36 case DOC:
37 return "DOC";
38 case STREAM:
39 return "STREAM";
40 case NOTYPE:
41 return "NOTYPE";
42 default:
43 if((ty & KEYVAL) == KEYVAL)
44 return "KEYVAL***";
45 if((ty & KEYMAP) == KEYMAP)
46 return "KEYMAP***";
47 if((ty & KEYSEQ) == KEYSEQ)
48 return "KEYSEQ***";
49 if((ty & DOCSEQ) == DOCSEQ)
50 return "DOCSEQ***";
51 if((ty & DOCMAP) == DOCMAP)
52 return "DOCMAP***";
53 if((ty & DOCVAL) == DOCVAL)
54 return "DOCVAL***";
55 if(ty & KEY)
56 return "KEY***";
57 if(ty & VAL)
58 return "VAL***";
59 if(ty & MAP)
60 return "MAP***";
61 if(ty & SEQ)
62 return "SEQ***";
63 if(ty & DOC)
64 return "DOC***";
65 return "(unk)";
66 }
67}
68
69namespace {
70struct type_and_name { const char* str; type_bits bits; };
71constexpr const type_and_name type_names[] = {
72 {"STREAM", STREAM},
73 {"DOC", DOC},
74 // key properties
75 {"KEY", KEY},
76 {"KNIL", KEYNIL},
77 {"KTAG", KEYTAG},
78 {"KANCH", KEYANCH},
79 {"KREF", KEYREF},
80 {"KLITERAL", KEY_LITERAL},
81 {"KFOLDED", KEY_FOLDED},
82 {"KSQUO", KEY_SQUO},
83 {"KDQUO", KEY_DQUO},
84 {"KPLAIN", KEY_PLAIN},
85 {"KUNFILT", KEY_UNFILT},
86 // val properties
87 {"VAL", VAL},
88 {"VNIL", VALNIL},
89 {"VTAG", VALTAG},
90 {"VANCH", VALANCH},
91 {"VREF", VALREF},
92 {"VLITERAL", VAL_LITERAL},
93 {"VFOLDED", VAL_FOLDED},
94 {"VSQUO", VAL_SQUO},
95 {"VDQUO", VAL_DQUO},
96 {"VPLAIN", VAL_PLAIN},
97 {"VUNFILT", VAL_UNFILT},
98 // container properties
99 {"MAP", MAP},
100 {"SEQ", SEQ},
101 {"FLOWSL", FLOW_SL},
102 {"FLOWML1", FLOW_ML1},
103 {"FLOWMLN", FLOW_MLN},
104 {"FLOWSPC", FLOW_SPC},
105 {"BLCK", BLOCK},
106};
107} // namespace
108size_t NodeType::type_str(substr buf, type_bits flags) noexcept
109{
110 detail::SubstrWriter_ writer(buf);
111 for(type_and_name const tn : type_names)
112 {
113 if((flags & tn.bits) == tn.bits)
114 {
115 if(writer.pos)
116 writer.append('|');
117 writer.append(tn.str);
118 flags = flags & ~tn.bits; // remove the flag
119 }
120 }
121 if(!writer.pos)
122 writer.append("NOTYPE");
123 if(writer.pos < buf.len)
124 buf[writer.pos] = '\0';
125 return writer.pos;
126}
127
128} // namespace yml
129} // namespace c4
Error utilities used by ryml.
uint32_t type_bits
the integral type necessary to cover all the bits for NodeType_e
Definition node_type.hpp:26
@ VALANCH
the val has an &anchor
Definition node_type.hpp:42
@ NOTYPE
no node type or style is set
Definition node_type.hpp:32
@ TYMASK_
all the bits up to here
Definition node_type.hpp:47
@ KEY_DQUO
mark key scalar as double quoted "
@ VALREF
a *reference: the val references an &anchor
Definition node_type.hpp:40
@ VALNIL
the val is null (eg {a : } results in a null val)
Definition node_type.hpp:46
@ MAP
a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
Definition node_type.hpp:35
@ STREAM
a stream: a seq of docs
Definition node_type.hpp:38
@ KEY
the scalar to the left of : in a map's member
Definition node_type.hpp:33
@ FLOW_ML1
mark container with multi-line flow style, 1 element per line
Definition node_type.hpp:75
@ VAL_FOLDED
mark val scalar as multiline, block folded >
@ KEYTAG
the key has a tag
Definition node_type.hpp:43
@ FLOW_SL
mark container with single-line flow style
Definition node_type.hpp:56
@ VAL_UNFILT
the val scalar was left unfiltered; the parser was set not to filter.
Definition node_type.hpp:52
@ 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:34
@ KEYMAP
mask of KEY|MAP
@ VALTAG
the val has a tag
Definition node_type.hpp:44
@ KEYSEQ
mask of KEY|SEQ
@ FLOW_MLN
mark container with multi-line flow style, n elements per line, wrapped (as set by EmitOptions::max_c...
Definition node_type.hpp:90
@ SEQ
a seq: a parent of VAL/SEQ/MAP nodes
Definition node_type.hpp:36
@ VAL_SQUO
mark val scalar as single quoted '
@ DOCSEQ
mask of DOC|SEQ
@ VAL_PLAIN
mark val scalar as plain scalar (unquoted, even when multiline)
@ KEYREF
a *reference: the key references an &anchor
Definition node_type.hpp:39
@ 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
@ KEYVAL
mask of KEY|VAL
@ KEYANCH
the key has an &anchor
Definition node_type.hpp:41
@ VAL_DQUO
mark val scalar as double quoted "
@ KEY_UNFILT
the key scalar was left unfiltered; the parser was set not to filter.
Definition node_type.hpp:51
@ 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)
@ 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:45
@ DOC
a document
Definition node_type.hpp:37
basic_substring< char > substr
a mutable string view
Definition substr.hpp:2355
const char * type_str() const noexcept
return a preset string based on the node type