1
16
17 import org.as2lib.regexp.AsciiUtil;
18 import org.as2lib.regexp.Pattern;
19 import org.as2lib.regexp.node.Node;
20 import org.as2lib.regexp.node.TreeInfo;
21
22
27
28 class org.as2lib.regexp.node.BitClass extends Node {
29
30 private var bits:Array;
31 private var complementMe:Boolean;
32
33 public function BitClass(flag:Boolean, newBits:Array) {
34 complementMe = (flag != null) ? flag : false;
35 bits = (newBits != null) ? newBits : new Array(256);
36 }
37
38 public function addChar(c:Number, f:Number):Node {
39 if ((f & Pattern.CASE_INSENSITIVE) == 0) {
40 bits[c] = true;
41 return this;
42 }
43 if (c < 128) {
44 bits[c] = true;
45 if (AsciiUtil.isUpper(c)) {
46 c += 0x20;
47 bits[c] = true;
48 } else if (AsciiUtil.isLower(c)) {
49 c -= 0x20;
50 bits[c] = true;
51 }
52 return this;
53 }
54 c = AsciiUtil.toLower(c);
55 bits[c] = true;
56 c = AsciiUtil.toUpper(c);
57 bits[c] = true;
58 return this;
59 }
60
61 public function dup(flag:Boolean):Node {
62 return new BitClass(flag, bits);
63 }
64
65 public function match(matcher:Object, i:Number, seq:String):Boolean {
66 if (i >= matcher.to) return false;
67 var c:Number = seq.charCodeAt(i);
68 var charMatches:Boolean = (c > 255) ?
69 complementMe : Boolean(Number(bits[c]) ^ Number(complementMe));
70 return charMatches && next.match(matcher, i+1, seq);
71 }
72
73 public function study(info:TreeInfo):Boolean {
74 info.minLength++;
75 info.maxLength++;
76 return next.study(info);
77 }
78 }
79