Skip to content

Commit 9bb6d0f

Browse files
committed
Fix parsing skipped elements
1 parent 1fd40af commit 9bb6d0f

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

extras/analyze/src/parse.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ static EventSchema parseEventSchema(
6060
return Result;
6161
}
6262

63+
#include <iostream>
64+
6365
// Schemas are globally loaded.
6466
// This static/thread_local dance is to make it appropriately thread safe but
6567
// still fast.
@@ -92,22 +94,34 @@ static Event parseEvent(const std::string_view Event) {
9294
Event.find_first_not_of(" \t\n", Event.find(':', KeyE + 1) + 1);
9395
if (ValF == std::string_view::npos)
9496
break;
95-
const auto ValE = Event[ValF] == '"'
96-
? Event.find('"', ValF + 1) + 1
97-
: Event.find_first_of(",} \t\n", ValF + 1);
97+
const auto ValE = [&] {
98+
if (Event[ValF] == '"') {
99+
// Find the end of the string
100+
return Event.find('"', ValF
101+
// start after the open quote
102+
+ 1)
103+
// include the end quote
104+
+ 1;
105+
} else {
106+
// Find the end of the number/bool/etc; either the next whitespace, the
107+
// separating comma, or the end of the JSON object:
108+
return Event.find_first_of(",} \t\n", ValF + 1);
109+
}
110+
}();
98111
if (ValE == std::string_view::npos)
99112
break;
100113
std::string_view Val = Event.substr(ValF, ValE - ValF);
101114

102115
Result.emplace_back(Key, Val);
103-
Begin = Event.find_first_of(",}", ValE + 1);
116+
// Find the start of the next element (if there is a next)
117+
Begin = Event.find_first_of(",}", ValE);
104118
if (Begin == std::string_view::npos)
105119
break;
106120
Begin += 1;
107121
}
108122

109123
assert(Result[0].first == "event_id"sv);
110-
EventId Id(Result[0].second);
124+
EventId Id(Result[0].second.substr(1, Result[0].second.size() - 2));
111125

112126
auto It = Schemas.find(Id);
113127
if (It == Schemas.end()) {

0 commit comments

Comments
 (0)