rapidyaml 0.14.0
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
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
17namespace c4 {
18namespace yml {
19
20// instantiate the template
22
23namespace extra {
24
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 '\n':
48 count += 3;
49 break;
50 case '[':
51 case ']':
52 count += 4;
53 break;
54 case '{':
55 case '}':
56 count += 7;
57 break;
58 case '?':
59 count += 5;
60 break;
61 }
62 }
63 return count;
64}
65
66// ensure the ievt flags work despite being signed
67namespace ievt {
68static_assert((MASK & BSTR) == BSTR, "overflow?");
69static_assert((MASK & ESTR) == ESTR, "overflow?");
70static_assert((MASK & BDOC) == BDOC, "overflow?");
71static_assert((MASK & EDOC) == EDOC, "overflow?");
72static_assert((MASK & BMAP) == BMAP, "overflow?");
73static_assert((MASK & EMAP) == EMAP, "overflow?");
74static_assert((MASK & BSEQ) == BSEQ, "overflow?");
75static_assert((MASK & ESEQ) == ESEQ, "overflow?");
76static_assert((MASK & ANCH) == ANCH, "overflow?");
77static_assert((MASK & ALIA) == ALIA, "overflow?");
78static_assert((MASK & TAG_) == TAG_, "overflow?");
79static_assert((MASK & PLAI) == PLAI, "overflow?");
80static_assert((MASK & SQUO) == SQUO, "overflow?");
81static_assert((MASK & DQUO) == DQUO, "overflow?");
82static_assert((MASK & LITL) == LITL, "overflow?");
83static_assert((MASK & FOLD) == FOLD, "overflow?");
84static_assert((MASK & FLOW) == FLOW, "overflow?");
85static_assert((MASK & BLCK) == BLCK, "overflow?");
86static_assert((MASK & KEY_) == KEY_, "overflow?");
87static_assert((MASK & VAL_) == VAL_, "overflow?");
88static_assert((MASK & EXPL) == EXPL, "overflow?");
89static_assert((MASK & YAML) == YAML, "overflow?");
90static_assert((MASK & TAGH) == TAGH, "overflow?");
91static_assert((MASK & TAGP) == TAGP, "overflow?");
92static_assert((MASK & AREN) == AREN, "overflow?");
93static_assert((MASK & PSTR) == PSTR, "overflow?");
94static_assert((MASK & UNFILT) == UNFILT, "overflow?");
95static_assert((MASK & LAST) == LAST, "overflow?");
96static_assert((MASK & MASK) == MASK, "overflow?");
97static_assert((MASK & WSTR) == WSTR, "overflow?");
98} // namespace ievt
99
100} // namespace extra
101} // namespace yml
102} // namespace c4
This is the main driver of parsing logic: it scans the YAML or JSON source for tokens,...
An event handler that creates an integer buffer with a very compact representation of the YAML tree i...
#define RYML_EXPORT
Definition export.hpp:18
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...
basic_substring< const char > csubstr
an immutable string view
Definition substr.hpp:2357
@ 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)
@ TAGH
tag directive, handle: \TAG <handle> ........
@ 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
@ TAGP
tag directive, prefix: \TAG ........ <prefix>
@ 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)
@ AREN
IMPORTANT. Marks events whose string was placed in the arena. This happens when the filtered string i...
@ YAML
yaml directive: \YAML <version>
@ 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
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