Changeset 5777 in josm
- Timestamp:
- 2013-03-13T23:15:17+01:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java
r5721 r5777 33 33 private static class PrefixSuffixSwitcher { 34 34 35 private static final String SEPARATOR = "[:_] ?";35 private static final String SEPARATOR = "[:_]"; 36 36 37 37 private final String a; 38 38 private final String b; 39 private final Pattern startPattern; 40 private final Pattern endPattern; 39 private final Pattern pattern; 41 40 42 41 public PrefixSuffixSwitcher(String a, String b) { 43 42 this.a = a; 44 43 this.b = b; 45 startPattern = Pattern.compile(46 " ^(" + a + "|" + b + ")(" + SEPARATOR + "|$)",44 this.pattern = Pattern.compile( 45 "(^|.*" + SEPARATOR + ")(" + a + "|" + b + ")(" + SEPARATOR + ".*|$)", 47 46 Pattern.CASE_INSENSITIVE); 48 endPattern = Pattern.compile("^.*" +49 SEPARATOR + "(" + a + "|" + b + ")$",50 Pattern.CASE_INSENSITIVE);51 47 } 52 48 53 49 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); 58 51 59 52 if (m.lookingAt()) { 60 String leftRight = m.group( 1).toLowerCase();53 String leftRight = m.group(2).toLowerCase(); 61 54 62 55 StringBuilder result = new StringBuilder(); 63 result.append(text.substring(0, m.start( 1)));56 result.append(text.substring(0, m.start(2))); 64 57 result.append(leftRight.equals(a) ? b : a); 65 result.append(text.substring(m.end( 1)));58 result.append(text.substring(m.end(2))); 66 59 67 60 return result.toString();
Note:
See TracChangeset
for help on using the changeset viewer.