1 package net.systemeD.halcyon.styleparser {
3 /** A single tag test that forms part of a MapCSS selector.
4 For example, "highway==primary" or "population>1000".
5 Conditions are grouped in Rules.
7 @see net.systemeD.halcyon.styleparser.Rule */
9 public class Condition {
10 public var type:String;
11 public var params:Array;
13 /** Create a new Condition. <p>
16 eq,'highway','trunk' - simple equality test </p><p>
17 ne,'highway','trunk' - not equals </p><p>
18 regex,'highway','trunk.+' - regular expression </p><p>
19 true,'bridge' - value is true/yes/1 </p><p>
20 untrue,'bridge' - value is not true/yes/1 </p><p>
21 set,'highway' - tag exists and is not '' </p><p>
22 unset,'highway' - tag does not exist, or is '' </p><p>
23 <,'population','5000' - numeric comparison (also <=, >, >=) </p>
26 public function Condition(type:String='', ...params) {
27 this.type=type; this.params=params;
30 /** Test a tag hash against the Condition. */
32 public function test(tags:Object):Boolean {
34 case 'eq': return (tags[params[0]]==params[1]); break;
35 case 'ne': return (tags[params[0]]!=params[1]); break;
36 case 'regex': var r:RegExp=new RegExp(params[1],"i");
37 return (r.test(tags[params[0]])); break;
38 case 'true': return (tags[params[0]]=='true' || tags[params[0]]=='yes' || tags[params[0]]=='1'); break;
39 case 'false': return (tags[params[0]]=='false' || tags[params[0]]=='no' || tags[params[0]]=='0'); break;
40 case 'set': return (tags[params[0]]!=undefined && tags[params[0]]!=''); break;
41 case 'unset': return (tags[params[0]]==undefined || tags[params[0]]==''); break;
42 case '<': return (Number(tags[params[0]])< Number(params[1])); break;
43 case '<=': return (Number(tags[params[0]])<=Number(params[1])); break;
44 case '>': return (Number(tags[params[0]])> Number(params[1])); break;
45 case '>=': return (Number(tags[params[0]])>=Number(params[1])); break;
50 public function toString():String {
51 return "Condition("+type+":"+params+")";