Simple JSON string value extractor (for config parsing)
| 159 | |
| 160 | // Simple JSON string value extractor (for config parsing) |
| 161 | static std::string config_get_string(const std::string& json, const std::string& key) { |
| 162 | auto pos = json.find("\"" + key + "\""); |
| 163 | if (pos == std::string::npos) return ""; |
| 164 | auto colon = json.find(':', pos); |
| 165 | if (colon == std::string::npos) return ""; |
| 166 | auto q1 = json.find('"', colon + 1); |
| 167 | if (q1 == std::string::npos) return ""; |
| 168 | auto q2 = json.find('"', q1 + 1); |
| 169 | if (q2 == std::string::npos) return ""; |
| 170 | return json.substr(q1 + 1, q2 - q1 - 1); |
| 171 | } |
| 172 | |
| 173 | static int config_get_int(const std::string& json, const std::string& key, int default_val) { |
| 174 | auto pos = json.find("\"" + key + "\""); |