Changeset 5777 in josm for trunk/src/org


Ignore:
Timestamp:
2013-03-13T23:15:17+01:00 (11 years ago)
Author:
Don-vip
Message:

fix #8499 - Over-sensitive directional tag detection

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java

    r5721 r5777  
    3333    private static class PrefixSuffixSwitcher {
    3434
    35         private static final String SEPARATOR = "[:_]?";
     35        private static final String SEPARATOR = "[:_]";
    3636
    3737        private final String a;
    3838        private final String b;
    39         private final Pattern startPattern;
    40         private final Pattern endPattern;
     39        private final Pattern pattern;
    4140
    4241        public PrefixSuffixSwitcher(String a, String b) {
    4342            this.a = a;
    4443            this.b = b;
    45             startPattern = Pattern.compile(
    46                     "^(" + a + "|" + b + ")(" + SEPARATOR + "|$)",
     44            this.pattern = Pattern.compile(
     45                    "(^|.*" + SEPARATOR + ")(" + a + "|" + b + ")(" + SEPARATOR + ".*|$)",
    4746                    Pattern.CASE_INSENSITIVE);
    48             endPattern = Pattern.compile("^.*" +
    49                     SEPARATOR + "(" + a + "|" + b + ")$",
    50                     Pattern.CASE_INSENSITIVE);
    5147        }
    5248
    5349        public String apply(String text) {
    54             Matcher m = startPattern.matcher(text);
    55             if (!m.lookingAt()) {
    56                 m = endPattern.matcher(text);
    57             }
     50            Matcher m = pattern.matcher(text);
    5851
    5952            if (m.lookingAt()) {
    60                 String leftRight = m.group(1).toLowerCase();
     53                String leftRight = m.group(2).toLowerCase();
    6154
    6255                StringBuilder result = new StringBuilder();
    63                 result.append(text.substring(0, m.start(1)));
     56                result.append(text.substring(0, m.start(2)));
    6457                result.append(leftRight.equals(a) ? b : a);
    65                 result.append(text.substring(m.end(1)));
     58                result.append(text.substring(m.end(2)));
    6659
    6760                return result.toString();
Note: See TracChangeset for help on using the changeset viewer.