MCPcopy Create free account
hub / github.com/cactus-compute/cactus / json_array

Function json_array

tests/test_utils.cpp:293–308  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

291}
292
293std::string json_array(const std::string& json, const std::string& key) {
294 std::string pattern = "\"" + key + "\":";
295 size_t pos = json.find(pattern);
296 if (pos == std::string::npos) return "[]";
297 size_t start = pos + pattern.size();
298 while (start < json.size() && (json[start] == ' ' || json[start] == '\t')) ++start;
299 if (start >= json.size() || json[start] != '[') return "[]";
300 int depth = 1;
301 size_t end = start + 1;
302 while (end < json.size() && depth > 0) {
303 if (json[end] == '[') depth++;
304 else if (json[end] == ']') depth--;
305 end++;
306 }
307 return json.substr(start, end - start);
308}
309
310void Metrics::parse(const std::string& json) {
311 success = json_bool(json, "success", false);

Callers 1

parseMethod · 0.70

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected