| 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 | | } |
| | 110 | try { |
| | 111 | searchKey = Pattern.compile(key, searchFlags); |
| | 112 | } catch (PatternSyntaxException e) { |
| | 113 | throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage())); |
| 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 | | } |
| | 174 | int searchFlags = regexFlags(); |
| | 175 | |
| | 176 | try { |
| | 177 | searchRegex = Pattern.compile(search, searchFlags); |
| | 178 | } catch (PatternSyntaxException e) { |
| | 179 | throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage())); |
| | 476 | |
| | 477 | private int regexFlags() { |
| | 478 | int searchFlags = 0; |
| | 479 | |
| | 480 | // Enables canonical Unicode equivalence so that e.g. the two |
| | 481 | // forms of "égal", "\u00e9gal" and "e\u0301gal" will match. |
| | 482 | // |
| | 483 | // I don't know how common this is in the OSM data but it |
| | 484 | // makes sense to match "é" to "é" no matter how the character |
| | 485 | // happened to be constructed. |
| | 486 | searchFlags |= Pattern.CANON_EQ; |
| | 487 | |
| | 488 | // Make "." match any character including newline (/s in Perl) |
| | 489 | searchFlags |= Pattern.DOTALL; |
| | 490 | |
| | 491 | // CASE_INSENSITIVE by itself only matches US-ASCII case |
| | 492 | // insensitively, but the OSM data is in Unicode. With |
| | 493 | // UNICODE_CASE casefolding is made Unicode-aware. |
| | 494 | if (!caseSensitive) |
| | 495 | searchFlags |= (Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); |
| | 496 | |
| | 497 | return searchFlags; |
| | 498 | } |