rapidyaml  0.11.0
parse and emit YAML, and do it fast
event_handler_ints.cpp
Go to the documentation of this file.
1 #ifdef RYML_SINGLE_HEADER_INTS
2  #ifndef _RYML_SINGLE_HEADER_AMALGAMATED_HPP_
3  #include <ryml_ints.hpp>
4  #endif
5 #elif defined(RYML_SINGLE_HEADER)
6  #ifndef _RYML_SINGLE_HEADER_AMALGAMATED_HPP_
7  #include <ryml_all.hpp>
8  #endif
9 #else
11 #endif
12 
13 #ifndef _C4_YML_EXTRA_EVENT_HANDLER_INTS_HPP_
15 #endif
16 
17 namespace c4 {
18 namespace yml {
19 
20 // instantiate the template
21 template class ParseEngine<extra::EventHandlerInts>;
22 
23 namespace extra {
24 
25 int32_t estimate_events_ints_size(csubstr src)
26 {
27  int32_t count = 7; // BSTR + BDOC + =VAL + EDOC + ESTR
28  for(size_t i = 0; i < src.len; ++i)
29  {
30  switch(src.str[i])
31  {
32  case ':': // this has strings preceding/following it
33  case ',': // overestimate, assume map
34  case '%': // assume TAGD->string + TAGV->string
35  count += 6;
36  break;
37  // these have (or are likely to have) a string following it
38  case '-':
39  case '&':
40  case '*':
41  case '<':
42  case '!':
43  case '\'':
44  case '"':
45  case '|':
46  case '>':
47  case '?':
48  case '\n':
49  count += 3;
50  break;
51  case '[':
52  case ']':
53  count += 4;
54  break;
55  case '{':
56  case '}':
57  count += 7;
58  break;
59  }
60  }
61  return count;
62 }
63 
64 // ensure the ievt flags work despite being signed
65 namespace ievt {
66 static_assert((MASK & BSTR) == BSTR, "overflow?");
67 static_assert((MASK & ESTR) == ESTR, "overflow?");
68 static_assert((MASK & BDOC) == BDOC, "overflow?");
69 static_assert((MASK & EDOC) == EDOC, "overflow?");
70 static_assert((MASK & BMAP) == BMAP, "overflow?");
71 static_assert((MASK & EMAP) == EMAP, "overflow?");
72 static_assert((MASK & BSEQ) == BSEQ, "overflow?");
73 static_assert((MASK & ESEQ) == ESEQ, "overflow?");
74 static_assert((MASK & ANCH) == ANCH, "overflow?");
75 static_assert((MASK & ALIA) == ALIA, "overflow?");
76 static_assert((MASK & TAG_) == TAG_, "overflow?");
77 static_assert((MASK & PLAI) == PLAI, "overflow?");
78 static_assert((MASK & SQUO) == SQUO, "overflow?");
79 static_assert((MASK & DQUO) == DQUO, "overflow?");
80 static_assert((MASK & LITL) == LITL, "overflow?");
81 static_assert((MASK & FOLD) == FOLD, "overflow?");
82 static_assert((MASK & FLOW) == FLOW, "overflow?");
83 static_assert((MASK & BLCK) == BLCK, "overflow?");
84 static_assert((MASK & KEY_) == KEY_, "overflow?");
85 static_assert((MASK & VAL_) == VAL_, "overflow?");
86 static_assert((MASK & EXPL) == EXPL, "overflow?");
87 static_assert((MASK & YAML) == YAML, "overflow?");
88 static_assert((MASK & TAGD) == TAGD, "overflow?");
89 static_assert((MASK & TAGV) == TAGV, "overflow?");
90 static_assert((MASK & AREN) == AREN, "overflow?");
91 static_assert((MASK & PSTR) == PSTR, "overflow?");
92 static_assert((MASK & UNFILT) == UNFILT, "overflow?");
93 static_assert((MASK & LAST) == LAST, "overflow?");
94 static_assert((MASK & MASK) == MASK, "overflow?");
95 static_assert((MASK & WSTR) == WSTR, "overflow?");
96 } // namespace ievt
97 
98 } // namespace extra
99 } // namespace yml
100 } // namespace c4
An event handler that creates an integer buffer with a very compact representation of the YAML tree i...
int32_t estimate_events_ints_size(csubstr src)
Read YAML source and, without undergoing a full parse, estimate the size of the integer buffer requir...
@ TAGD
tag directive, name : \TAG <name> .......
@ LITL
scalar: block literal (|)
@ UNFILT
special flag to mark a scalar as unfiltered (when the parser is set not to filter).
@ EMAP
end map (-MAP in test suite events)
@ DQUO
scalar: double-quoted ("")
@ FOLD
scalar: block folded (>)
@ BMAP
begin map (+MAP in test suite events)
@ MASK
a mask of all bits in this enumeration
@ ESTR
end stream (-STR in test suite events)
@ BSTR
begin stream (+STR in test suite events)
@ BSEQ
begin seq (+SEQ in test suite events)
@ ESEQ
end seq (-SEQ in test suite events)
@ WSTR
WithSTRing: mask of all the events that encode a string following the event. For such events,...
@ FLOW
container: flow: [] for seqs or {} for maps
@ VAL_
as value special flag to enable look-back in the event array. it signifies that the previous event ha...
@ BDOC
begin doc (+DOC in test suite events)
@ BLCK
container: block
@ AREN
IMPORTANT. Marks events whose string was placed in the arena. This happens when the filtered string i...
@ TAGV
tag directive, value: \TAG ...... <value>
@ YAML
yaml directive: \YAML <version>
@ ALIA
*ref (reference)
@ EDOC
end doc (-DOC in test suite events)
@ LAST
the last flag defined above
@ EXPL
--- (with BDOC) or ... (with EDOC)
@ SQUO
scalar: single-quoted (')
(Undefined by default) Use shorter error message from checks/asserts: do not show the check condition...
Definition: common.cpp:14