diff options
author | VladiMihaylenko <vxmihaylenko@gmail.com> | 2016-04-27 19:44:11 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2016-05-01 10:28:03 +0300 |
commit | 9d7fc9dbbe1a2fc816c5afa049b8eab4f827bb2c (patch) | |
tree | 3727ff3da3c9ba50a26d7671093c3a4d7d4e44bf /editor | |
parent | 920f2577a35aba443ee33abf36050f7d0c66a505 (diff) |
[ios] Implemented new category search.
Diffstat (limited to 'editor')
-rw-r--r-- | editor/new_feature_categories.cpp | 40 | ||||
-rw-r--r-- | editor/new_feature_categories.hpp | 16 |
2 files changed, 40 insertions, 16 deletions
diff --git a/editor/new_feature_categories.cpp b/editor/new_feature_categories.cpp index 456b076dfd..24733ed7aa 100644 --- a/editor/new_feature_categories.cpp +++ b/editor/new_feature_categories.cpp @@ -29,9 +29,24 @@ NewFeatureCategories::NewFeatureCategories(editor::EditorConfig const & config) } } -void NewFeatureCategories::AddLanguage(string const & lang) +NewFeatureCategories::NewFeatureCategories(NewFeatureCategories && other) + : m_index(move(other.m_index)) + , m_types(move(other.m_types)) + , m_categoriesByLang(move(other.m_categoriesByLang)) { - auto const langCode = CategoriesHolder::MapLocaleToInteger(lang); +} + +void NewFeatureCategories::AddLanguage(string lang) +{ + auto langCode = CategoriesHolder::MapLocaleToInteger(lang); + if (langCode == CategoriesHolder::kUnsupportedLocaleCode) + { + lang = "en"; + langCode = CategoriesHolder::kEnglishCode; + } + if (m_categoriesByLang.find(lang) != m_categoriesByLang.end()) + return; + NewFeatureCategories::TNames names; names.reserve(m_types.size()); for (auto const & type : m_types) @@ -43,17 +58,24 @@ void NewFeatureCategories::AddLanguage(string const & lang) m_categoriesByLang[lang] = names; } -NewFeatureCategories::TNames NewFeatureCategories::Search(string const & query, - string const & lang) const +NewFeatureCategories::TNames NewFeatureCategories::Search(string const & query, string lang) const { - auto const langCode = CategoriesHolder::MapLocaleToInteger(lang); + auto langCode = CategoriesHolder::MapLocaleToInteger(lang); + if (langCode == CategoriesHolder::kUnsupportedLocaleCode) + { + lang = "en"; + langCode = CategoriesHolder::kEnglishCode; + } vector<uint32_t> resultTypes; m_index.GetAssociatedTypes(query, resultTypes); NewFeatureCategories::TNames result(resultTypes.size()); for (size_t i = 0; i < result.size(); ++i) - result[i] = {m_index.GetCategoriesHolder()->GetReadableFeatureType(resultTypes[i], langCode), - resultTypes[i]}; + { + result[i].first = + m_index.GetCategoriesHolder()->GetReadableFeatureType(resultTypes[i], langCode); + result[i].second = resultTypes[i]; + } my::SortUnique(result); return result; } @@ -61,7 +83,9 @@ NewFeatureCategories::TNames NewFeatureCategories::Search(string const & query, NewFeatureCategories::TNames const & NewFeatureCategories::GetAllCategoryNames( string const & lang) const { - auto const it = m_categoriesByLang.find(lang); + auto it = m_categoriesByLang.find(lang); + if (it == m_categoriesByLang.end()) + it = m_categoriesByLang.find("en"); CHECK(it != m_categoriesByLang.end(), ()); return it->second; } diff --git a/editor/new_feature_categories.hpp b/editor/new_feature_categories.hpp index 6f1ad89bf5..0e46108a3c 100644 --- a/editor/new_feature_categories.hpp +++ b/editor/new_feature_categories.hpp @@ -23,12 +23,7 @@ public: NewFeatureCategories(editor::EditorConfig const & config); - NewFeatureCategories(NewFeatureCategories && other) - : m_index(move(other.m_index)) - , m_types(move(other.m_types)) - , m_categoriesByLang(move(other.m_categoriesByLang)) - { - } + NewFeatureCategories(NewFeatureCategories && other); NewFeatureCategories() = default; @@ -36,15 +31,20 @@ public: // Adds all known synonyms in language |lang| for all categories that // can be applied to a newly added feature. - void AddLanguage(string const & lang); + // If one language is added more than once, all the calls except for the + // first one are ignored. + // If |lang| is not supported, "en" is used. + void AddLanguage(string lang); // Returns names (in language |lang|) and types of categories that have a synonym containing // the substring |query| (in any language that was added before). + // If |lang| is not supported, "en" is used. // The returned list is sorted. - TNames Search(string const & query, string const & lang) const; + TNames Search(string const & query, string lang) const; // Returns all registered names of categories in language |lang| and // types corresponding to these names. The language must have been added before. + // If |lang| is not supported, "en" is used. // The returned list is sorted. TNames const & GetAllCategoryNames(string const & lang) const; |