MCPcopy Create free account
hub / github.com/comaps/comaps / LoadFromStream

Method LoadFromStream

libs/indexer/categories_holder.cpp:175–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173}
174
175void CategoriesHolder::LoadFromStream(std::istream & s)
176{
177 m_type2cat.clear();
178 m_name2type.Clear();
179 m_groupTranslations.clear();
180
181 ParseState state = EParseTypes;
182 std::string line;
183 Category cat;
184 std::vector<uint32_t> types;
185 std::vector<std::string> currentGroups;
186
187 int lineNumber = 0;
188 while (s.good())
189 {
190 ++lineNumber;
191 getline(s, line);
192 strings::Trim(line);
193 // Allow for comments starting with '#' character.
194 if (!line.empty() && line[0] == '#')
195 continue;
196
197 strings::SimpleTokenizer iter(line, state == EParseTypes ? "|" : ":|");
198
199 if (state == EParseTypes)
200 {
201 AddCategory(cat, types);
202 currentGroups.clear();
203
204 while (iter)
205 {
206 ProcessCategory(*iter, currentGroups, types);
207 ++iter;
208 }
209
210 if (!types.empty() || currentGroups.size() == 1)
211 {
212 state = EParseLanguages;
213 AddGroupTranslationsToSynonyms(currentGroups, m_groupTranslations, cat.m_synonyms);
214 }
215 }
216 else if (state == EParseLanguages)
217 {
218 if (!iter)
219 {
220 state = EParseTypes;
221 continue;
222 }
223
224 int8_t const langCode = MapLocaleToInteger(*iter);
225 CHECK(langCode != kUnsupportedLocaleCode, ("Invalid language code:", *iter, "at line:", lineNumber));
226
227 while (++iter)
228 {
229 Category::Name name;
230 name.m_locale = langCode;
231 name.m_name = *iter;
232

Callers

nothing calls this directly

Calls 8

TrimFunction · 0.85
ProcessCategoryFunction · 0.85
ProcessNameFunction · 0.85
clearMethod · 0.45
ClearMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected