Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Gorshenin <y@maps.me>2016-09-07 12:04:07 +0300
committerYuri Gorshenin <y@maps.me>2016-09-07 12:09:34 +0300
commite8a77fb0fbf27ba468a8b3f952efd0fb3743cabd (patch)
treec351e6fe6856798828dc06446cde5998cdbbf099 /indexer/categories_holder.cpp
parente34ff29fc192f5fe62e6a4ee21dd634277107c9a (diff)
[search][android][ios] Exposed categories synonyms.
Diffstat (limited to 'indexer/categories_holder.cpp')
-rw-r--r--indexer/categories_holder.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/indexer/categories_holder.cpp b/indexer/categories_holder.cpp
index c723cbee17..cac2e9e7fe 100644
--- a/indexer/categories_holder.cpp
+++ b/indexer/categories_holder.cpp
@@ -22,8 +22,12 @@ enum State
// static
int8_t const CategoriesHolder::kEnglishCode = 1;
int8_t const CategoriesHolder::kUnsupportedLocaleCode = -1;
-// *NOTE* These constants should be updated when
-// adding new translation to categories.txt.
+
+// *NOTE* These constants should be updated when adding new
+// translation to categories.txt. When editing, keep in mind to check
+// CategoriesHolder::MapLocaleToInteger() and
+// CategoriesHolder::MapIntegerToLocale() as their implementations
+// highly depend on the contents of the variable.
vector<CategoriesHolder::Mapping> const CategoriesHolder::kLocaleMapping = {{"en", 1},
{"ru", 2},
{"uk", 3},
@@ -111,6 +115,7 @@ void CategoriesHolder::LoadFromStream(istream & s)
{
m_type2cat.clear();
m_name2type.clear();
+ m_groupTranslations.clear();
State state = EParseTypes;
string line;
@@ -118,7 +123,6 @@ void CategoriesHolder::LoadFromStream(istream & s)
Category cat;
vector<uint32_t> types;
vector<string> currentGroups;
- multimap<string, Category::Name> groupTranslations;
Classificator const & c = classif();
@@ -184,9 +188,11 @@ void CategoriesHolder::LoadFromStream(istream & s)
{
for (string const & group : currentGroups)
{
- auto trans = groupTranslations.equal_range(group);
- for (auto it = trans.first; it != trans.second; ++it)
- cat.m_synonyms.push_back(it->second);
+ auto it = m_groupTranslations.find(group);
+ if (it == m_groupTranslations.end())
+ continue;
+ for (auto const & synonym : it->second)
+ cat.m_synonyms.push_back(synonym);
}
}
@@ -242,7 +248,7 @@ void CategoriesHolder::LoadFromStream(istream & s)
if (currentGroups.size() == 1 && types.empty())
{
// Not a translation, but a category group definition
- groupTranslations.emplace(currentGroups[0], name);
+ m_groupTranslations[currentGroups[0]].push_back(name);
}
else
cat.m_synonyms.push_back(name);
@@ -308,6 +314,7 @@ bool CategoriesHolder::IsTypeExist(uint32_t type) const
return range.first != range.second;
}
+// static
int8_t CategoriesHolder::MapLocaleToInteger(string const & locale)
{
ASSERT(!kLocaleMapping.empty(), ());
@@ -338,3 +345,11 @@ int8_t CategoriesHolder::MapLocaleToInteger(string const & locale)
return kUnsupportedLocaleCode;
}
+
+// static
+string CategoriesHolder::MapIntegerToLocale(int8_t code)
+{
+ if (code <= 0 || code > kLocaleMapping.size())
+ return string();
+ return kLocaleMapping[code - 1].m_name;
+}