Changeset 1607 in josm for trunk/src/org
- Timestamp:
- 2009-05-20T16:08:00+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r1603 r1607 93 93 @Override public boolean match(OsmPrimitive osm) throws ParseError { 94 94 95 if (regexSearch) { 95 if (regexSearch) { 96 96 if (osm.keys == null) 97 97 return false; … … 106 106 Pattern searchKey = null; 107 107 Pattern searchValue = null; 108 109 if (caseSensitive) { 110 try { 111 searchKey = Pattern.compile(key); 112 } catch (PatternSyntaxException e) { 113 throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage())); 114 } 115 try { 116 searchValue = Pattern.compile(value); 117 } catch (PatternSyntaxException e) { 118 throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage())); 119 } 120 } else { 121 try { 122 searchKey = Pattern.compile(key, Pattern.CASE_INSENSITIVE); 123 } catch (PatternSyntaxException e) { 124 throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage())); 125 } 126 try { 127 searchValue = Pattern.compile(value, Pattern.CASE_INSENSITIVE); 128 } catch (PatternSyntaxException e) { 129 throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage())); 130 } 108 int searchFlags = regexFlags(); 109 110 try { 111 searchKey = Pattern.compile(key, searchFlags); 112 searchValue = Pattern.compile(value, searchFlags); 113 } catch (PatternSyntaxException e) { 114 throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage())); 131 115 } 132 116 … … 183 167 if (regexSearch) { 184 168 search = s; 185 if (caseSensitive) { 186 try { 187 searchRegex = Pattern.compile(search); 188 } catch (PatternSyntaxException e) { 189 throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage())); 190 } 191 } else { 192 try { 193 searchRegex = Pattern.compile(search, Pattern.CASE_INSENSITIVE); 194 } catch (PatternSyntaxException e) { 195 throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage())); 196 } 169 int searchFlags = regexFlags(); 170 171 try { 172 searchRegex = Pattern.compile(search, searchFlags); 173 } catch (PatternSyntaxException e) { 174 throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage())); 197 175 } 198 176 } else { … … 275 253 @Override public String toString() {return "nodes="+count;} 276 254 } 277 255 278 256 private static class NodeCountRange extends Match { 279 257 private int minCount; 280 258 private int maxCount; 281 public NodeCountRange(int minCount, int maxCount) { 259 public NodeCountRange(int minCount, int maxCount) { 282 260 if(maxCount < minCount) { 283 261 this.minCount = maxCount; … … 323 301 @Override public String toString() {return "untagged";} 324 302 } 325 303 326 304 private static class Parent extends Match { 327 305 private Match child; … … 334 312 if (child == null) 335 313 child = new Always(); 336 314 337 315 if (osm instanceof Way) { 338 316 for (Node n : ((Way)osm).nodes) … … 474 452 return new NodeCount(Integer.parseInt(value)); 475 453 } catch(Exception x) {} 476 454 477 455 try { 478 456 String[] range = value.split("-", 2); 479 457 return new NodeCountRange(Integer.parseInt(range[0]), Integer.parseInt(range[1])); 480 458 } catch(Exception x) {} 481 459 482 460 return new NodeCount(0); 483 461 } else if (key.equals("id")) { … … 491 469 } 492 470 } 471 472 private int regexFlags() { 473 int searchFlags = 0; 474 475 // Enables canonical Unicode equivalence so that e.g. the two 476 // forms of "\u00e9gal" and "e\u0301gal" will match. 477 // 478 // It makes sense to match no matter how the character 479 // happened to be constructed. 480 searchFlags |= Pattern.CANON_EQ; 481 482 // Make "." match any character including newline (/s in Perl) 483 searchFlags |= Pattern.DOTALL; 484 485 // CASE_INSENSITIVE by itself only matches US-ASCII case 486 // insensitively, but the OSM data is in Unicode. With 487 // UNICODE_CASE casefolding is made Unicode-aware. 488 if (!caseSensitive) 489 searchFlags |= (Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); 490 491 return searchFlags; 492 } 493 493 }
Note:
See TracChangeset
for help on using the changeset viewer.