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