Changeset 6859 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2014-02-17T19:11:05+01:00 (10 years ago)
Author:
simon04
Message:

see #9593 - MapCSS: fix matching of negated regular expressions for missing values

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java

    r6830 r6859  
    66import java.text.MessageFormat;
    77import java.util.EnumSet;
     8import java.util.Set;
    89import java.util.regex.Pattern;
    910
     
    7879        REGEX, NREGEX, ONE_OF, BEGINS_WITH, ENDS_WITH, CONTAINS;
    7980
     81        private static Set<Op> NEGATED_OPS = EnumSet.of(NEQ, NREGEX);
     82
    8083        public boolean eval(String testString, String prototypeString) {
    81             if (testString == null && this != NEQ)
     84            if (testString == null && !NEGATED_OPS.contains(this))
    8285                return false;
    8386            switch (this) {
     
    202205        public boolean applies(Environment env) {
    203206            final String value = env.osm.get(k);
    204             return value != null && (op.equals(Op.REGEX)
    205                     ? pattern.matcher(value).find()
    206                     : !pattern.matcher(value).find());
     207            if (Op.REGEX.equals(op)) {
     208                return value != null && pattern.matcher(value).find();
     209            } else if (Op.NREGEX.equals(op)) {
     210                return value == null || !pattern.matcher(value).find();
     211            } else {
     212                throw new IllegalStateException();
     213            }
    207214        }
    208215    }
Note: See TracChangeset for help on using the changeset viewer.