diff --git a/base/base_tests/string_utils_test.cpp b/base/base_tests/string_utils_test.cpp index 0759e30410..faec4fc3f5 100644 --- a/base/base_tests/string_utils_test.cpp +++ b/base/base_tests/string_utils_test.cpp @@ -522,3 +522,18 @@ UNIT_TEST(IsHTML) TEST(!IsHTML("This is not html < too!"), ()); TEST(!IsHTML("I am > not html"), ()); } + +UNIT_TEST(AlmostEqual) +{ + using namespace strings; + + TEST(AlmostEqual("МКАД, 70-й километр", "МКАД, 79-й километр", 2), ()); + TEST(AlmostEqual("MKAD, 60 km", "MKAD, 59 km", 2), ()); + TEST(AlmostEqual("KAD, 5-y kilometre", "KAD, 7-y kilometre", 1), ()); + TEST(AlmostEqual("", "", 2), ()); + TEST(AlmostEqual("The Vista", "The Vista", 2), ()); + TEST(!AlmostEqual("Glasbrook Road", "ул. Петрова", 2), ()); + TEST(!AlmostEqual("MKAD, 600 km", "MKAD, 599 km", 2), ()); + TEST(!AlmostEqual("MKAD, 45-y kilometre", "MKAD, 46", 2), ()); + TEST(!AlmostEqual("ул. Героев Панфиловцев", "ул. Планерная", 2), ()); +} diff --git a/base/string_utils.cpp b/base/string_utils.cpp index 8b5d81f269..821e8c5da6 100644 --- a/base/string_utils.cpp +++ b/base/string_utils.cpp @@ -222,4 +222,21 @@ bool IsHTML(string const & utf8) return (ltCount > 0 && gtCount > 0); } +bool AlmostEqual(string const & str1, string const & str2, size_t mismatchedCount) +{ + pair mis(str1.begin(), str2.begin()); + auto const str1End = str1.end(); + auto const str2End = str2.end(); + + for (size_t i = 0; i <= mismatchedCount; ++i) + { + mis = mismatch(mis.first, str1End, mis.second); + if (mis.first == str1End && mis.second == str2End) + return true; + ++mis.first; + ++mis.second; + } + return false; +} + } // namespace strings diff --git a/base/string_utils.hpp b/base/string_utils.hpp index 9b4e3ce662..c1a0208dff 100644 --- a/base/string_utils.hpp +++ b/base/string_utils.hpp @@ -258,6 +258,9 @@ bool StartsWith(string const & s1, char const * s2); /// Try to guess if it's HTML or not. No guarantee. bool IsHTML(string const & utf8); +/// Compare str1 and str2 and return if they are equal except for mismatchedSymbolsNum symbols +bool AlmostEqual(string const & str1, string const & str2, size_t mismatchedCount); + /* template typename ItT::value_type JoinStrings(ItT begin, ItT end, DelimiterT const & delimiter) diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index c11d3f32b1..ac55cfdf39 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -306,7 +306,6 @@ public: } // namespace - OsrmRouter::OsrmRouter(Index const * index, CountryFileFnT const & fn) : m_countryFn(fn), m_pIndex(index), m_isFinalChanged(false), m_requestCancel(false) @@ -997,9 +996,9 @@ void OsrmRouter::FixupTurns(vector const & points, Route::TurnsT & t continue; } - if (!t.m_srcName.empty() - && t.m_srcName == t.m_trgName - && turns::IsTurnSlightOrStraight(t.m_turn)) + if (t.m_turn == turns::GoStraight + && !t.m_srcName.empty() + && strings::AlmostEqual(t.m_srcName, t.m_trgName, 2)) { turnsDir.erase(turnsDir.begin() + idx); continue; diff --git a/routing/turns.cpp b/routing/turns.cpp index 78ac321260..ae47d4f673 100644 --- a/routing/turns.cpp +++ b/routing/turns.cpp @@ -54,10 +54,5 @@ bool IsStayOnRoad(TurnDirection t) return (t == turns::GoStraight || t == turns::StayOnRoundAbout); } -bool IsTurnSlightOrStraight(TurnDirection t) -{ - return (t == GoStraight || t == TurnSlightRight || t == TurnSlightLeft); -} - } } diff --git a/routing/turns.hpp b/routing/turns.hpp index f9adcb9d12..3099490252 100644 --- a/routing/turns.hpp +++ b/routing/turns.hpp @@ -46,7 +46,6 @@ bool IsLeftTurn(TurnDirection t); bool IsRightTurn(TurnDirection t); bool IsLeftOrRightTurn(TurnDirection t); bool IsStayOnRoad(TurnDirection t); -bool IsTurnSlightOrStraight(TurnDirection t); } }