JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / bin / com / stevesoft / pat / FastBracket.js
1 Clazz.declarePackage ("com.stevesoft.pat");\r
2 Clazz.load (["com.stevesoft.pat.Bracket"], "com.stevesoft.pat.FastBracket", ["com.stevesoft.pat.Range", "$.oneChar", "java.util.BitSet", "$.Vector"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.$min = 0;\r
5 this.$max = 0;\r
6 this.bs = null;\r
7 Clazz.instantialize (this, arguments);\r
8 }, com.stevesoft.pat, "FastBracket", com.stevesoft.pat.Bracket);\r
9 c$.process = Clazz.defineMethod (c$, "process", \r
10 function (b, ignc) {\r
11 var v = b.v;\r
12 b.pv = null;\r
13 try {\r
14 var nv = v;\r
15 if (ignc) {\r
16 nv =  new java.util.Vector ();\r
17 for (var i = 0; i < v.size (); i++) {\r
18 var p = v.elementAt (i);\r
19 nv.addElement (p);\r
20 if (Clazz.instanceOf (p, com.stevesoft.pat.oneChar)) {\r
21 var oc = p;\r
22 nv.addElement ( new com.stevesoft.pat.oneChar (oc.altc));\r
23 } else if (Clazz.instanceOf (p, com.stevesoft.pat.Range)) {\r
24 var ra = p;\r
25 nv.addElement ( new com.stevesoft.pat.Range (ra.altlo, ra.althi));\r
26 }}\r
27 }v = nv;\r
28 for (var i = 0; i < v.size () - 1; i++) {\r
29 for (var j = 0; j < v.size () - 1; j++) {\r
30 var c1 = com.stevesoft.pat.FastBracket.getl (v.elementAt (j));\r
31 var c2 = com.stevesoft.pat.FastBracket.getl (v.elementAt (j + 1));\r
32 if (c2 < c1) {\r
33 var o = v.elementAt (j);\r
34 v.setElementAt (v.elementAt (j + 1), j);\r
35 v.setElementAt (o, j + 1);\r
36 }}\r
37 }\r
38 nv =  new java.util.Vector ();\r
39 var p = v.elementAt (0);\r
40 nv.addElement (p);\r
41 for (var i = 1; i < v.size (); i++) {\r
42 if ((com.stevesoft.pat.FastBracket.geth (p)).charCodeAt (0) + 1 >= (com.stevesoft.pat.FastBracket.getl (v.elementAt (i))).charCodeAt (0)) {\r
43 var p2 = v.elementAt (i);\r
44 var lo = com.stevesoft.pat.FastBracket.min (com.stevesoft.pat.FastBracket.getl (p), com.stevesoft.pat.FastBracket.getl (p2));\r
45 var hi = com.stevesoft.pat.FastBracket.max (com.stevesoft.pat.FastBracket.geth (p), com.stevesoft.pat.FastBracket.geth (p2));\r
46 nv.setElementAt (p = com.stevesoft.pat.FastBracket.mkelem (lo, hi), nv.size () - 1);\r
47 } else {\r
48 p = v.elementAt (i);\r
49 nv.addElement (p);\r
50 }}\r
51 b.v = v = nv;\r
52 } catch (e) {\r
53 if (Clazz.exceptionOf (e, com.stevesoft.pat.RegSyntax)) {\r
54 e.printStackTrace ();\r
55 } else {\r
56 throw e;\r
57 }\r
58 }\r
59 var negv = com.stevesoft.pat.FastBracket.neg (v);\r
60 if (v.size () == 1) {\r
61 return b;\r
62 }if (negv.size () == 1) {\r
63 b.v = negv;\r
64 b.neg = !b.neg;\r
65 return b;\r
66 }var fb = com.stevesoft.pat.FastBracket.newbrack (v, b.neg);\r
67 if (fb == null) {\r
68 fb = com.stevesoft.pat.FastBracket.newbrack (negv, !b.neg);\r
69 }if (fb != null) {\r
70 fb.parent = b.parent;\r
71 fb.next = b.next;\r
72 return fb;\r
73 }return b;\r
74 }, "com.stevesoft.pat.Bracket,~B");\r
75 c$.newbrack = Clazz.defineMethod (c$, "newbrack", \r
76 function (v, neg) {\r
77 var fb =  new com.stevesoft.pat.FastBracket (neg);\r
78 fb.v = v;\r
79 if (v.size () == 0) {\r
80 return null;\r
81 }fb.$min = (com.stevesoft.pat.FastBracket.getl (v.elementAt (0))).charCodeAt (0);\r
82 fb.$max = (com.stevesoft.pat.FastBracket.geth (v.elementAt (v.size () - 1))).charCodeAt (0);\r
83 if (fb.$max - fb.$min <= 256) {\r
84 fb.bs =  new java.util.BitSet (fb.$max - fb.$min + 1);\r
85 for (var i = 0; i < v.size (); i++) {\r
86 var o = v.elementAt (i);\r
87 var min0 = (com.stevesoft.pat.FastBracket.getl (o)).charCodeAt (0) - fb.$min;\r
88 var max0 = (com.stevesoft.pat.FastBracket.geth (o)).charCodeAt (0) - fb.$min;\r
89 for (var j = min0; j <= max0; j++) {\r
90 fb.bs.set (j);\r
91 }\r
92 }\r
93 return fb;\r
94 }return null;\r
95 }, "java.util.Vector,~B");\r
96 c$.neg = Clazz.defineMethod (c$, "neg", \r
97 function (v) {\r
98 try {\r
99 var nv =  new java.util.Vector ();\r
100 if (v.size () == 0) {\r
101 nv.addElement ( new com.stevesoft.pat.Range (String.fromCharCode (0), String.fromCharCode (65535)));\r
102 return nv;\r
103 }var p0 = (com.stevesoft.pat.FastBracket.getl (v.elementAt (0))).charCodeAt (0);\r
104 if (p0 != 0) {\r
105 nv.addElement (com.stevesoft.pat.FastBracket.mkelem (String.fromCharCode (0), String.fromCharCode (p0 - 1)));\r
106 }for (var i = 0; i < v.size () - 1; i++) {\r
107 var hi = (com.stevesoft.pat.FastBracket.getl (v.elementAt (i + 1))).charCodeAt (0) - 1;\r
108 var lo = (com.stevesoft.pat.FastBracket.geth (v.elementAt (i))).charCodeAt (0) + 1;\r
109 nv.addElement (com.stevesoft.pat.FastBracket.mkelem (String.fromCharCode (lo), String.fromCharCode (hi)));\r
110 }\r
111 var pN = (com.stevesoft.pat.FastBracket.geth (v.lastElement ())).charCodeAt (0);\r
112 if (pN != 65535) {\r
113 nv.addElement (com.stevesoft.pat.FastBracket.mkelem (String.fromCharCode (pN + 1), String.fromCharCode (65535)));\r
114 }return nv;\r
115 } catch (rs) {\r
116 if (Clazz.exceptionOf (rs, com.stevesoft.pat.RegSyntax)) {\r
117 return null;\r
118 } else {\r
119 throw rs;\r
120 }\r
121 }\r
122 }, "java.util.Vector");\r
123 c$.mkelem = Clazz.defineMethod (c$, "mkelem", \r
124 function (lo, hi) {\r
125 return lo == hi ? ( new com.stevesoft.pat.oneChar (lo)) : ( new com.stevesoft.pat.Range (lo, hi));\r
126 }, "~S,~S");\r
127 c$.min = Clazz.defineMethod (c$, "min", \r
128 function (a, b) {\r
129 return a < b ? a : b;\r
130 }, "~S,~S");\r
131 c$.max = Clazz.defineMethod (c$, "max", \r
132 function (a, b) {\r
133 return a > b ? a : b;\r
134 }, "~S,~S");\r
135 c$.getl = Clazz.defineMethod (c$, "getl", \r
136 function (o) {\r
137 var p = o;\r
138 if (Clazz.instanceOf (p, com.stevesoft.pat.Range)) {\r
139 return (p).lo;\r
140 }return (p).c;\r
141 }, "~O");\r
142 c$.geth = Clazz.defineMethod (c$, "geth", \r
143 function (o) {\r
144 var p = o;\r
145 if (Clazz.instanceOf (p, com.stevesoft.pat.Range)) {\r
146 return (p).hi;\r
147 }return (p).c;\r
148 }, "~O");\r
149 Clazz.overrideMethod (c$, "matchInternal", \r
150 function (pos, pt) {\r
151 if (pos >= pt.src.length () || this.Masked (pos, pt)) {\r
152 return -1;\r
153 }var c = pt.src.charAt (pos);\r
154 return ( new Boolean (this.neg ^ (c.charCodeAt (0) >= this.$min && c.charCodeAt (0) <= this.$max && this.bs.get (c.charCodeAt (0) - this.$min))).valueOf ()) ? this.nextMatch (pos + 1, pt) : -1;\r
155 }, "~N,com.stevesoft.pat.Pthings");\r
156 });\r