• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

biojppm / rapidyaml / 18077090334

28 Sep 2025 04:45PM UTC coverage: 97.625% (+0.3%) from 97.312%
18077090334

Pull #536

github

web-flow
Merge c8e2917d6 into 9a044c88b
Pull Request #536: Int handler

982 of 991 new or added lines in 16 files covered. (99.09%)

1 existing line in 1 file now uncovered.

13031 of 13348 relevant lines covered (97.63%)

766298.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.54
/src_extra/c4/yml/extra/event_handler_ints_utils.cpp
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
#endif
10

11
#ifndef _C4_YML_EXTRA_SCALAR_HPP_
12
#include "c4/yml/extra/scalar.hpp"
13
#endif
14

15
#ifndef _C4_YML_EXTRA_EVENT_HANDLER_INTS_UTILS_HPP_
16
#include "c4/yml/extra/event_handler_ints_utils.hpp"
17
#endif
18

19
#ifndef _C4_BITMASK_HPP_
20
#include "c4/bitmask.hpp"
21
#endif
22

23

24
C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wold-style-cast")
25
C4_SUPPRESS_WARNING_CLANG_WITH_PUSH("-Wold-style-cast")
26
// NOLINTBEGIN(hicpp-signed-bitwise)
27

28
namespace c4 {
29
template<>
30
c4::EnumSymbols<yml::extra::ievt::EventFlags> const esyms<yml::extra::ievt::EventFlags>()
1,018,492✔
31
{
32
    static constexpr const EnumSymbols<yml::extra::ievt::EventFlags>::Sym syms[] = {
33
        {yml::extra::ievt::KEY_, "KEY_"},
34
        {yml::extra::ievt::VAL_, "VAL_"},
35
        {yml::extra::ievt::SCLR, "SCLR"},
36
        {yml::extra::ievt::BSEQ, "BSEQ"},
37
        {yml::extra::ievt::ESEQ, "ESEQ"},
38
        {yml::extra::ievt::BMAP, "BMAP"},
39
        {yml::extra::ievt::EMAP, "EMAP"},
40
        {yml::extra::ievt::ALIA, "ALIA"},
41
        {yml::extra::ievt::ANCH, "ANCH"},
42
        {yml::extra::ievt::TAG_, "TAG_"},
43
        {yml::extra::ievt::PLAI, "PLAI"},
44
        {yml::extra::ievt::SQUO, "SQUO"},
45
        {yml::extra::ievt::DQUO, "DQUO"},
46
        {yml::extra::ievt::LITL, "LITL"},
47
        {yml::extra::ievt::FOLD, "FOLD"},
48
        {yml::extra::ievt::FLOW, "FLOW"},
49
        {yml::extra::ievt::BLCK, "BLCK"},
50
        {yml::extra::ievt::BDOC, "BDOC"},
51
        {yml::extra::ievt::EDOC, "EDOC"},
52
        {yml::extra::ievt::BSTR, "BSTR"},
53
        {yml::extra::ievt::ESTR, "ESTR"},
54
        {yml::extra::ievt::EXPL, "EXPL"},
55
        {yml::extra::ievt::AREN, "AREN"},
56
        {yml::extra::ievt::PSTR, "PSTR"},
57
        {yml::extra::ievt::UNFILT, "UNFILT"},
58
        {yml::extra::ievt::YAML, "YAML"},
59
        {yml::extra::ievt::TAGD, "TAGD"},
60
        {yml::extra::ievt::TAGV, "TAGV"},
61
    };
62
    return EnumSymbols<yml::extra::ievt::EventFlags>(syms);
1,018,492✔
63
}
64
namespace yml {
65
namespace extra {
66
namespace ievt {
NEW
67
size_t to_chars(substr buf, ievt::DataType flags)
×
68
{
NEW
69
    return c4::bm2str<ievt::EventFlags>((flags & ievt::MASK), buf.str, buf.len);
×
70
}
71
csubstr to_chars_sub(substr buf, ievt::DataType flags)
1,018,492✔
72
{
73
    size_t reqsize = c4::bm2str<ievt::EventFlags>((flags & ievt::MASK), buf.str, buf.len);
1,018,492✔
74
    RYML_CHECK(reqsize > 0u);
1,018,492✔
75
    RYML_CHECK(reqsize < buf.len);
1,018,492✔
76
    return buf.first(reqsize - 1u);
3,055,476✔
77
}
78
} // namespace ievt
79
} // namespace extra
80
} // namespace yml
81
} // namespace c4
82

83

84
//-----------------------------------------------------------------------------
85
//-----------------------------------------------------------------------------
86
//-----------------------------------------------------------------------------
87

