| 56 | } |
| 57 | |
| 58 | void INIParser::ParseContent(const string &content) { |
| 59 | phxqueue::comm::utils::RWLock rwlock_read(&impl_->rwlock, phxqueue::comm::utils::RWLock::LockMode::WRITE); |
| 60 | |
| 61 | string section, key, val; |
| 62 | |
| 63 | impl_->section_key2val.clear(); |
| 64 | |
| 65 | if (content.empty()) return; |
| 66 | const char *src = content.c_str(); |
| 67 | int len = content.length(); |
| 68 | |
| 69 | const char *eol, *tmp; |
| 70 | |
| 71 | for (const char *ptr = src; len > 0;) { |
| 72 | eol = strchr(ptr, '\n'); // for each line |
| 73 | |
| 74 | if (eol == NULL) eol = ptr + len; // last line |
| 75 | |
| 76 | len -= ( eol - ptr +1); |
| 77 | |
| 78 | if (ptr < eol) { |
| 79 | while (ptr < eol && (*ptr == ' ' || *ptr == '\t')) ptr++; // ltrim |
| 80 | if (*ptr == '[') { //section |
| 81 | ptr += 1; |
| 82 | tmp = ptr; |
| 83 | for (; *ptr != ']' && *ptr != '\n' && ptr < eol; ptr++); |
| 84 | |
| 85 | section = Slice2String(tmp, ptr); |
| 86 | StrTrim("\t ", section); |
| 87 | } else if (nullptr == strchr("#;\n",*ptr)) { //item |
| 88 | tmp = ptr; |
| 89 | for (; *ptr != '=' && ptr < eol; ptr++); |
| 90 | |
| 91 | key = Slice2String(tmp, ptr); |
| 92 | StrTrim("\t ", key); |
| 93 | |
| 94 | if (*ptr == '=' && !section.empty()) { |
| 95 | ptr += 1; |
| 96 | |
| 97 | tmp = ptr; |
| 98 | for (; *ptr != '\n' && *ptr != '\r' && ptr < eol ; ptr++); |
| 99 | |
| 100 | val = Slice2String(tmp, ptr); |
| 101 | StrTrim("\t ", val); |
| 102 | |
| 103 | impl_->section_key2val.emplace(make_pair(section, key), val); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | ptr = eol + 1; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | |
| 113 | bool INIParser::GetValue(const string §ion, const string &key, string &val) { |
nothing calls this directly
no test coverage detected