rapidyaml  0.16.0
parseandemitYAML,anddoitfast
node_type.cpp
Go to the documentation of this file.
1 #ifndef C4_YML_NODE_TYPE_HPP_
2 #include "c4/yml/node_type.hpp"
3 #endif
4 #ifndef C4_YML_ERROR_HPP_
5 #include "c4/yml/error.hpp"
6 #endif
7 
8 
9 namespace c4 {
10 namespace yml {
11 
12 const 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 
69 namespace {
70 struct type_and_name { const char* str; type_bits bits; };
71 constexpr 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
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
const char * type_str() const noexcept
return a preset string based on the node type
Definition: node_type.hpp:263
mark val scalar as plain scalar (unquoted, even when multiline)
Definition: node_type.hpp:156
the val has an &anchor
Definition: node_type.hpp:42
the key has a tag
Definition: node_type.hpp:43
the val scalar was left unfiltered; the parser was set not to filter.
Definition: node_type.hpp:52
mark key scalar as double quoted "
Definition: node_type.hpp:153
mark key scalar as multiline, block literal |
Definition: node_type.hpp:147
mark val scalar as single quoted '
Definition: node_type.hpp:152
the key scalar was left unfiltered; the parser was set not to filter.
Definition: node_type.hpp:51
type_bits bits
Definition: node_type.cpp:70
the val has a tag
Definition: node_type.hpp:44
EventBits flags
Definition: ints_utils.cpp:27
const char * str
Definition: node_type.cpp:70
mark val scalar as double quoted "
Definition: node_type.hpp:154
a document
Definition: node_type.hpp:37
mask of DOC|VAL
Definition: node_type.hpp:165
mark container with multi-line flow style, n elements per line, < wrapped (as set by EmitOptions::max...
Definition: node_type.hpp:90
the key is null (eg { : b} results in a null key)
Definition: node_type.hpp:45
mask of KEY|VAL
Definition: node_type.hpp:160
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
the key has an &anchor
Definition: node_type.hpp:41
mask of KEY|SEQ
Definition: node_type.hpp:161
mark val scalar as multiline, block folded >
Definition: node_type.hpp:150
mark key scalar as multiline, block folded >
Definition: node_type.hpp:149
all the bits up to here
Definition: node_type.hpp:47
mask of DOC|MAP
Definition: node_type.hpp:163
the val is null (eg {a : } results in a null val)
Definition: node_type.hpp:46
a *reference: the val references an &anchor
Definition: node_type.hpp:40
mark container with block style < - seqs as <
Definition: node_type.hpp:136
mask of DOC|SEQ
Definition: node_type.hpp:164
the scalar to the left of : in a map's member
Definition: node_type.hpp:33
a *reference: the key references an &anchor
Definition: node_type.hpp:39
no node type or style is set
Definition: node_type.hpp:32
a stream: a seq of docs
Definition: node_type.hpp:38
mark container with spaces after comma when in flow mode. < Applies to both FLOW_SL and FLOW_MLN (but...
Definition: node_type.hpp:132
mark key scalar as plain scalar (unquoted, even when multiline)
Definition: node_type.hpp:155
Error utilities used by ryml.
mark val scalar as multiline, block literal |
Definition: node_type.hpp:148
uint32_t type_bits
the integral type necessary to cover all the bits for NodeType_e
Definition: node_type.hpp:26
a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
Definition: node_type.hpp:35
mark key scalar as single quoted '
Definition: node_type.hpp:151
mark container with multi-line flow style, 1 element per line < - seqs as <
Definition: node_type.hpp:75
mask of KEY|MAP
Definition: node_type.hpp:162
a seq: a parent of VAL/SEQ/MAP nodes
Definition: node_type.hpp:36
mark container with single-line flow style < - seqs as <
Definition: node_type.hpp:56