Ticket #17837: 17837.patch

File 17837.patch, 1.8 KB (added by GerdP, 5 years ago)

Patch to make sure that two entries have the same error code, so that "120" is not treated as group for an entry starting with "1201_Key ". There is probably a simpler way to express this with regex patterns, but I couldn't find one.

  • src/org/openstreetmap/josm/data/validation/OsmValidator.java

     
    267267            List<String> toRemove = new ArrayList<>();
    268268
    269269            Iterator<Entry<String, String>> iter = ignoredErrors.entrySet().iterator();
    270             Entry<String, String> last = iter.next();
     270            String lastKey = iter.next().getKey();
    271271            while (iter.hasNext()) {
    272                 Entry<String, String> entry = iter.next();
    273                 if (entry.getKey().startsWith(last.getKey())) {
    274                     toRemove.add(entry.getKey());
     272                String currKey = iter.next().getKey();
     273                if (currKey.startsWith(lastKey) && sameCode(currKey, lastKey)) {
     274                    toRemove.add(currKey);
    275275                } else {
    276                     last = entry;
     276                    lastKey = currKey;
    277277                }
    278278            }
    279279            toRemove.forEach(ignoredErrors::remove);
     
    286286        }
    287287    }
    288288
     289    private static boolean sameCode(String key1, String key2) {
     290        return extractCodeFromIgnoreKey(key1).equals(extractCodeFromIgnoreKey(key2));
     291    }
     292
     293    private static String extractCodeFromIgnoreKey(String key) {
     294        int lenCode = 0;
     295
     296        for (int i = 0; i < key.length(); i++) {
     297            if (key.charAt(i) >= '0' && key.charAt(i) <= '9') {
     298                lenCode++;
     299            } else {
     300                break;
     301            }
     302        }
     303        return key.substring(0, lenCode);
     304    }
     305
    289306    /**
    290307     * Check if a error should be ignored
    291308     * @param s The ignore group / sub group name