MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / ParseKeyValues

Function ParseKeyValues

src/Lexicon.cpp:27–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25namespace {
26
27DictEntry* 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

Callers 2

ParseLexiconFromFileMethod · 0.85

Calls 7

IsLineEndingOrFileEndingFunction · 0.85
FindNextInlineFunction · 0.85
FromSubstrFunction · 0.85
NextCharFunction · 0.85
NewFunction · 0.85
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected