From 228aafdfbefb174d55564ba4e20b0a5915eca931 Mon Sep 17 00:00:00 2001 From: Viktor Govako Date: Thu, 13 Oct 2022 14:43:36 +0300 Subject: [PATCH] Removed obsolete functions. Signed-off-by: Viktor Govako --- base/string_utils.cpp | 7 ----- base/string_utils.hpp | 6 ++++- indexer/feature_data.cpp | 3 +-- indexer/feature_impl.cpp | 55 ++-------------------------------------- indexer/feature_impl.hpp | 21 ++++----------- search/query_params.cpp | 2 +- 6 files changed, 14 insertions(+), 80 deletions(-) diff --git a/base/string_utils.cpp b/base/string_utils.cpp index 028645d175..819a528996 100644 --- a/base/string_utils.cpp +++ b/base/string_utils.cpp @@ -294,13 +294,6 @@ bool IsASCIISpace(UniChar c) return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v'; } -bool IsASCIINumeric(std::string const & str) -{ - if (str.empty()) - return false; - return std::all_of(str.begin(), str.end(), strings::IsASCIIDigit); -} - bool IsASCIILatin(UniChar c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } bool StartsWith(UniString const & s, UniString const & p) diff --git a/base/string_utils.hpp b/base/string_utils.hpp index 5bfe684d9c..8daa3fdc38 100644 --- a/base/string_utils.hpp +++ b/base/string_utils.hpp @@ -128,7 +128,11 @@ UniString MakeUniString(std::string_view utf8s); std::string ToUtf8(UniString const & s); bool IsASCIIString(std::string_view sv); bool IsASCIIDigit(UniChar c); -bool IsASCIINumeric(std::string const & str); +template bool IsASCIINumeric(StringT const & str) +{ + return !std::empty(str) && std::all_of(std::begin(str), std::end(str), &IsASCIIDigit); +} +inline bool IsASCIINumeric(char const * s) { return IsASCIINumeric(std::string_view(s)); } bool IsASCIISpace(UniChar c); bool IsASCIILatin(UniChar c); diff --git a/indexer/feature_data.cpp b/indexer/feature_data.cpp index 4627079e21..536897b55a 100644 --- a/indexer/feature_data.cpp +++ b/indexer/feature_data.cpp @@ -2,7 +2,6 @@ #include "indexer/classificator.hpp" #include "indexer/feature.hpp" -#include "indexer/feature_impl.hpp" #include "indexer/ftypes_matcher.hpp" #include "base/assert.hpp" @@ -347,7 +346,7 @@ bool FeatureParams::AddHouseNumber(string houseNumber) ++i; houseNumber.erase(0, i); - if (any_of(houseNumber.cbegin(), houseNumber.cend(), IsDigit)) + if (any_of(houseNumber.cbegin(), houseNumber.cend(), &strings::IsASCIIDigit)) { house.Set(houseNumber); return true; diff --git a/indexer/feature_impl.cpp b/indexer/feature_impl.cpp index a5510c936f..81e07059b4 100644 --- a/indexer/feature_impl.cpp +++ b/indexer/feature_impl.cpp @@ -1,66 +1,15 @@ #include "indexer/feature_impl.hpp" #include "base/string_utils.hpp" -#include "base/logging.hpp" #include "base/math.hpp" -#include - -using namespace std; - namespace feature { - -bool IsDigit(int c) -{ - return (int('0') <= c && c <= int('9')); -} - -bool IsNumber(strings::UniString const & s) -{ - for (size_t i = 0; i < s.size(); ++i) - { - // android production ndk-r8d has bug. "еда" detected as a number. - if (!IsDigit(s[i])) - return false; - } - return true; -} - -bool IsStreetNumber(strings::UniString const & s) -{ - if (s.size() < 2) - return false; - - /// add different localities in future, if it's a problem. - for (auto const & streetEnding : {"st", "nd", "rd", "th"}) - { - if (strings::EndsWith(strings::ToUtf8(s), streetEnding)) - return true; - } - return false; -} - -bool IsHouseNumberDeepCheck(strings::UniString const & s) -{ - size_t const count = s.size(); - if (count == 0) - return false; - if (!IsDigit(s[0])) - return false; - if (IsStreetNumber(s)) - return false; - return (count < 8); -} +using namespace std; bool IsHouseNumber(string const & s) { - return (!s.empty() && IsDigit(s[0])); -} - -bool IsHouseNumber(strings::UniString const & s) -{ - return (!s.empty() && IsDigit(s[0])); + return !s.empty() && strings::IsASCIIDigit(s[0]); } uint8_t PopulationToRank(uint64_t p) diff --git a/indexer/feature_impl.hpp b/indexer/feature_impl.hpp index 6ff167d0aa..7a59160d29 100644 --- a/indexer/feature_impl.hpp +++ b/indexer/feature_impl.hpp @@ -3,7 +3,6 @@ #include "indexer/scales.hpp" #include "base/assert.hpp" -#include "base/macros.hpp" #include #include @@ -12,27 +11,17 @@ namespace strings { class UniString; } namespace feature { -static int const g_arrWorldScales[] = {3, 5, 7, 9}; -static_assert(9 == scales::GetUpperWorldScale(), ""); -static int const g_arrCountryScales[] = {10, 12, 14, 17}; -static_assert(17 == scales::GetUpperScale(), ""); +int constexpr g_arrWorldScales[] = { 3, 5, 7, scales::GetUpperWorldScale() }; +int constexpr g_arrCountryScales[] = { 10, 12, 14, scales::GetUpperScale() }; +static_assert(std::size(g_arrWorldScales) == std::size(g_arrCountryScales)); inline std::string GetTagForIndex(std::string const & prefix, size_t ind) { - static char const arrChar[] = {'0', '1', '2', '3'}; - static_assert(ARRAY_SIZE(arrChar) >= ARRAY_SIZE(g_arrWorldScales), ""); - static_assert(ARRAY_SIZE(arrChar) >= ARRAY_SIZE(g_arrCountryScales), ""); - ASSERT(ind < ARRAY_SIZE(arrChar), (ind)); - - return prefix + arrChar[ind]; + ASSERT(ind < std::size(g_arrWorldScales) && ind < std::size(g_arrCountryScales), (ind)); + return prefix + char('0' + ind); } -bool IsDigit(int c); -bool IsNumber(strings::UniString const & s); - bool IsHouseNumber(std::string const & s); -bool IsHouseNumber(strings::UniString const & s); -bool IsHouseNumberDeepCheck(strings::UniString const & s); uint8_t PopulationToRank(uint64_t p); uint64_t RankToPopulation(uint8_t r); diff --git a/search/query_params.cpp b/search/query_params.cpp index d5cab7ae5f..9b64eb00aa 100644 --- a/search/query_params.cpp +++ b/search/query_params.cpp @@ -151,7 +151,7 @@ bool QueryParams::IsNumberTokens(TokenRange const & range) const for (size_t i : range) { - if (!GetToken(i).AnyOfOriginalOrSynonyms([](String const & s) { return feature::IsNumber(s); })) + if (!GetToken(i).AnyOfOriginalOrSynonyms([](String const & s) { return strings::IsASCIINumeric(s); })) return false; }