Ticket #11498: patch2.diff

File patch2.diff, 1.8 KB (added by mdk, 11 years ago)

patch extension

  • josm/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

     
    420420                    } else if (!tagInPresets) {
    421421                        // try to fix common typos and check again if value is still unknown
    422422                        String fixedValue = prettifyValue(prop.getValue());
    423                         if (values != null && values.contains(fixedValue)) {
     423                        HashMap<String, String> possibleValues = getPossibleValues(values);
     424                        if (possibleValues.containsKey(fixedValue)) {
     425                            fixedValue = possibleValues.get(fixedValue);
    424426                            // misspelled preset value
    425427                            String i = marktr("Value ''{0}'' for key ''{1}'' looks like ''{2}}.");
    426428                            errors.add(new FixableTestError(this, Severity.WARNING, tr("Misspelled property value"),
     
    450452        }
    451453    }
    452454
     455    private HashMap<String, String> getPossibleValues(Set<String> values) {
     456        // generate a map with common typos
     457        HashMap<String, String> map = new HashMap<>();
     458        if (values != null) {
     459            for (String value : values) {
     460                map.put(value, value);
     461                if (value.contains("_")) {
     462                    map.put(value.replace("_", ""), value);
     463                }
     464            }
     465        }
     466        return map;
     467    }
     468
    453469    private static String prettifyValue(String value) {
    454470        // convert to lower case, replace ' ' or '-' with '_'
    455471        value = value.toLowerCase(Locale.ENGLISH).replace('-', '_').replace(' ', '_');