| 25 | namespace { |
| 26 | |
| 27 | DictEntry* ParseKeyValues(const char* buff, size_t lineNum) { |
| 28 | size_t length; |
| 29 | if (buff == nullptr || UTF8Util::IsLineEndingOrFileEnding(*buff)) { |
| 30 | return nullptr; |
| 31 | } |
| 32 | const char* pbuff = UTF8Util::FindNextInline(buff, '\t'); |
| 33 | if (UTF8Util::IsLineEndingOrFileEnding(*pbuff)) { |
| 34 | throw InvalidTextDictionary("Tabular not found " + std::string(buff), |
| 35 | lineNum); |
| 36 | } |
| 37 | length = static_cast<size_t>(pbuff - buff); |
| 38 | std::string key = UTF8Util::FromSubstr(buff, length); |
| 39 | std::vector<std::string> values; |
| 40 | while (!UTF8Util::IsLineEndingOrFileEnding(*pbuff)) { |
| 41 | buff = pbuff = UTF8Util::NextChar(pbuff); |
| 42 | pbuff = UTF8Util::FindNextInline(buff, ' '); |
| 43 | length = static_cast<size_t>(pbuff - buff); |
| 44 | const std::string& value = UTF8Util::FromSubstr(buff, length); |
| 45 | values.push_back(value); |
| 46 | } |
| 47 | if (values.size() == 0) { |
| 48 | throw InvalidTextDictionary("No value in an item", lineNum); |
| 49 | } else if (values.size() == 1) { |
| 50 | return DictEntryFactory::New(key, values.at(0)); |
| 51 | } else { |
| 52 | return DictEntryFactory::New(key, values); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | } // namespace |
| 57 |
no test coverage detected