JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / com / stevesoft / pat / SkipBMH.js
1 Clazz.declarePackage ("com.stevesoft.pat");\r
2 Clazz.load (["com.stevesoft.pat.Skip"], "com.stevesoft.pat.SkipBMH", ["com.stevesoft.pat.CaseMgr", "com.stevesoft.pat.wrap.StringWrap"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.MAX_CHAR = 64;\r
5 this.skip = null;\r
6 this.sm1 = 0;\r
7 this.jump_ahead = 0;\r
8 this.uc = '\0';\r
9 this.lc = '\0';\r
10 this.tc = '\0';\r
11 this.x = '\0';\r
12 Clazz.instantialize (this, arguments);\r
13 }, com.stevesoft.pat, "SkipBMH", com.stevesoft.pat.Skip);\r
14 Clazz.prepareFields (c$, function () {\r
15 this.skip =  Clazz.newCharArray (64, '\0');\r
16 });\r
17 Clazz.defineMethod (c$, "exact", \r
18 function (c) {\r
19 return (this.ign && this.anyc (c)) || c == this.x;\r
20 }, "~S");\r
21 Clazz.defineMethod (c$, "anyc", \r
22 function (c) {\r
23 return c == this.uc || c == this.lc || c == this.tc;\r
24 }, "~S");\r
25 Clazz.makeConstructor (c$, \r
26 function (pt, ign) {\r
27 this.construct (pt, ign, 0);\r
28 }, "~S,~B");\r
29 Clazz.makeConstructor (c$, \r
30 function (pt) {\r
31 this.construct (pt, false, 0);\r
32 }, "~S");\r
33 Clazz.makeConstructor (c$, \r
34 function (pt, ign, offset) {\r
35 Clazz.superConstructor (this, com.stevesoft.pat.SkipBMH, [pt, ign, offset]);\r
36 for (var k = 0; k < 64; k++) {\r
37 this.skip[k] = String.fromCharCode (this.src.length);\r
38 }\r
39 this.sm1 = this.src.length - 1;\r
40 this.x = this.src.charAt (this.sm1);\r
41 this.uc = com.stevesoft.pat.CaseMgr.toUpperCaseC (this.x);\r
42 this.lc = com.stevesoft.pat.CaseMgr.toLowerCaseC (this.x);\r
43 this.tc = com.stevesoft.pat.CaseMgr.toTitleCaseC (this.x);\r
44 for (var k = 0; k < this.src.length - 1; k++) {\r
45 var x_ = this.src.charAt (k);\r
46 if (ign) {\r
47 var uc_ = com.stevesoft.pat.CaseMgr.toUpperCaseC (x_);\r
48 var lc_ = com.stevesoft.pat.CaseMgr.toLowerCaseC (x_);\r
49 var tc_ = com.stevesoft.pat.CaseMgr.toTitleCaseC (x_);\r
50 this.skip[uc_.charCodeAt (0) & (63)] = String.fromCharCode (this.src.length - k - 1);\r
51 this.skip[lc_.charCodeAt (0) & (63)] = String.fromCharCode (this.src.length - k - 1);\r
52 this.skip[tc_.charCodeAt (0) & (63)] = String.fromCharCode (this.src.length - k - 1);\r
53 } else {\r
54 this.skip[x_.charCodeAt (0) & (63)] = String.fromCharCode (this.src.length - k - 1);\r
55 }}\r
56 this.jump_ahead = this.src.length - 1;\r
57 for (var k = 0; k < this.src.length - 1; k++) {\r
58 var y = this.src.charAt (this.sm1 - k - 1);\r
59 if (this.exact (y)) {\r
60 this.jump_ahead = k;\r
61 break;\r
62 }}\r
63 }, "~S,~B,~N");\r
64 Clazz.defineMethod (c$, "searchRegion", \r
65 function (s, start, end) {\r
66 return this.find (s, start, end);\r
67 }, "~S,~N,~N");\r
68 Clazz.defineMethod (c$, "searchFrom", \r
69 function (s, start) {\r
70 return this.find (s, start, s.length);\r
71 }, "~S,~N");\r
72 Clazz.defineMethod (c$, "search", \r
73 function (s) {\r
74 return this.find (s, 0, s.length);\r
75 }, "~S");\r
76 Clazz.defineMethod (c$, "find", \r
77 function (s, start, end) {\r
78 start += this.$offset + this.sm1;\r
79 var vend = com.stevesoft.pat.Skip.min (s.length - 1, end + this.sm1 + this.$offset);\r
80 var k;\r
81 var vend1 = vend - this.jump_ahead;\r
82 if (this.ign) {\r
83 for (k = start; k <= vend1; k += (this.skip[s.charCodeAt (k) & (63)]).charCodeAt (0)) {\r
84 if (this.anyc (s.charAt (k))) {\r
85 if (com.stevesoft.pat.CaseMgr.regionMatches2 (this.src, this.ign, 0, s, k - this.sm1, this.sm1)) {\r
86 return k - this.sm1 - this.$offset;\r
87 }k += this.jump_ahead;\r
88 }}\r
89 for (; k <= vend; k += (this.skip[s.charCodeAt (k) & (63)]).charCodeAt (0)) {\r
90 if (this.anyc (s.charAt (k))) {\r
91 if (com.stevesoft.pat.CaseMgr.regionMatches2 (this.src, this.ign, 0, s, k - this.sm1, this.sm1)) {\r
92 return k - this.sm1 - this.$offset;\r
93 }k += this.jump_ahead;\r
94 if (k > vend) {\r
95 return -1;\r
96 }}}\r
97 } else {\r
98 for (k = start; k <= vend1; k += (this.skip[s.charCodeAt (k) & (63)]).charCodeAt (0)) {\r
99 if (this.x == s.charAt (k)) {\r
100 if (com.stevesoft.pat.CaseMgr.regionMatches2 (this.src, false, 0, s, k - this.sm1, this.sm1)) {\r
101 return k - this.sm1 - this.$offset;\r
102 }k += this.jump_ahead;\r
103 }}\r
104 for (; k <= vend; k += (this.skip[s.charCodeAt (k) & (63)]).charCodeAt (0)) {\r
105 if (this.x == s.charAt (k)) {\r
106 if (com.stevesoft.pat.CaseMgr.regionMatches2 (this.src, false, 0, s, k - this.sm1, this.sm1)) {\r
107 return k - this.sm1 - this.$offset;\r
108 }k += this.jump_ahead;\r
109 if (k > vend) {\r
110 return -1;\r
111 }}}\r
112 }return -1;\r
113 }, "~S,~N,~N");\r
114 Clazz.defineMethod (c$, "find", \r
115 function (s, start, end) {\r
116 if (Clazz.instanceOf (s, com.stevesoft.pat.wrap.StringWrap)) {\r
117 return this.find (s.toString (), start, end);\r
118 }start += this.$offset + this.sm1;\r
119 var vend = com.stevesoft.pat.Skip.min (s.length () - 1, end + this.sm1 + this.$offset);\r
120 var k;\r
121 var vend1 = vend - this.jump_ahead;\r
122 if (this.ign) {\r
123 for (k = start; k <= vend1; k += (this.skip[s.charCodeAt (k) & (63)]).charCodeAt (0)) {\r
124 if (this.anyc (s.charAt (k))) {\r
125 if (com.stevesoft.pat.CaseMgr.regionMatches (this.src, this.ign, 0, s, k - this.sm1, this.sm1)) {\r
126 return k - this.sm1 - this.$offset;\r
127 }k += this.jump_ahead;\r
128 }}\r
129 for (; k <= vend; k += (this.skip[s.charCodeAt (k) & (63)]).charCodeAt (0)) {\r
130 if (this.anyc (s.charAt (k))) {\r
131 if (com.stevesoft.pat.CaseMgr.regionMatches (this.src, this.ign, 0, s, k - this.sm1, this.sm1)) {\r
132 return k - this.sm1 - this.$offset;\r
133 }k += this.jump_ahead;\r
134 if (k > vend) {\r
135 return -1;\r
136 }}}\r
137 } else {\r
138 for (k = start; k <= vend1; k += (this.skip[s.charCodeAt (k) & (63)]).charCodeAt (0)) {\r
139 if (this.x == s.charAt (k)) {\r
140 if (com.stevesoft.pat.CaseMgr.regionMatches (this.src, false, 0, s, k - this.sm1, this.sm1)) {\r
141 return k - this.sm1 - this.$offset;\r
142 }k += this.jump_ahead;\r
143 }}\r
144 for (; k <= vend; k += (this.skip[s.charCodeAt (k) & (63)]).charCodeAt (0)) {\r
145 if (this.x == s.charAt (k)) {\r
146 if (com.stevesoft.pat.CaseMgr.regionMatches (this.src, false, 0, s, k - this.sm1, this.sm1)) {\r
147 return k - this.sm1 - this.$offset;\r
148 }k += this.jump_ahead;\r
149 if (k > vend) {\r
150 return -1;\r
151 }}}\r
152 }return -1;\r
153 }, "com.stevesoft.pat.StringLike,~N,~N");\r
154 });\r