From d7536acac09ce688800262b092a5b54238621ffe Mon Sep 17 00:00:00 2001 From: Maxim Pimenov Date: Wed, 29 Jun 2016 15:29:11 +0300 Subject: [PATCH] Build fix. --- search/utils.hpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 search/utils.hpp 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; + +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 +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(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(todo, i, _1)); + } + } +} +} // namespace search