- Timestamp:
- 2018-05-26T00:47:08+02:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/SimilarNamedWays.java
r13390 r13836 7 7 8 8 import java.awt.geom.Point2D; 9 import java.text.Normalizer;10 9 import java.util.ArrayList; 11 10 import java.util.Arrays; … … 25 24 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 26 25 import org.openstreetmap.josm.tools.MultiMap; 26 import org.openstreetmap.josm.tools.Utils; 27 27 28 28 /** … … 35 35 36 36 protected static final int SIMILAR_NAMED = 701; 37 38 private static final Pattern REMOVE_DIACRITICS = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");39 37 40 38 /** All ways, grouped by cells */ … … 207 205 // check if only the case differs, so we don't consider large distance as different strings 208 206 if (distance > 2 && name.length() == name2.length()) { 209 similar = deAccent(name).equalsIgnoreCase(deAccent(name2));207 similar = Utils.deAccent(name).equalsIgnoreCase(Utils.deAccent(name2)); 210 208 } 211 209 … … 225 223 226 224 /** 227 * Removes diacritics (accents) from string.228 * @param str string229 * @return {@code str} without any diacritic (accent)230 * @since 12283231 */232 public static String deAccent(String str) {233 // https://stackoverflow.com/a/1215117/2257172234 return REMOVE_DIACRITICS.matcher(Normalizer.normalize(str, Normalizer.Form.NFD)).replaceAll("");235 }236 237 /**238 225 * A normalization that is applied to names before testing them 239 226 */ -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java
r12691 r13836 18 18 import java.util.Objects; 19 19 import java.util.Set; 20 import java.util.stream.Collectors; 20 21 21 22 import javax.swing.AbstractAction; … … 128 129 private static int isMatching(Collection<String> values, String... searchString) { 129 130 int sum = 0; 131 List<String> deaccentedValues = values.stream().map( 132 s -> Utils.deAccent(s).toLowerCase(Locale.ENGLISH)).collect(Collectors.toList()); 130 133 for (String word: searchString) { 131 134 boolean found = false; 132 135 boolean foundFirst = false; 133 for (String value: values) { 134 int index = value.toLowerCase(Locale.ENGLISH).indexOf(word); 136 String deaccentedWord = Utils.deAccent(word); 137 for (String value: deaccentedValues) { 138 int index = value.indexOf(deaccentedWord); 135 139 if (index == 0) { 136 140 foundFirst = true; -
trunk/src/org/openstreetmap/josm/tools/AlphanumComparator.java
r12909 r13836 34 34 import java.text.Collator; 35 35 import java.util.Comparator; 36 import java.util.Locale;37 36 38 37 /** … … 141 140 } else { 142 141 // Instantiate the collator 143 Collator compareOperator = Collator.getInstance( Locale.getDefault());142 Collator compareOperator = Collator.getInstance(); 144 143 // Compare regardless of accented letters 145 144 compareOperator.setStrength(Collator.SECONDARY); -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r13716 r13836 36 36 import java.text.DateFormat; 37 37 import java.text.MessageFormat; 38 import java.text.Normalizer; 38 39 import java.text.ParseException; 39 40 import java.util.AbstractCollection; … … 98 99 public static final String URL_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;=%"; 99 100 101 private static final Pattern REMOVE_DIACRITICS = Pattern.compile("\\p{InCombiningDiacriticalMarks}+"); 102 100 103 private static final char[] DEFAULT_STRIP = {'\u200B', '\uFEFF'}; 101 104 … … 1559 1562 } 1560 1563 return gvs; 1564 } 1565 1566 /** 1567 * Removes diacritics (accents) from string. 1568 * @param str string 1569 * @return {@code str} without any diacritic (accent) 1570 * @since 13836 (moved from SimilarNamedWays) 1571 */ 1572 public static String deAccent(String str) { 1573 // https://stackoverflow.com/a/1215117/2257172 1574 return REMOVE_DIACRITICS.matcher(Normalizer.normalize(str, Normalizer.Form.NFD)).replaceAll(""); 1561 1575 } 1562 1576
Note:
See TracChangeset
for help on using the changeset viewer.