Changeset 13836 in josm


Ignore:
Timestamp:
2018-05-26T00:47:08+02:00 (11 months ago)
Author:
Don-vip
Message:

fix #13889 - Make preset searchs ignore accents

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/SimilarNamedWays.java

    r13390 r13836  
    77
    88import java.awt.geom.Point2D;
    9 import java.text.Normalizer;
    109import java.util.ArrayList;
    1110import java.util.Arrays;
     
    2524import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2625import org.openstreetmap.josm.tools.MultiMap;
     26import org.openstreetmap.josm.tools.Utils;
    2727
    2828/**
     
    3535
    3636    protected static final int SIMILAR_NAMED = 701;
    37 
    38     private static final Pattern REMOVE_DIACRITICS = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
    3937
    4038    /** All ways, grouped by cells */
     
    207205        // check if only the case differs, so we don't consider large distance as different strings
    208206        if (distance > 2 && name.length() == name2.length()) {
    209             similar = deAccent(name).equalsIgnoreCase(deAccent(name2));
     207            similar = Utils.deAccent(name).equalsIgnoreCase(Utils.deAccent(name2));
    210208        }
    211209
     
    225223
    226224    /**
    227      * Removes diacritics (accents) from string.
    228      * @param str string
    229      * @return {@code str} without any diacritic (accent)
    230      * @since 12283
    231      */
    232     public static String deAccent(String str) {
    233         // https://stackoverflow.com/a/1215117/2257172
    234         return REMOVE_DIACRITICS.matcher(Normalizer.normalize(str, Normalizer.Form.NFD)).replaceAll("");
    235     }
    236 
    237     /**
    238225     * A normalization that is applied to names before testing them
    239226     */
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java

    r12691 r13836  
    1818import java.util.Objects;
    1919import java.util.Set;
     20import java.util.stream.Collectors;
    2021
    2122import javax.swing.AbstractAction;
     
    128129        private static int isMatching(Collection<String> values, String... searchString) {
    129130            int sum = 0;
     131            List<String> deaccentedValues = values.stream().map(
     132                    s -> Utils.deAccent(s).toLowerCase(Locale.ENGLISH)).collect(Collectors.toList());
    130133            for (String word: searchString) {
    131134                boolean found = false;
    132135                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);
    135139                    if (index == 0) {
    136140                        foundFirst = true;
  • trunk/src/org/openstreetmap/josm/tools/AlphanumComparator.java

    r12909 r13836  
    3434import java.text.Collator;
    3535import java.util.Comparator;
    36 import java.util.Locale;
    3736
    3837/**
     
    141140            } else {
    142141                // Instantiate the collator
    143                 Collator compareOperator = Collator.getInstance(Locale.getDefault());
     142                Collator compareOperator = Collator.getInstance();
    144143                // Compare regardless of accented letters
    145144                compareOperator.setStrength(Collator.SECONDARY);
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r13716 r13836  
    3636import java.text.DateFormat;
    3737import java.text.MessageFormat;
     38import java.text.Normalizer;
    3839import java.text.ParseException;
    3940import java.util.AbstractCollection;
     
    9899    public static final String URL_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;=%";
    99100
     101    private static final Pattern REMOVE_DIACRITICS = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
     102
    100103    private static final char[] DEFAULT_STRIP = {'\u200B', '\uFEFF'};
    101104
     
    15591562        }
    15601563        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("");
    15611575    }
    15621576
Note: See TracChangeset for help on using the changeset viewer.