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
path: root/search
diff options
context:
space:
mode:
authorMaxim Pimenov <m@maps.me>2016-06-29 15:29:11 +0300
committerMaxim Pimenov <m@maps.me>2016-06-29 15:29:24 +0300
commitd7536acac09ce688800262b092a5b54238621ffe (patch)
treea33c3c6c27671978f01f86b22cd3c51e03f9c469 /search
parent3a7817fbdf44b11203bdadccdb34a08b8181e46b (diff)
Build fix.
Diffstat (limited to 'search')
-rw-r--r--search/utils.hpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/search/utils.hpp b/search/utils.hpp
new file mode 100644
index 0000000000..d1c8e3ea48
--- /dev/null
+++ b/search/utils.hpp
@@ -0,0 +1,42 @@
+#pragma once
+
+#include "search/token_slice.hpp"
+
+#include "indexer/categories_holder.hpp"
+
+#include "base/buffer_vector.hpp"
+#include "base/string_utils.hpp"
+
+namespace search
+{
+using TLocales = buffer_vector<int8_t, 3>;
+
+inline bool IsHashtagged(strings::UniString const & s) { return !s.empty() && s[0] == '#'; }
+
+inline strings::UniString RemoveHashtag(strings::UniString const & s)
+{
+ if (IsHashtagged(s))
+ return strings::UniString(s.begin() + 1, s.end());
+ return s;
+}
+
+template <typename ToDo>
+void ForEachCategoryType(StringSliceBase const & slice, TLocales const & locales,
+ CategoriesHolder const & categories, ToDo && todo)
+{
+ for (size_t i = 0; i < slice.Size(); ++i)
+ {
+ auto token = RemoveHashtag(slice.Get(i));
+ for (size_t j = 0; j < locales.size(); ++j)
+ categories.ForEachTypeByName(locales[j], token, bind<void>(todo, i, _1));
+
+ // Special case processing of 2 codepoints emoji (e.g. black guy on a bike).
+ // Only emoji synonyms can have one codepoint.
+ if (token.size() > 1)
+ {
+ categories.ForEachTypeByName(CategoriesHolder::kEnglishCode, strings::UniString(1, token[0]),
+ bind<void>(todo, i, _1));
+ }
+ }
+}
+} // namespace search