| 315 | } |
| 316 | |
| 317 | bool parse_kv_map(const char *args, |
| 318 | /*out*/ std::map<std::string, std::string> &kv_map, |
| 319 | char item_splitter, |
| 320 | char kv_splitter, |
| 321 | bool allow_dup_key) |
| 322 | { |
| 323 | kv_map.clear(); |
| 324 | std::vector<std::string> splits; |
| 325 | split_args(args, splits, item_splitter); |
| 326 | for (std::string &i : splits) { |
| 327 | if (i.empty()) |
| 328 | continue; |
| 329 | size_t pos = i.find(kv_splitter); |
| 330 | if (pos == std::string::npos) { |
| 331 | return false; |
| 332 | } |
| 333 | std::string key = i.substr(0, pos); |
| 334 | std::string value = i.substr(pos + 1); |
| 335 | if (!allow_dup_key && kv_map.find(key) != kv_map.end()) { |
| 336 | return false; |
| 337 | } |
| 338 | kv_map[key] = value; |
| 339 | } |
| 340 | return true; |
| 341 | } |
| 342 | |
| 343 | void kv_map_to_stream(const std::map<std::string, std::string> &kv_map, |
| 344 | /*out*/ std::ostream &oss, |