Read MXL flow labels from top-level metadata

This commit is contained in:
Johanness
2026-05-19 02:23:13 +03:00
parent 32f5b70f59
commit ba9bf1894e
+73 -19
View File
@@ -59,44 +59,98 @@ namespace
const char* json, const char* json,
const char* key) const char* key)
{ {
std::string searchKey = std::string("\"") + key + "\""; int depth = 0;
const char* pos = std::strstr(json, searchKey.c_str());
if (!pos) for (const char* p = json; *p != '\0'; ++p)
{
if (*p == '"')
{
const char* keyBegin = p + 1;
const char* keyEnd = keyBegin;
bool keyEscaped = false;
while (*keyEnd != '\0')
{
if (!keyEscaped && *keyEnd == '"')
{
break;
}
keyEscaped = !keyEscaped && *keyEnd == '\\';
if (*keyEnd != '\\')
{
keyEscaped = false;
}
++keyEnd;
}
if (*keyEnd == '\0')
{ {
return ""; return "";
} }
pos += searchKey.size(); const char* value = keyEnd + 1;
while (*value == ' ' || *value == '\t' ||
while (*pos == ' ' || *pos == '\t' || *pos == '\n' || *value == '\n' || *value == '\r')
*pos == '\r' || *pos == ':')
{ {
pos++; ++value;
} }
if (*pos != '"') if (depth == 1 &&
*value == ':' &&
unescapeJsonString(keyBegin, keyEnd) == key)
{
++value;
while (*value == ' ' || *value == '\t' ||
*value == '\n' || *value == '\r')
{
++value;
}
if (*value != '"')
{ {
return ""; return "";
} }
++pos; ++value;
const char* valueBegin = pos; const char* valueBegin = value;
bool escaped = false; bool valueEscaped = false;
while (*pos != '\0') while (*value != '\0')
{ {
if (!escaped && *pos == '"') if (!valueEscaped && *value == '"')
{ {
return unescapeJsonString(valueBegin, pos); return unescapeJsonString(
valueBegin,
value);
} }
escaped = !escaped && *pos == '\\'; valueEscaped =
if (*pos != '\\') !valueEscaped && *value == '\\';
if (*value != '\\')
{ {
escaped = false; valueEscaped = false;
} }
++pos; ++value;
}
return "";
}
p = keyEnd;
continue;
}
if (*p == '{' || *p == '[')
{
++depth;
}
else if ((*p == '}' || *p == ']') && depth > 0)
{
--depth;
}
} }
return ""; return "";