- Timestamp:
- 2013-12-27T16:14:28+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
r6538 r6547 6 6 import java.text.MessageFormat; 7 7 import java.util.EnumSet; 8 import java.util.regex.Matcher;9 8 import java.util.regex.Pattern; 10 9 … … 16 15 import org.openstreetmap.josm.gui.mappaint.Cascade; 17 16 import org.openstreetmap.josm.gui.mappaint.Environment; 17 import org.openstreetmap.josm.tools.Predicates; 18 18 import org.openstreetmap.josm.tools.Utils; 19 19 … … 39 39 } 40 40 41 public static Condition create(String k, boolean not, boolean yes, boolean no, Context context) {41 public static Condition create(String k, boolean not, KeyMatchType matchType, Context context) { 42 42 switch (context) { 43 43 case PRIMITIVE: 44 return new KeyCondition(k, not, yes, no);44 return new KeyCondition(k, not, matchType); 45 45 case LINK: 46 if ( yes || no)47 throw new MapCSSException("Question mark operator ''?'' not supported in LINK context"); 46 if (matchType != null) 47 throw new MapCSSException("Question mark operator ''?'' and regexp match not supported in LINK context"); 48 48 if (not) 49 49 return new RoleCondition(k, Op.NEQ); … … 77 77 case REGEX: 78 78 case NREGEX: 79 Pattern p = Pattern.compile(prototypeString); 80 Matcher m = p.matcher(testString); 81 return REGEX.equals(this) ? m.find() : !m.find(); 79 final boolean contains = Pattern.compile(prototypeString).matcher(testString).find(); 80 return REGEX.equals(this) ? contains : !contains; 82 81 case ONE_OF: 83 82 String[] parts = testString.split(";"); … … 142 141 public static class KeyValueCondition extends Condition { 143 142 144 public String k; 145 public String v; 146 public Op op; 143 public final String k; 144 public final String v; 145 public final Op op; 147 146 148 147 /** … … 175 174 176 175 public static class RoleCondition extends Condition { 177 public String role; 178 public Op op; 176 public final String role; 177 public final Op op; 179 178 180 179 public RoleCondition(String role, Op op) { … … 192 191 193 192 public static class IndexCondition extends Condition { 194 public String index; 195 public Op op; 193 public final String index; 194 public final Op op; 196 195 197 196 public IndexCondition(String index, Op op) { … … 205 204 return op.eval(Integer.toString(env.index + 1), index); 206 205 } 206 } 207 208 public static enum KeyMatchType { 209 EQ, TRUE, FALSE, REGEX 207 210 } 208 211 … … 228 231 public static class KeyCondition extends Condition { 229 232 230 private String label; 231 private boolean negateResult; 232 private boolean testForTrueValues; 233 private boolean testForFalseValues; 234 235 public KeyCondition(String label, boolean negateResult, boolean testForTrueValues, boolean testForFalseValues){ 233 public final String label; 234 public final boolean negateResult; 235 public final KeyMatchType matchType; 236 237 public KeyCondition(String label, boolean negateResult, KeyMatchType matchType){ 236 238 this.label = label; 237 239 this.negateResult = negateResult; 238 this.testForTrueValues = testForTrueValues; 239 this.testForFalseValues = testForFalseValues; 240 this.matchType = matchType; 240 241 } 241 242 … … 244 245 switch(e.getContext()) { 245 246 case PRIMITIVE: 246 if ( testForTrueValues)247 if (KeyMatchType.TRUE.equals(matchType)) 247 248 return OsmUtils.isTrue(e.osm.get(label)) ^ negateResult; 248 else if ( testForFalseValues)249 else if (KeyMatchType.FALSE.equals(matchType)) 249 250 return OsmUtils.isFalse(e.osm.get(label)) ^ negateResult; 251 else if (KeyMatchType.REGEX.equals(matchType)) 252 return Utils.exists(e.osm.keySet(), Predicates.stringContainsPattern(Pattern.compile(label))) ^ negateResult; 250 253 else 251 254 return e.osm.hasKey(label) ^ negateResult; … … 269 272 public static class PseudoClassCondition extends Condition { 270 273 271 String id; 272 boolean not; 274 public final String id; 275 public final boolean not; 273 276 274 277 public PseudoClassCondition(String id, boolean not) { -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
r6532 r6547 345 345 { 346 346 boolean not = false; 347 boolean yes = false; 348 boolean no = false; 347 Condition.KeyMatchType matchType = null;; 349 348 String key; 350 349 } 351 350 { 352 351 ( <EXCLAMATION> { not = true; } )? 353 key=tag_key() 354 ( LOOKAHEAD(2) <QUESTION> <EXCLAMATION> { no = true; } )? 355 ( <QUESTION> { yes = true; } )? 356 { return Condition.create(key, not, yes, no, context); } 352 ( 353 { matchType = Condition.KeyMatchType.REGEX; } key = regex() 354 | 355 key = tag_key() 356 ) 357 ( LOOKAHEAD(2) <QUESTION> <EXCLAMATION> { matchType = Condition.KeyMatchType.FALSE; } )? 358 ( <QUESTION> { matchType = Condition.KeyMatchType.TRUE; } )? 359 { return Condition.create(key, not, matchType, context); } 357 360 } 358 361
Note:
See TracChangeset
for help on using the changeset viewer.