MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / parse_flat_json_object

Function parse_flat_json_object

src/framework/io/config.cpp:48–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46} // namespace
47
48ConfigMap parse_flat_json_object(const std::string & text) {
49 const auto root = json::parse(text);
50 const auto & object = root.as_object();
51 ConfigMap config;
52 config.reserve(object.size());
53 for (const auto & [key, value] : object) {
54 if (value.is_string()) {
55 config[key] = value.as_string();
56 continue;
57 }
58 if (value.is_bool()) {
59 config[key] = value.as_bool() ? "true" : "false";
60 continue;
61 }
62 if (value.is_null()) {
63 config[key] = "null";
64 continue;
65 }
66 if (value.is_number()) {
67 const double number = value.as_number();
68 if (std::isfinite(number) && std::floor(number) == number) {
69 config[key] = std::to_string(static_cast<long long>(number));
70 } else {
71 std::ostringstream stream;
72 stream << number;
73 config[key] = stream.str();
74 }
75 continue;
76 }
77 throw std::runtime_error("flat json config values must be scalar");
78 }
79 return config;
80}
81
82ConfigMap parse_key_value_text(const std::string & text, char separator) {
83 return parse_lines(text, separator);

Callers 1

load_config_mapFunction · 0.85

Calls 10

parseFunction · 0.85
is_stringMethod · 0.80
is_boolMethod · 0.80
as_boolMethod · 0.80
is_nullMethod · 0.80
is_numberMethod · 0.80
as_numberMethod · 0.80
strMethod · 0.80
to_stringFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected