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:
authortatiana-yan <tatiana.kondakova@gmail.com>2019-05-23 12:52:06 +0300
committermpimenov <mpimenov@users.noreply.github.com>2019-05-23 19:09:58 +0300
commit858b73e5169ecf83bdea8f03ef924a4105c7f690 (patch)
tree90b8df18b54e787f093a24b1e0a6287dbb952ebe /storage
parent28a21c83ee1feda55b649d5c758898fbdf2f3869 (diff)
[storage] Normalize CountryTree keys
Diffstat (limited to 'storage')
-rw-r--r--storage/country_tree.hpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/storage/country_tree.hpp b/storage/country_tree.hpp
index 6d266d298b..1b22055b2d 100644
--- a/storage/country_tree.hpp
+++ b/storage/country_tree.hpp
@@ -4,6 +4,7 @@
#include "storage/storage_defines.hpp"
#include "base/assert.hpp"
+#include "base/string_utils.hpp"
#include <algorithm>
#include <functional>
@@ -179,7 +180,7 @@ public:
}
ASSERT(added, ());
- m_countryTreeHashTable.insert(make_pair(value.Name(), added));
+ m_countryTreeHashTable.insert(make_pair(Normalize(value.Name()), added));
return added->Value();
}
@@ -199,10 +200,11 @@ public:
if (IsEmpty())
return;
- if (key == m_countryTree->Value().Name())
+ auto const normalizedKey = Normalize(key);
+ if (normalizedKey == Normalize(m_countryTree->Value().Name()))
found.push_back(m_countryTree.get());
- auto const range = m_countryTreeHashTable.equal_range(key);
+ auto const range = m_countryTreeHashTable.equal_range(normalizedKey);
if (range.first == range.second)
return;
@@ -218,6 +220,7 @@ public:
return nullptr;
std::vector<Node const *> found;
+ // |key| will be normalized inside Find.
Find(key, found);
if (found.empty())
return nullptr;
@@ -235,6 +238,7 @@ public:
return nullptr;
std::vector<Node const *> found;
+ // |key| will be normalized inside Find.
Find(key, found);
for (auto node : found)
@@ -248,6 +252,18 @@ public:
private:
using CountryTreeHashTable = std::multimap<CountryId, Node *>;
+ static CountryId Normalize(CountryId const & id)
+ {
+ auto normalized = strings::Normalize(id);
+ strings::MakeLowerCaseInplace(normalized);
+ if (strings::StartsWith(normalized, "the "))
+ normalized.erase(0, 4);
+ size_t pos = 0;
+ while ((pos = normalized.find(" the "), pos) != std::string::npos)
+ normalized.erase(pos, 4);
+ return normalized;
+ }
+
std::unique_ptr<Node> m_countryTree;
CountryTreeHashTable m_countryTreeHashTable;
};