JAL-1807 test
[jalviewjs.git] / bin / com / stevesoft / pat / FastMulti.js
1 Clazz.declarePackage ("com.stevesoft.pat");
2 Clazz.load (["com.stevesoft.pat.PatternSub"], "com.stevesoft.pat.FastMulti", ["com.stevesoft.pat.RegSyntaxError", "$.patInt"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.fewestMatches = null;
5 this.mostMatches = null;
6 this.matchFewest = false;
7 this.step = -1;
8 Clazz.instantialize (this, arguments);
9 }, com.stevesoft.pat, "FastMulti", com.stevesoft.pat.PatternSub);
10 Clazz.overrideMethod (c$, "minChars", 
11 function () {
12 return this.sub.countMinChars ().mul (this.fewestMatches);
13 });
14 Clazz.overrideMethod (c$, "maxChars", 
15 function () {
16 return this.sub.countMaxChars ().mul (this.mostMatches);
17 });
18 Clazz.makeConstructor (c$, 
19 function (a, b, p) {
20 Clazz.superConstructor (this, com.stevesoft.pat.FastMulti, []);
21 if (p == null) {
22 com.stevesoft.pat.RegSyntaxError.endItAll ("Null length pattern followed by *, +, or other Multi.");
23 }this.fewestMatches = a;
24 this.mostMatches = b;
25 this.sub = p;
26 this.step = p.countMinChars ().intValue ();
27 this.sub.setParent (null);
28 }, "com.stevesoft.pat.patInt,com.stevesoft.pat.patInt,com.stevesoft.pat.Pattern");
29 Clazz.defineMethod (c$, "toString", 
30 function () {
31 return this.sub.toString () + "{" + this.fewestMatches + "," + this.mostMatches + "}" + (this.matchFewest ? "?" : "") + "(?# <= fast multi)" + this.nextString ();
32 });
33 Clazz.defineMethod (c$, "matchInternal", 
34 function (pos, pt) {
35 var m = -1;
36 var i = pos;
37 var endstr = pt.src.length () - this.step;
38 var matches =  new com.stevesoft.pat.patInt (0);
39 if (this.matchFewest) {
40 if (this.fewestMatches.lessEq (matches)) {
41 var ii = this.nextMatch (i, pt);
42 if (ii >= 0) {
43 return ii;
44 }}while (i >= 0 && i <= endstr) {
45 i = this.sub.matchInternal (i, pt);
46 if (i >= 0) {
47 matches.inc ();
48 if (this.fewestMatches.lessEq (matches)) {
49 var ii = this.nextMatch (i, pt);
50 if (ii >= 0) {
51 return ii;
52 }}if (matches.equals (this.mostMatches)) {
53 return -1;
54 }}}
55 return -1;
56 }var nMatches = 0;
57 while (this.fewestMatches.intValue () > nMatches) {
58 i = this.sub.matchInternal (i, pt);
59 if (i >= 0) {
60 nMatches++;
61 } else {
62 return -1;
63 }}
64 m = i;
65 if (this.mostMatches.finite ()) {
66 while (nMatches < this.mostMatches.intValue ()) {
67 i = this.sub.matchInternal (i, pt);
68 if (i >= 0) {
69 m = i;
70 nMatches++;
71 } else {
72 break;
73 }}
74 } else {
75 while (true) {
76 i = this.sub.matchInternal (i, pt);
77 if (i >= 0) {
78 m = i;
79 nMatches++;
80 } else {
81 break;
82 }}
83 }while (m >= pos) {
84 var r = this.nextMatch (m, pt);
85 if (r >= 0) {
86 return r;
87 }m -= this.step;
88 nMatches--;
89 if (nMatches < this.fewestMatches.intValue ()) {
90 return -1;
91 }}
92 return -1;
93 }, "~N,com.stevesoft.pat.Pthings");
94 Clazz.overrideMethod (c$, "clone1", 
95 function (h) {
96 try {
97 var fm =  new com.stevesoft.pat.FastMulti (this.fewestMatches, this.mostMatches, this.sub.clone (h));
98 fm.matchFewest = this.matchFewest;
99 return fm;
100 } catch (rs) {
101 if (Clazz.exceptionOf (rs, com.stevesoft.pat.RegSyntax)) {
102 return null;
103 } else {
104 throw rs;
105 }
106 }
107 }, "java.util.Hashtable");
108 });