1212#include " c4/yml/extra/ints_utils.hpp"
1313#endif
1414
15- #ifndef _C4_YML_ERROR_HPP_
16- #include " c4/yml/error.hpp"
17- #endif
18-
19- #ifndef _C4_BITMASK_HPP_
20- #include " c4/bitmask.hpp"
21- #endif
22-
2315
2416C4_SUPPRESS_WARNING_GCC_WITH_PUSH (" -Wold-style-cast" )
2517C4_SUPPRESS_WARNING_CLANG_WITH_PUSH (" -Wold-style-cast" )
2618// NOLINTBEGIN(hicpp-signed-bitwise,*avoid-c-style-cast)
2719
2820
2921namespace c4 {
30- template <>
31- c4::EnumSymbols<yml::extra::ievt::EventFlags> esyms<yml::extra::ievt::EventFlags>()
32- {
33- static constexpr const EnumSymbols<yml::extra::ievt::EventFlags>::Sym syms[] = {
34- {yml::extra::ievt::KEY_ , " KEY_" },
35- {yml::extra::ievt::VAL_ , " VAL_" },
36- {yml::extra::ievt::SCLR , " SCLR" },
37- {yml::extra::ievt::BSEQ , " BSEQ" },
38- {yml::extra::ievt::ESEQ , " ESEQ" },
39- {yml::extra::ievt::BMAP , " BMAP" },
40- {yml::extra::ievt::EMAP , " EMAP" },
41- {yml::extra::ievt::ALIA , " ALIA" },
42- {yml::extra::ievt::ANCH , " ANCH" },
43- {yml::extra::ievt::TAG_ , " TAG_" },
44- {yml::extra::ievt::PLAI , " PLAI" },
45- {yml::extra::ievt::SQUO , " SQUO" },
46- {yml::extra::ievt::DQUO , " DQUO" },
47- {yml::extra::ievt::LITL , " LITL" },
48- {yml::extra::ievt::FOLD , " FOLD" },
49- {yml::extra::ievt::FLOW , " FLOW" },
50- {yml::extra::ievt::BLCK , " BLCK" },
51- {yml::extra::ievt::BDOC , " BDOC" },
52- {yml::extra::ievt::EDOC , " EDOC" },
53- {yml::extra::ievt::BSTR , " BSTR" },
54- {yml::extra::ievt::ESTR , " ESTR" },
55- {yml::extra::ievt::EXPL , " EXPL" },
56- {yml::extra::ievt::AREN , " AREN" },
57- {yml::extra::ievt::PSTR , " PSTR" },
58- {yml::extra::ievt::UNFILT , " UNFILT" },
59- {yml::extra::ievt::YAML , " YAML" },
60- {yml::extra::ievt::TAGH , " TAGH" },
61- {yml::extra::ievt::TAGP , " TAGP" },
62- };
63- return EnumSymbols<yml::extra::ievt::EventFlags>(syms);
64- }
6522namespace yml {
6623namespace extra {
6724namespace ievt {
68- size_t to_chars (substr buf, ievt::DataType flags)
69- {
70- flags &= ievt::MASK ; // clear any other bits
71- return c4::bm2str<ievt::EventFlags>(flags, buf.str , buf.len );
72- }
73- csubstr to_chars_sub (substr buf, ievt::DataType flags)
25+
26+ namespace {
27+ struct FlagSym { const char *str; EventFlags flags; };
28+ const FlagSym flag_syms_[] = {
29+ {" KEY_" , KEY_ },
30+ {" VAL_" , VAL_ },
31+ {" SCLR" , SCLR },
32+ {" BSEQ" , BSEQ },
33+ {" ESEQ" , ESEQ },
34+ {" BMAP" , BMAP },
35+ {" EMAP" , EMAP },
36+ {" ALIA" , ALIA },
37+ {" ANCH" , ANCH },
38+ {" TAG_" , TAG_ },
39+ {" PLAI" , PLAI },
40+ {" SQUO" , SQUO },
41+ {" DQUO" , DQUO },
42+ {" LITL" , LITL },
43+ {" FOLD" , FOLD },
44+ {" FLOW" , FLOW },
45+ {" BLCK" , BLCK },
46+ {" BDOC" , BDOC },
47+ {" EDOC" , EDOC },
48+ {" BSTR" , BSTR },
49+ {" ESTR" , ESTR },
50+ {" EXPL" , EXPL },
51+ {" AREN" , AREN },
52+ {" PSTR" , PSTR },
53+ {" UNFILT" , UNFILT },
54+ {" YAML" , YAML },
55+ {" TAGH" , TAGH },
56+ {" TAGP" , TAGP },
57+ };
58+ } // namespace
59+
60+ size_t to_chars (substr buf, ievt::DataType flags) noexcept
7461{
75- size_t reqsize = ievt::to_chars (buf, flags);
76- _RYML_CHECK_BASIC (reqsize > 0u );
77- _RYML_CHECK_BASIC (reqsize < buf.len );
78- return buf.first (reqsize - 1u );
62+ detail::_SubstrWriter writer (buf);
63+ for (const FlagSym sym : flag_syms_)
64+ {
65+ if (flags & sym.flags )
66+ {
67+ if (writer.pos )
68+ writer.append (' |' );
69+ writer.append (sym.str );
70+ flags &= ~sym.flags ;
71+ }
72+ }
73+ if (!writer.pos )
74+ writer.append (" NONE" );
75+ return writer.pos ;
7976}
77+
8078} // namespace ievt
8179} // namespace extra
8280} // namespace yml
@@ -100,7 +98,7 @@ void events_ints_print(csubstr parsed_yaml, csubstr arena, ievt::DataType const*
10098 evtpos += ((evts[evtpos] & ievt::WSTR ) ? 3 : 1 ))
10199 {
102100 ievt::DataType evt = evts[evtpos];
103- csubstr flags = ievt:: to_chars_sub (buf, evt);
101+ csubstr flags = to_chars_sub (buf, evt);
104102 printf (" [%d][%d] %.*s(0x%x)" , evtnumber, evtpos, (int )flags.len , flags.str , evt);
105103 if (evt & ievt::WSTR )
106104 {
0 commit comments