88
namespace c4 {
89
namespace yml {
90
namespace extra {
91

92
void print_events_ints(csubstr parsed_yaml, csubstr arena, ievt::DataType const* evts, ievt::DataType evts_sz)
13,916✔
93
{
94
    char buf[200];
95
    for(ievt::DataType evtpos = 0, evtnumber = 0;
13,916✔
96
        evtpos < evts_sz;
216,008✔
97
        ++evtnumber,
202,092✔
98
            evtpos += ((evts[evtpos] & ievt::WSTR) ? 3 : 1))
202,092✔
99
    {
100
        ievt::DataType evt = evts[evtpos];
202,092✔
101
        {
102
            csubstr str = ievt::to_chars_sub(buf, evt);
202,092✔
103
            printf("[%d][%d] %.*s(0x%x)", evtnumber, evtpos, (int)str.len, str.str, evt);
202,092✔
104
        }
105
        if (evt & ievt::WSTR)
202,092✔
106
        {
107
            bool in_arena = evt & ievt::AREN;
86,348✔
108
            csubstr region = !in_arena ? parsed_yaml : arena;
86,348✔
109
            bool safe = (evts[evtpos + 1] >= 0)
172,696✔
110
                && (evts[evtpos + 2] >= 0)
86,348✔
111
                && (evts[evtpos + 1] <= (int)region.len)
86,348✔
112
                && ((evts[evtpos + 1] + evts[evtpos + 2]) <= (int)region.len);
172,696✔
113
            const char *str = safe ? (region.str + evts[evtpos + 1]) : "ERR!!!";
86,348✔
114
            int len = safe ? evts[evtpos + 2] : 6;
86,348✔
115
            printf(": %d [%d]~~~%.*s~~~", evts[evtpos+1], evts[evtpos+2], len, str);
86,348✔
116
            if(in_arena)
86,348✔
117
                printf(" (arenasz=%zu)", arena.len);
512✔
118
            else
119
                printf(" (srcsz=%zu)", parsed_yaml.len);
85,836✔
120
        }
121
        printf("\n");
202,092✔
122
    }
123
}
13,916✔
124

125
size_t emit_events_testsuite_from_ints(csubstr parsed_yaml,
63,712✔
126
                                        csubstr arena,
127
                                        ievt::DataType const* evts_ints,
128
                                        ievt::DataType evts_ints_sz,
129
                                        substr evts_test_suite)
130
{
131
    auto getstr = [&](ievt::DataType i){
411,296✔
132
        bool in_arena = evts_ints[i] & ievt::AREN;
411,296✔
133
        csubstr region = !in_arena ? parsed_yaml : arena;
411,296✔
134
        return region.sub((size_t)evts_ints[i+1], (size_t)evts_ints[i+2]);
822,592✔
135
    };
63,712✔
136
    size_t sz = 0;
63,712✔
137
    auto append = [&](csubstr s){
2,244,720✔
138
        size_t next = sz + s.len;
2,244,720✔
139
        if (s.len && (next <= evts_test_suite.len && evts_test_suite.len))
2,244,720✔
140
            memcpy(evts_test_suite.str + sz, s.str, s.len);
1,122,352✔
141
        sz = next;
2,244,720✔
142
    };
2,308,432✔
143
    bool has_tag = false;
63,712✔
144
    csubstr tag;
63,712✔
145
    auto maybe_append_tag = [&]{
454,256✔
146
        if(has_tag)
454,256✔
147
        {
148
            #ifdef RYML_NO_COVERAGE__TO_BE_DELETED
149
            if(tag.begins_with('<'))
150
            {
151
                append(" ");
152
                append(tag);
153
            }
154
            else
155
            #endif
156
            if(tag.begins_with("!<"))
39,632✔
157
            {
158
                append(" ");
560✔
159
                append(tag.sub(1));
1,120✔
160
            }
161
            else if(tag.begins_with('!'))
39,072✔
162
            {
163
                append(" <");
37,552✔
164
                append(tag);
37,552✔
165
                append(">");
37,552✔
166
            }
167
            else
168
            {
169
                append(" <!");
1,520✔
170
                append(tag);
1,520✔
171
                append(">");
1,520✔
172
            }
173
        }
174
        has_tag = false;
454,256✔
175
    };
517,968✔
176
    bool has_anchor = false;
63,712✔
177
    csubstr anchor;
63,712✔
178
    auto maybe_append_anchor = [&]{
454,256✔
179
        if(has_anchor)
454,256✔
180
        {
181
            append(" &");
39,408✔
182
            append(anchor);
39,408✔
183
        }
184
        has_anchor = false;
454,256✔
185
    };
517,968✔
186
    auto append_cont = [&](csubstr evt, csubstr style){
128,080✔
187
        append(evt);
128,080✔
188
        if(style.len)
128,080✔
189
        {
190
            append(" ");
34,912✔
191
            append(style);
34,912✔
192
        }
193
        maybe_append_anchor();
128,080✔
194
        maybe_append_tag();
128,080✔
195
        append("\n");
128,080✔
196
    };
191,792✔
197
    auto append_val = [&](csubstr evt, csubstr val){
326,176✔
198
        append("=VAL");
326,176✔
199
        maybe_append_anchor();
326,176✔
200
        maybe_append_tag();
326,176✔
201
        append(" ");
326,176✔
202
        append(evt);
326,176✔
203
        substr buf = sz <= evts_test_suite.len ? evts_test_suite.sub(sz) : evts_test_suite.last(0);
489,264✔
204
        sz += escape_scalar(buf, val);
326,176✔
205
        append("\n");
326,176✔
206
    };
326,176✔
207
    for(ievt::DataType i = 0; i < evts_ints_sz; )
1,006,992✔
208
    {
209
        ievt::DataType evt = evts_ints[i];
943,280✔
210
        if(evt & ievt::SCLR)
943,280✔
211
        {
212
            csubstr s = getstr(i);
326,176✔
213
            if(evt & ievt::SQUO)
326,176✔
214
                append_val("'", s);
6,256✔
215
            else if(evt & ievt::DQUO)
319,920✔
216
                append_val("\"", s);
15,344✔
217
            else if(evt & ievt::LITL)
304,576✔
218
                append_val("|", s);
9,456✔
219
            else if(evt & ievt::FOLD)
295,120✔
220
                append_val(">", s);
5,648✔
221
            else //if(evt & ievt::PLAI)
222
                append_val(":", s);
289,472✔
223
        }
224
        else if(evt & ievt::BSEQ)
617,104✔
225
        {
226
            if(evt & ievt::FLOW)
42,016✔
227
                append_cont("+SEQ", "[]");
15,584✔
228
            else
229
                append_cont("+SEQ", "");
26,432✔
230
        }
231
        else if(evt & ievt::ESEQ)
575,088✔
232
        {
233
            append("-SEQ\n");
42,016✔
234
        }
235
        else if(evt & ievt::BMAP)
533,072✔
236
        {
237
            if(evt & ievt::FLOW)
86,064✔
238
                append_cont("+MAP", "{}");
19,328✔
239
            else
240
                append_cont("+MAP", "");
66,736✔
241
        }
242
        else if(evt & ievt::EMAP)
447,008✔
243
        {
244
            append("-MAP\n");
86,064✔
245
        }
246
        else if(evt & ievt::ALIA)
360,944✔
247
        {
248
            append("=ALI *");
6,080✔
249
            append(getstr(i));
6,080✔
250
            append("\n");
6,080✔
251
        }
252
        else if(evt & ievt::TAG_)
354,864✔
253
        {
254
            has_tag = true;
39,632✔
255
            tag = getstr(i);
39,632✔
256
        }
257
        else if(evt & ievt::ANCH)
315,232✔
258
        {
259
            has_anchor = true;
39,408✔
260
            anchor = getstr(i);
39,408✔
261
        }
262
        else if(evt & ievt::BDOC)
275,824✔
263
        {
264
            if(evt & ievt::EXPL)
71,568✔
265
                append("+DOC ---\n");
22,144✔
266
            else
267
                append("+DOC\n");
49,424✔
268
        }
269
        else if(evt & ievt::EDOC)
204,256✔
270
        {
271
            if(evt & ievt::EXPL)
71,568✔
272
                append("-DOC ...\n");
5,264✔
273
            else
274
                append("-DOC\n");
66,304✔
275
        }
276
        else if(evt & ievt::BSTR)
132,688✔
277
        {
278
             append("+STR\n");
63,712✔
279
        }
280
        else if(evt & ievt::ESTR)
68,976✔
281
        {
282
            append("-STR\n");
63,712✔
283
        }
284

285
        i += (evt & ievt::WSTR) ? 3 : 1;
943,280✔
286
    }
287
    return sz;
63,712✔
288
}
289

290
} // namespace extra
291
} // namespace yml
292
} // namespace c4
293

294
// NOLINTEND(hicpp-signed-bitwise)
295
C4_SUPPRESS_WARNING_CLANG_POP
296
C4_SUPPRESS_WARNING_GCC_POP
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc