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

Function ParseTranslations

generator/brands_loader.cpp:49–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49void ParseTranslations(json_t * root, std::set<string> const & keys, map<uint32_t, string> & idToKey)
50{
51 string const empty;
52 auto getKey = [&](string & translation) -> string const &
53 {
54 strings::MakeLowerCaseInplace(translation);
55 translation = strings::Normalize(translation);
56 replace(translation.begin(), translation.end(), ' ', '_');
57 replace(translation.begin(), translation.end(), '-', '_');
58 replace(translation.begin(), translation.end(), '\'', '_');
59 auto const it = keys.find(translation);
60 if (it != keys.end())
61 return *it;
62 return empty;
63 };
64
65 char const * key;
66 json_t * value;
67 json_object_foreach(root, key, value)
68 {
69 vector<string> enTranslations;
70 if (!FromJSONObjectOptional(value, "en", enTranslations))
71 continue;
72
73 for (auto & translation : enTranslations)
74 {
75 auto const & indexKey = getKey(translation);
76 if (!indexKey.empty())
77 {
78 uint32_t id;
79 if (!strings::to_uint(key, id))
80 MYTHROW(ParsingError, ("Incorrect brand id:", key));
81 idToKey.emplace(id, indexKey);
82 break;
83 }
84 }
85 }
86}
87
88bool LoadBrands(string const & brandsFilename, string const & translationsFilename, map<GeoObjectId, string> & brands)
89{

Callers 1

LoadBrandsFunction · 0.85

Calls 6

replaceFunction · 0.85
MakeLowerCaseInplaceFunction · 0.50
NormalizeFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected