Changeset 16260 in josm for trunk


Ignore:
Timestamp:
2020-04-11T17:37:01+02:00 (5 years ago)
Author:
simon04
Message:

fix #19070 - SearchCompiler: regexp comparison using <tilde>

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/search/PushbackTokenizer.java

    r12656 r16260  
    108108        EQUALS(marktr("<equals>")),
    109109        /**
     110         * The tilde sign (~)
     111         */
     112        TILDE(marktr("<tilde>")),
     113        /**
    110114         * A text
    111115         */
     
    148152    }
    149153
    150     private static final List<Character> SPECIAL_CHARS = Arrays.asList('"', ':', '(', ')', '|', '^', '=', '?', '<', '>');
     154    private static final List<Character> SPECIAL_CHARS = Arrays.asList('"', ':', '(', ')', '|', '^', '=', '~', '?', '<', '>');
    151155    private static final List<Character> SPECIAL_CHARS_QUOTED = Arrays.asList('"');
    152156
     
    200204            getChar();
    201205            return Token.EQUALS;
     206        case '~':
     207            getChar();
     208            return Token.TILDE;
    202209        case '<':
    203210            getChar();
  • trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java

    r16259 r16260  
    21192119            if (tokenizer.readIfEqual(Token.EQUALS)) {
    21202120                return new ExactKeyValue(regexSearch, key, tokenizer.readTextOrNumber());
     2121            } else if (tokenizer.readIfEqual(Token.TILDE)) {
     2122                return new ExactKeyValue(true, key, tokenizer.readTextOrNumber());
    21212123            } else if (tokenizer.readIfEqual(Token.LESS_THAN)) {
    21222124                return new ValueComparison(key, tokenizer.readTextOrNumber(), -1);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SearchDialog.java

    r15292 r16260  
    294294                .addKeyword("<i>key</i>", null, tr("matches if ''key'' exists"))
    295295                .addKeyword("<i>key</i>=<i>value</i>", null, tr("''key'' with exactly ''value''"))
     296                .addKeyword("<i>key</i>~<i>regexp</i>", null, tr("value of ''key'' matching the regular expression ''regexp''"))
    296297                .addKeyword("<i>key</i>=*", null, tr("''key'' with any value"))
    297298                .addKeyword("<i>key</i>=", null, tr("''key'' with empty value"))
  • trunk/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java

    r14561 r16260  
    142142
    143143    /**
     144     * Search by regular expression: key~value.
     145     * @throws SearchParseError if an error has been encountered while compiling
     146     */
     147    @Test
     148    public void testRegexp() throws SearchParseError {
     149        final SearchCompiler.Match c = SearchCompiler.compile("foo~[Bb]a[rz]");
     150        assertFalse(c.match(newPrimitive("foobar", "true")));
     151        assertFalse(c.match(newPrimitive("foo", "foo")));
     152        assertTrue(c.match(newPrimitive("foo", "bar")));
     153        assertTrue(c.match(newPrimitive("foo", "baz")));
     154        assertTrue(c.match(newPrimitive("foo", "Baz")));
     155        assertEquals("foo=[Bb]a[rz]", c.toString());
     156    }
     157
     158    /**
    144159     * Search by comparison.
    145160     * @throws SearchParseError if an error has been encountered while compiling
Note: See TracChangeset for help on using the changeset viewer.