MCPcopy Create free account
hub / github.com/alibaba/PhotonLibOS / do_parse_ini

Function do_parse_ini

ecosystem/simple_dom.cpp:392–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

390
391using ini_handler = void (*)(void*, estring_view, estring_view, estring_view);
392static int do_parse_ini(estring_view text, ini_handler h, void* user) {
393 int err_cnt = 0;
394 estring_view section;
395 for (auto line: text.split_lines()) {
396 auto comment = line.rfind(" ;");
397 if (comment < line.size())
398 line = line.substr(0, comment);
399 line = line.trim();
400 if (line.empty() || line[0] == '#' || line[0] == ';') continue;
401 if (line[0] == '[') {
402 if (line.back() == ']') {
403 section = line.substr(1, line.size() - 2).trim();
404 } else {
405 err_cnt++;
406 LOG_DEBUG("section with no ending: ", line);
407 }
408 } else {
409 auto eq = line.find_first_of(charset("=:"));
410 if (eq > 0 && eq < line.size() - 1) {
411 auto key = line.substr(0, eq).trim();
412 auto val = line.substr(eq + 1).trim();
413 h(user, section, key, val);
414 } else {
415 err_cnt++;
416 LOG_DEBUG("ill formed kv: ", line);
417 }
418 }
419 }
420 return -err_cnt;
421}
422
423static NodeImpl* parse_ini(char* text, size_t size, int flags) {
424 struct Item {

Callers 1

parse_iniFunction · 0.85

Calls 8

find_first_ofMethod · 0.80
charsetClass · 0.50
split_linesMethod · 0.45
sizeMethod · 0.45
substrMethod · 0.45
trimMethod · 0.45
emptyMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected