From b3fabc02c67fb9c3533eddbc12280631b3bc5bda Mon Sep 17 00:00:00 2001 From: vng Date: Thu, 10 Apr 2014 20:09:18 +0300 Subject: [PATCH] Minor code changes. --- search/house_detector.cpp | 11 ++++--- search/house_detector.hpp | 6 ---- search/latlon_match.cpp | 67 ++++++++++++--------------------------- 3 files changed, 26 insertions(+), 58 deletions(-) diff --git a/search/house_detector.cpp b/search/house_detector.cpp index e2979a570b..6932e99c41 100644 --- a/search/house_detector.cpp +++ b/search/house_detector.cpp @@ -1074,14 +1074,15 @@ void GetClosestHouse(MergedStreet const & st, ResultAccumulator & acc) acc.ProcessCandidate(st.Get(i)); } -/// if it's odd or even part of the street pass 2, else pass 1 +// If it's odd or even part of the street pass 2, else pass 1. void AddToQueue(int houseNumber, int step, queue & q) { - for (size_t i = 1; i <= 2; ++i) + for (int i = 1; i <= 2; ++i) { - q.push(houseNumber + step * i); - if (houseNumber - step * i > 0) - q.push(houseNumber - step * i); + int const delta = step * i; + q.push(houseNumber + delta); + if (houseNumber - delta > 0) + q.push(houseNumber - delta); } } diff --git a/search/house_detector.hpp b/search/house_detector.hpp index 4cd679049b..38a5939c91 100644 --- a/search/house_detector.hpp +++ b/search/house_detector.hpp @@ -149,12 +149,6 @@ public: HouseProjection const * GetHousePivot(bool isOdd, bool & sign) const; - /// @name Temporary - //@{ - inline size_t size() const { return m_cont.size(); } - inline Street const * operator[] (size_t i) const { return m_cont[i]; } - //@} - struct GreaterLength { bool operator() (MergedStreet const & s1, MergedStreet const & s2) const diff --git a/search/latlon_match.cpp b/search/latlon_match.cpp index 4e970423a5..8bbbebeadd 100644 --- a/search/latlon_match.cpp +++ b/search/latlon_match.cpp @@ -2,6 +2,8 @@ #include "../indexer/mercator.hpp" +#include "../base/macros.hpp" + #include "../std/array.hpp" #include "../std/cmath.hpp" #include "../std/cstdlib.hpp" @@ -83,63 +85,34 @@ bool MatchLatLon(string const & str, double & latRes, double & lonRes, namespace { -int Match1Byte(char const * & s) +bool MatchDMSArray(char const * & s, char const * arr[], size_t count) { - uint8_t const ch = static_cast(*s++); - switch (ch) + for (size_t i = 0; i < count; ++i) { - case 0xB0: // ° - return 0; - default: - return -1; - } -} - -int Match2Bytes(char const * & s) -{ - uint8_t ch = static_cast(*s++); - if (ch != 0x80) - return -1; - - ch = static_cast(*s++); - switch (ch) - { - case 0x99: // ’ - return 1; - case 0x9D: // ” - return 2; - case 0xB2: // ′ - if (static_cast(*s) == 0xE2 - && static_cast(*(s+1)) == 0x80 - && static_cast(*(s+2)) == 0xB2) + int const len = strlen(arr[i]); + if (strncmp(s, arr[i], len) == 0) { - s += 3; - return 2; // this specific case when the string is normalized and ″ is splitted to ′′ + s += len; + return true; } - return 1; - case 0xB3: // ″ - return 2; - default: - return -1; } + return false; } int GetDMSIndex(char const * & s) { - uint8_t const ch = static_cast(*s++); - switch (ch) - { - // UTF8 control symbols - case 0xC2: - return Match1Byte(s); - case 0xE2: - return Match2Bytes(s); + char const * arrDegree[] = { "*", "°" }; + char const * arrMinutes[] = { "\'", "’", "′" }; + char const * arrSeconds[] = { "\"", "”", "″", "\'\'", "’’", "′′" }; - case '*': return 0; - case '\'': return 1; - case '\"': return 2; - default: return -1; - } + if (MatchDMSArray(s, arrDegree, ARRAY_SIZE(arrDegree))) + return 0; + if (MatchDMSArray(s, arrSeconds, ARRAY_SIZE(arrSeconds))) + return 2; + if (MatchDMSArray(s, arrMinutes, ARRAY_SIZE(arrMinutes))) + return 1; + + return -1; } void SkipNSEW(char const * & s, char const * (&arrPos) [4])