Debian Codegraph @

3rdparty/catch2/fuzzing/fuzz_textflow.cpp

raw symbols SCIP
1 //License: Boost 1.0
2 //By Paul Dreik 2020
3
4 #include <catch2/internal/catch_textflow.hpp>
5
6 #include "NullOStream.h"
7
8 #include <string>
9 #include <string_view>
10
11
12 template<class Callback>
13 void split(const char *Data, size_t Size, Callback callback) {
14
15 using namespace std::literals;
16 constexpr auto sep="\n~~~\n"sv;
17
18 std::string_view remainder(Data,Size);
19 for (;;) {
20 auto pos=remainder.find(sep);
21 if(pos==std::string_view::npos) {
22 //not found. use the remainder and exit
23 callback(remainder);
24 return;
25 } else {
26 //found. invoke callback on the first part, then proceed with the rest.
27 callback(remainder.substr(0,pos));
28 remainder=remainder.substr(pos+sep.size());
29 }
30 }
31 }
32
33 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
34
35 Catch::TextFlow::Columns columns;
36
37 // break the input on separator
38 split((const char*)Data,Size,[&](std::string_view word) {
39 columns+=Catch::TextFlow::Column(std::string(word));
40 });
41
42 NullOStream nul;
43 nul << columns;
44
45 return 0;
46 }
47