Ignore:
Timestamp:
2015-05-21T01:18:35+02:00 (7 years ago)
Author:
Don-vip
Message:

When doing a String.toLowerCase()/toUpperCase() call, use a Locale. This avoids problems with certain locales, i.e. Lithuanian or Turkish. See PMD UseLocaleWithCaseConversions rule and String.toLowerCase() javadoc.

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ColorHelper.java

    r8345 r8404  
    33
    44import java.awt.Color;
     5import java.util.Locale;
    56
    67/**
     
    4041    private static String int2hex(int i) {
    4142        String s = Integer.toHexString(i / 16) + Integer.toHexString(i % 16);
    42         return s.toUpperCase();
     43        return s.toUpperCase(Locale.ENGLISH);
    4344    }
    4445
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r8395 r8404  
    693693            }
    694694
    695             ImageType type = name.toLowerCase().endsWith(".svg") ? ImageType.SVG : ImageType.OTHER;
     695            ImageType type = Utils.hasExtension(name, "svg") ? ImageType.SVG : ImageType.OTHER;
    696696
    697697            if (name.startsWith(HTTP_PROTOCOL) || name.startsWith(HTTPS_PROTOCOL)) {
  • trunk/src/org/openstreetmap/josm/tools/LanguageInfo.java

    r8284 r8404  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.tools;
    3 
    4 import static org.openstreetmap.josm.tools.I18n.trc;
    53
    64import java.util.Collection;
     
    5553            return null;
    5654        } else if(code.matches(".+@.+")) {
    57           return code.substring(0,1).toUpperCase() + code.substring(1,2)
    58           + "-" + code.substring(3,4).toUpperCase() + code.substring(4) + ":";
    59         }
    60         return code.substring(0,1).toUpperCase() + code.substring(1) + ":";
     55          return code.substring(0,1).toUpperCase(Locale.ENGLISH) + code.substring(1,2)
     56          + "-" + code.substring(3,4).toUpperCase(Locale.ENGLISH) + code.substring(4) + ":";
     57        }
     58        return code.substring(0,1).toUpperCase(Locale.ENGLISH) + code.substring(1) + ":";
    6159    }
    6260
     
    8886     * to identify the locale of a localized resource, but in some cases it may use the
    8987     * programmatic name for locales, as replied by {@link Locale#toString()}.
    90      * 
     88     *
    9189     * For unknown country codes and variants this function already does fallback to
    9290     * internally known translations.
     
    191189        return want.equals(newLanguage) || (!want.equals(oldLanguage) && newLanguage.startsWith("en"));
    192190    }
    193    
     191
    194192    /**
    195193     * Replies the language prefix for use in XML elements (with a dot appended).
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java

    r8390 r8404  
    3232import java.util.Collection;
    3333import java.util.List;
     34import java.util.Locale;
    3435import java.util.Properties;
    3536
     
    501502                for (FontEntry entry: extrasPref) {
    502503                    Collection<String> fontsAvail = getInstalledFonts();
    503                     if (fontsAvail != null && fontsAvail.contains(entry.file.toUpperCase())) {
     504                    if (fontsAvail != null && fontsAvail.contains(entry.file.toUpperCase(Locale.ENGLISH))) {
    504505                        if (!allCharSubsets.contains(entry.charset)) {
    505506                            allCharSubsets.add(entry.charset);
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java

    r8379 r8404  
    5050import java.util.Enumeration;
    5151import java.util.List;
     52import java.util.Locale;
    5253
    5354import javax.swing.JOptionPane;
     
    320321                Path filename = p.getFileName();
    321322                if (filename != null) {
    322                     fontsAvail.add(filename.toString().toUpperCase());
     323                    fontsAvail.add(filename.toString().toUpperCase(Locale.ENGLISH));
    323324                }
    324325            }
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r8390 r8404  
    4242import java.util.Iterator;
    4343import java.util.List;
     44import java.util.Locale;
    4445import java.util.concurrent.ExecutorService;
    4546import java.util.concurrent.Executors;
     
    12061207        if (value != null) {
    12071208            String old = System.setProperty(key, value);
    1208             if (!key.toLowerCase().contains("password")) {
     1209            if (!key.toLowerCase(Locale.ENGLISH).contains("password")) {
    12091210                Main.debug("System property '"+key+"' set to '"+value+"'. Old value was '"+old+"'");
    12101211            } else {
     
    12511252        }
    12521253    }
     1254
     1255    /**
     1256     * Determines if the filename has one of the given extensions, in a robust manner.
     1257     * The comparison is case and locale insensitive.
     1258     * @param filename The file name
     1259     * @param extensions The list of extensions to look for (without dot)
     1260     * @return {@code true} if the filename has one of the given extensions
     1261     * @since 8404
     1262     */
     1263    public static boolean hasExtension(String filename, String ... extensions) {
     1264        String name = filename.toLowerCase(Locale.ENGLISH);
     1265        for (String ext : extensions)
     1266            if (name.endsWith("."+ext.toLowerCase(Locale.ENGLISH)))
     1267                return true;
     1268        return false;
     1269    }
     1270
     1271    /**
     1272     * Determines if the file's name has one of the given extensions, in a robust manner.
     1273     * The comparison is case and locale insensitive.
     1274     * @param file The file
     1275     * @param extensions The list of extensions to look for (without dot)
     1276     * @return {@code true} if the file's name has one of the given extensions
     1277     * @since 8404
     1278     */
     1279    public static boolean hasExtension(File file, String ... extensions) {
     1280        return hasExtension(file.getName(), extensions);
     1281    }
    12531282}
  • trunk/src/org/openstreetmap/josm/tools/template_engine/Variable.java

    r8390 r8404  
    33
    44import java.util.Collection;
     5import java.util.Locale;
    56
    67public class Variable implements TemplateEntry {
     
    1415
    1516    public Variable(String variableName) {
    16         if (variableName.toLowerCase().startsWith(SPECIAL_VARIABLE_PREFIX)) {
     17        if (variableName.toLowerCase(Locale.ENGLISH).startsWith(SPECIAL_VARIABLE_PREFIX)) {
    1718            this.variableName = variableName.substring(SPECIAL_VARIABLE_PREFIX.length());
    1819            // special:special:key means that real key named special:key is needed, not special variable
    19             this.special = !this.variableName.toLowerCase().startsWith(SPECIAL_VARIABLE_PREFIX);
     20            this.special = !this.variableName.toLowerCase(Locale.ENGLISH).startsWith(SPECIAL_VARIABLE_PREFIX);
    2021        } else {
    2122            this.variableName = variableName;
Note: See TracChangeset for help on using the changeset viewer.