JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / com / stevesoft / pat / DotMulti.js
1 Clazz.declarePackage ("com.stevesoft.pat");\r
2 Clazz.load (["com.stevesoft.pat.PatternSub"], "com.stevesoft.pat.DotMulti", null, function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.fewestMatches = null;\r
5 this.mostMatches = null;\r
6 this.matchFewest = false;\r
7 this.src = null;\r
8 this.srclength = 0;\r
9 this.dotDoesntMatchCR = true;\r
10 Clazz.instantialize (this, arguments);\r
11 }, com.stevesoft.pat, "DotMulti", com.stevesoft.pat.PatternSub);\r
12 Clazz.overrideMethod (c$, "minChars", \r
13 function () {\r
14 return this.fewestMatches;\r
15 });\r
16 Clazz.overrideMethod (c$, "maxChars", \r
17 function () {\r
18 return this.mostMatches;\r
19 });\r
20 Clazz.makeConstructor (c$, \r
21 function (a, b) {\r
22 Clazz.superConstructor (this, com.stevesoft.pat.DotMulti, []);\r
23 this.fewestMatches = a;\r
24 this.mostMatches = b;\r
25 }, "com.stevesoft.pat.patInt,com.stevesoft.pat.patInt");\r
26 Clazz.overrideMethod (c$, "toString", \r
27 function () {\r
28 return ".{" + this.fewestMatches + "," + this.mostMatches + "}" + (this.matchFewest ? "?" : "") + "(?# <= dot multi)" + this.nextString ();\r
29 });\r
30 Clazz.defineMethod (c$, "submatchInternal", \r
31 function (pos, pt) {\r
32 if (pos < this.srclength) {\r
33 if (this.dotDoesntMatchCR) {\r
34 if (this.src.charAt (pos) != '\n') {\r
35 return 1 + pos;\r
36 }} else {\r
37 return 1 + pos;\r
38 }}return -1;\r
39 }, "~N,com.stevesoft.pat.Pthings");\r
40 Clazz.overrideMethod (c$, "matchInternal", \r
41 function (pos, pt) {\r
42 var m = -1;\r
43 var i = pos;\r
44 this.src = pt.src;\r
45 this.srclength = this.src.length ();\r
46 this.dotDoesntMatchCR = pt.dotDoesntMatchCR;\r
47 if (this.matchFewest) {\r
48 var nMatches = 0;\r
49 while (this.fewestMatches.intValue () > nMatches) {\r
50 i = this.submatchInternal (i, pt);\r
51 if (i < 0) {\r
52 return -1;\r
53 }nMatches++;\r
54 }\r
55 if (i < 0) {\r
56 return -1;\r
57 }var ii = this.nextMatch (i, pt);\r
58 if (ii >= 0) {\r
59 return ii;\r
60 }if (!this.mostMatches.finite ()) {\r
61 while (i >= 0) {\r
62 i = this.submatchInternal (i, pt);\r
63 if (i < 0) {\r
64 return -1;\r
65 }ii = this.nextMatch (i, pt);\r
66 if (ii >= 0) {\r
67 return ii;\r
68 }}\r
69 } else {\r
70 while (i > 0) {\r
71 i = this.submatchInternal (i, pt);\r
72 if (i < 0) {\r
73 return -1;\r
74 }nMatches++;\r
75 if (nMatches > this.mostMatches.intValue ()) {\r
76 return -1;\r
77 }ii = this.nextMatch (i, pt);\r
78 if (ii >= 0) {\r
79 return ii;\r
80 }}\r
81 }return -1;\r
82 }var nMatches = 0;\r
83 while (this.fewestMatches.intValue () > nMatches) {\r
84 i = this.submatchInternal (i, pt);\r
85 if (i >= 0) {\r
86 nMatches++;\r
87 } else {\r
88 return -1;\r
89 }}\r
90 m = i;\r
91 if (this.mostMatches.finite ()) {\r
92 while (nMatches < this.mostMatches.intValue ()) {\r
93 i = this.submatchInternal (i, pt);\r
94 if (i >= 0) {\r
95 m = i;\r
96 nMatches++;\r
97 } else {\r
98 break;\r
99 }}\r
100 } else {\r
101 while (true) {\r
102 i = this.submatchInternal (i, pt);\r
103 if (i >= 0) {\r
104 m = i;\r
105 nMatches++;\r
106 } else {\r
107 break;\r
108 }}\r
109 }while (m >= pos) {\r
110 var r = this.nextMatch (m, pt);\r
111 if (r >= 0) {\r
112 return r;\r
113 }m -= 1;\r
114 nMatches--;\r
115 if (nMatches < this.fewestMatches.intValue ()) {\r
116 return -1;\r
117 }}\r
118 return -1;\r
119 }, "~N,com.stevesoft.pat.Pthings");\r
120 Clazz.overrideMethod (c$, "clone1", \r
121 function (h) {\r
122 var dm =  new com.stevesoft.pat.DotMulti (this.fewestMatches, this.mostMatches);\r
123 dm.matchFewest = this.matchFewest;\r
124 return dm;\r
125 }, "java.util.Hashtable");\r
126 Clazz.defineStatics (c$,\r
127 "step", 1,\r
128 "idcount", 1);\r
129 });\r