From 7b10a094efad6f6a05d7d55f4503a99047416806 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 31 Jul 2020 14:09:46 +0200 Subject: [PATCH] Fix #9529 --- .../net/osmand/search/core/SearchPhrase.java | 3 ++- .../main/java/net/osmand/util/Algorithms.java | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchPhrase.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchPhrase.java index 4cc5e63a84..f1b5b45b05 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchPhrase.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchPhrase.java @@ -160,7 +160,7 @@ public class SearchPhrase { public SearchPhrase generateNewPhrase(String text, SearchSettings settings) { - String textToSearch = text; + String textToSearch = Algorithms.normalizeSearchText(text); List leftWords = this.words; String thisTxt = getText(true); List foundWords = new ArrayList<>(); @@ -183,6 +183,7 @@ public class SearchPhrase { } + public static SearchPhrase emptyPhrase() { return emptyPhrase(null); } diff --git a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java index b5a466cb8b..575b975c63 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java @@ -44,6 +44,29 @@ public class Algorithms { public static boolean isEmpty(Collection c) { return c == null || c.size() == 0; } + + private static char[] CHARS_TO_NORMALIZE_KEY = new char['’']; + private static char[] CHARS_TO_NORMALIZE_VALUE = new char['\'']; + + public static String normalizeSearchText(String s) { + boolean norm = false; + for (int i = 0; i < s.length() && !norm; i++) { + char ch = s.charAt(i); + for (int j = 0; j < CHARS_TO_NORMALIZE_KEY.length; j++) { + if (ch == CHARS_TO_NORMALIZE_KEY[j]) { + norm = true; + break; + } + } + } + if (!norm) { + return s; + } + for (int k = 0; k < CHARS_TO_NORMALIZE_KEY.length; k++) { + s = s.replace(CHARS_TO_NORMALIZE_KEY[k], CHARS_TO_NORMALIZE_VALUE[k]); + } + return s; + } public static boolean isEmpty(Map map) { return map == null || map.size() == 0;