Changeset 17746 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java
r17585 r17746 898 898 * Constructs a new {@code ExactKeyValue}. 899 899 * @param regexp regular expression 900 * @param caseSensitive {@code true} to perform a case-sensitive search 900 901 * @param key key 901 902 * @param value value 902 903 * @throws SearchParseError if a parse error occurs 903 904 */ 904 public ExactKeyValue(boolean regexp, String key, String value) throws SearchParseError { 905 public ExactKeyValue(boolean regexp, boolean caseSensitive, String key, String value) throws SearchParseError { 905 906 if ("".equals(key)) 906 907 throw new SearchParseError(tr("Key cannot be empty when tag operator is used. Sample use: key=value")); … … 938 939 939 940 if (regexp && !key.isEmpty() && !"*".equals(key)) { 940 keyPattern = compilePattern(key, regexFlags( false));941 keyPattern = compilePattern(key, regexFlags(caseSensitive)); 941 942 } else { 942 943 keyPattern = null; 943 944 } 944 945 if (regexp && !this.value.isEmpty() && !"*".equals(this.value)) { 945 valuePattern = compilePattern(this.value, regexFlags( false));946 valuePattern = compilePattern(this.value, regexFlags(caseSensitive)); 946 947 } else { 947 948 valuePattern = null; … … 2102 2103 String key = tokenizer.getText(); 2103 2104 if (tokenizer.readIfEqual(Token.EQUALS)) { 2104 return new ExactKeyValue(regexSearch, key, tokenizer.readTextOrNumber()); 2105 return new ExactKeyValue(regexSearch, caseSensitive, key, tokenizer.readTextOrNumber()); 2105 2106 } else if (tokenizer.readIfEqual(Token.TILDE)) { 2106 return new ExactKeyValue(true, key, tokenizer.readTextOrNumber()); 2107 return new ExactKeyValue(true, caseSensitive, key, tokenizer.readTextOrNumber()); 2107 2108 } else if (tokenizer.readIfEqual(Token.LESS_THAN)) { 2108 2109 return new ValueComparison(key, tokenizer.readTextOrNumber(), -1); -
trunk/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java
r17277 r17746 147 147 148 148 /** 149 * Search by case-sensitive regular expression. 150 * @throws SearchParseError if an error has been encountered while compiling 151 */ 152 @Test 153 void testRegexpCaseSensitive() throws Exception { 154 SearchSetting searchSetting = new SearchSetting(); 155 searchSetting.regexSearch = true; 156 searchSetting.text = "foo=\"^bar$\""; 157 assertTrue(SearchCompiler.compile(searchSetting).match(OsmUtils.createPrimitive("node foo=bar"))); 158 assertTrue(SearchCompiler.compile(searchSetting).match(OsmUtils.createPrimitive("node foo=BAR"))); 159 searchSetting.caseSensitive = true; 160 assertTrue(SearchCompiler.compile(searchSetting).match(OsmUtils.createPrimitive("node foo=bar"))); 161 assertFalse(SearchCompiler.compile(searchSetting).match(OsmUtils.createPrimitive("node foo=BAR"))); 162 } 163 164 /** 149 165 * Search by comparison. 150 166 * @throws SearchParseError if an error has been encountered while compiling
Note:
See TracChangeset
for help on using the changeset viewer.