Changeset 8874 in josm for trunk/src/org
- Timestamp:
- 2015-10-14T22:56:14+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
r8846 r8874 8 8 import java.util.Collection; 9 9 import java.util.EnumSet; 10 import java.util.Map; 10 11 import java.util.Objects; 11 12 import java.util.Set; … … 54 55 default: throw new AssertionError(); 55 56 } 57 } 58 59 public static Condition createRegexpKeyRegexpValueCondition(String k, String v, Op op) { 60 return new RegexpKeyValueRegexpCondition(k, v, op); 56 61 } 57 62 … … 287 292 } 288 293 294 protected boolean matches(Environment env) { 295 final String value = env.osm.get(k); 296 return value != null && pattern.matcher(value).find(); 297 } 298 289 299 @Override 290 300 public boolean applies(Environment env) { 291 final String value = env.osm.get(k);292 301 if (Op.REGEX.equals(op)) { 293 return value != null && pattern.matcher(value).find();302 return matches(env); 294 303 } else if (Op.NREGEX.equals(op)) { 295 return value == null || !pattern.matcher(value).find();304 return !matches(env); 296 305 } else { 297 306 throw new IllegalStateException(); 298 307 } 308 } 309 } 310 311 public static class RegexpKeyValueRegexpCondition extends KeyValueRegexpCondition { 312 313 public final Pattern keyPattern; 314 315 public RegexpKeyValueRegexpCondition(String k, String v, Op op) { 316 super(k, v, op, false); 317 this.keyPattern = Pattern.compile(k); 318 } 319 320 @Override 321 protected boolean matches(Environment env) { 322 for (Map.Entry<String,String> kv: env.osm.getKeys().entrySet()) { 323 if (keyPattern.matcher(kv.getKey()).find() && pattern.matcher(kv.getValue()).find()) { 324 return true; 325 } 326 } 327 return false; 299 328 } 300 329 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
r8822 r8874 755 755 float f; 756 756 int i; 757 Condition.KeyMatchType matchType = null;; 757 758 Condition.Op op; 758 759 boolean considerValAsKey = false; 759 760 } 760 761 { 761 key=tag_key() s() 762 ( 763 key = regex() s() { matchType = Condition.KeyMatchType.REGEX; } 764 | 765 key=tag_key() s() 766 ) 762 767 ( 763 768 LOOKAHEAD(3) … … 807 812 f=float_() { val=Float.toString(f); } 808 813 ) 809 { return Condition.createKeyValueCondition(key, val, op, context, considerValAsKey); } 814 { return Condition.KeyMatchType.REGEX == matchType 815 ? Condition.createRegexpKeyRegexpValueCondition(key, val, op) 816 : Condition.createKeyValueCondition(key, val, op, context, considerValAsKey); } 810 817 } 811 818
Note:
See TracChangeset
for help on using the changeset viewer.