JAL-1807 test
[jalviewjs.git] / bin / com / stevesoft / pat / Skip.js
1 Clazz.declarePackage ("com.stevesoft.pat");
2 Clazz.load (null, "com.stevesoft.pat.Skip", ["com.stevesoft.pat.CaseMgr", "$.Or", "$.Skipped", "$.oneChar", "java.lang.StringBuffer"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.src = null;
5 this.c = 0;
6 this.mask = 0;
7 this.$offset = 0;
8 this.ign = false;
9 this.m1 = false;
10 Clazz.instantialize (this, arguments);
11 }, com.stevesoft.pat, "Skip");
12 c$.mkmask = Clazz.defineMethod (c$, "mkmask", 
13 function (c) {
14 var x = String.fromCharCode (c);
15 return ~((com.stevesoft.pat.CaseMgr.toUpperCaseC (x)).charCodeAt (0) | (com.stevesoft.pat.CaseMgr.toLowerCaseC (x)).charCodeAt (0) | (com.stevesoft.pat.CaseMgr.toTitleCaseC (x)).charCodeAt (0));
16 }, "~N");
17 c$.string = Clazz.defineMethod (c$, "string", 
18 function (r) {
19 return r.skipper == null ? null : r.skipper.src;
20 }, "com.stevesoft.pat.Regex");
21 c$.offset = Clazz.defineMethod (c$, "offset", 
22 function (r) {
23 return r.skipper == null ? -1 : r.skipper.$offset;
24 }, "com.stevesoft.pat.Regex");
25 Clazz.makeConstructor (c$, 
26 function (s, ign, o) {
27 this.src = s;
28 this.c = s.charCodeAt (0);
29 if (ign) {
30 this.mask = com.stevesoft.pat.Skip.mkmask (this.c);
31 } else {
32 this.mask = 0;
33 }this.$offset = o;
34 this.ign = ign;
35 this.m1 = (s.length == 1);
36 }, "~S,~B,~N");
37 Clazz.defineMethod (c$, "find", 
38 function (s) {
39 return this.find (s, 0, s.length ());
40 }, "com.stevesoft.pat.StringLike");
41 c$.min = Clazz.defineMethod (c$, "min", 
42 function (a, b) {
43 return a < b ? a : b;
44 }, "~N,~N");
45 Clazz.defineMethod (c$, "find", 
46 function (s, start, end) {
47 if (start > end) {
48 return -1;
49 }start += this.$offset;
50 var vend = com.stevesoft.pat.Skip.min (s.length () - 1, end + this.$offset);
51 if (this.mask != this.c) {
52 for (var i = start; i <= vend; i++) {
53 if (0 == (s.charCodeAt (i) & this.mask)) {
54 if (this.m1 || com.stevesoft.pat.CaseMgr.regionMatchesLike2 (s, this.ign, i, this.src, 0, this.src.length)) {
55 return i - this.$offset;
56 }}}
57 } else {
58 for (var i = start; i <= vend; i++) {
59 if (this.c == s.charCodeAt (i)) {
60 if (this.m1 || com.stevesoft.pat.CaseMgr.regionMatchesLike2 (s, this.ign, i, this.src, 0, this.src.length)) {
61 return i - this.$offset;
62 }}}
63 }return -1;
64 }, "com.stevesoft.pat.StringLike,~N,~N");
65 c$.findSkipRegex = Clazz.defineMethod (c$, "findSkipRegex", 
66 function (r) {
67 return com.stevesoft.pat.Skip.findSkip (r.thePattern, r.ignoreCase, !r.dontMatchInQuotes);
68 }, "com.stevesoft.pat.Regex");
69 c$.findSkip = Clazz.defineMethod (c$, "findSkip", 
70 function (p, ignoreCase, trnc) {
71 var sb =  new StringBuffer ();
72 var subsk = null;
73 var offset = 0;
74 var skipc = -1;
75 var skipoff = 0;
76 for (; p != null; p = p.next) {
77 if (Clazz.instanceOf (p, com.stevesoft.pat.oneChar)) {
78 skipc = ((p).c).charCodeAt (0);
79 skipoff = offset;
80 }if (Clazz.instanceOf (p, com.stevesoft.pat.oneChar) && Clazz.instanceOf (p.next, com.stevesoft.pat.oneChar)) {
81 var psav = p;
82 sb.append ((p).c);
83 while (Clazz.instanceOf (p.next, com.stevesoft.pat.oneChar)) {
84 sb.append ((p.next).c);
85 p = p.next;
86 }
87 var st = sb.toString ();
88 var sk = null;
89 if (st.length > 2) {
90 sk =  new com.stevesoft.pat.SkipBMH (st, ignoreCase, offset);
91 } else {
92 sk =  new com.stevesoft.pat.Skip2 (st, ignoreCase, offset);
93 }if (trnc && st.length > 2) {
94 psav.next =  new com.stevesoft.pat.Skipped (st.substring (1));
95 psav.next.next = p.next;
96 psav.next.parent = p.parent;
97 }return sk;
98 } else if (Clazz.instanceOf (p, com.stevesoft.pat.Or) && (p).v.size () == 1 && !(p).leftForm ().equals ("(?!") && null != (subsk = com.stevesoft.pat.Skip.findSkip ((p).v.elementAt (0), ignoreCase, trnc))) {
99 subsk.$offset += offset;
100 return subsk;
101 } else if (p.minChars ().equals (p.maxChars ())) {
102 offset += p.minChars ().intValue ();
103 } else {
104 return skipc < 0 ? null :  new com.stevesoft.pat.Skip ("" + String.fromCharCode (skipc), ignoreCase, skipoff);
105 }}
106 return null;
107 }, "com.stevesoft.pat.Pattern,~B,~B");
108 });