MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / json_tokenize

Function json_tokenize

src/convert_to_json.cpp:36–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34inline namespace MIGRAPHX_INLINE_NS {
35
36static std::vector<std::string_view> json_tokenize(const std::string& s)
37{
38 std::vector<lexer> lexers;
39
40 // Quote
41 lexers.push_back([](const char* start, const char* end) {
42 if(*start != '\"')
43 return start;
44 ++start;
45 while((start != end) and (*start != '\"'))
46 {
47 if(*start == '\\')
48 start++;
49 start++;
50 }
51
52 return ++start;
53 });
54
55 // Line comments
56 lexers.push_back([](const char* start, const char* end) {
57 if(*start == '#')
58 start++;
59 else if((start + 1) < end and start[0] == '/' and start[1] == '/')
60 start += 2;
61 else
62 return start;
63 return std::find_if(start, end, [&](char c) { return c == '\n'; });
64 });
65
66 // Whitespace
67 lexers.push_back(lex_while(&isspace));
68
69 // Punctation
70 lexers.push_back(lex_if(&ispunct));
71
72 // Identifier/number
73 lexers.push_back(lex_while([](char c) {
74 return (isalnum(c) != 0 or contains({'_', '.', '+'}, c));
75 }));
76
77 return tokenize(s.data(), s.data() + s.length(), lexers);
78}
79
80std::string convert_to_json(const std::string& str)
81{

Callers 1

convert_to_jsonFunction · 0.85

Calls 7

lex_whileFunction · 0.85
lex_ifFunction · 0.85
containsFunction · 0.85
tokenizeFunction · 0.85
find_ifFunction · 0.50
push_backMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected