JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / com / stevesoft / pat / Pattern.js
1 Clazz.declarePackage ("com.stevesoft.pat");\r
2 Clazz.load (null, "com.stevesoft.pat.Pattern", ["com.stevesoft.pat.MessageManager", "$.patInf", "$.patInt", "java.lang.Error", "$.StringBuffer"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.next = null;\r
5 this.parent = null;\r
6 this.mfrom = 0;\r
7 Clazz.instantialize (this, arguments);\r
8 }, com.stevesoft.pat, "Pattern");\r
9 Clazz.defineMethod (c$, "getNext", \r
10 function () {\r
11 return this.next != null ? this.next : (this.parent == null ? null : this.parent.getNext ());\r
12 });\r
13 Clazz.defineMethod (c$, "setParent", \r
14 function (p) {\r
15 if (this.next != null) {\r
16 this.next.setParent (p);\r
17 } else {\r
18 this.parent = p;\r
19 }}, "com.stevesoft.pat.Pattern");\r
20 Clazz.defineMethod (c$, "nextMatch", \r
21 function (i, pt) {\r
22 var p = this.getNext ();\r
23 return p == null ? i : p.matchInternal (i, pt);\r
24 }, "~N,com.stevesoft.pat.Pthings");\r
25 Clazz.defineMethod (c$, "nextString", \r
26 function () {\r
27 if (this.next == null) {\r
28 return "";\r
29 }return this.next.toString ();\r
30 });\r
31 c$.inString = Clazz.defineMethod (c$, "inString", \r
32 function (c, s) {\r
33 var i;\r
34 for (i = 0; i < s.length; i++) {\r
35 if (s.charAt (i) == c) {\r
36 return true;\r
37 }}\r
38 return false;\r
39 }, "~S,~S");\r
40 c$.protect = Clazz.defineMethod (c$, "protect", \r
41 function (s, PROTECT_THESE, esc) {\r
42 var i;\r
43 var sb =  new StringBuffer ();\r
44 var p = PROTECT_THESE + esc;\r
45 for (i = 0; i < s.length; i++) {\r
46 var c = s.charAt (i);\r
47 if (com.stevesoft.pat.Pattern.inString (c, p)) {\r
48 sb.append (esc);\r
49 }sb.append (c);\r
50 }\r
51 return sb.toString ();\r
52 }, "~S,~S,~S");\r
53 Clazz.defineMethod (c$, "match", \r
54 function (s, pt) {\r
55 return this.matchAt (s, 0, pt);\r
56 }, "com.stevesoft.pat.StringLike,com.stevesoft.pat.Pthings");\r
57 Clazz.defineMethod (c$, "matchAt", \r
58 function (s, i, pt) {\r
59 pt.src = s;\r
60 var r = this.matchInternal (i, pt);\r
61 if (r < 0) {\r
62 return -1;\r
63 }this.mfrom = r < i ? r + 1 : i;\r
64 return r < i ? i - r - 1 : r - i;\r
65 }, "com.stevesoft.pat.StringLike,~N,com.stevesoft.pat.Pthings");\r
66 Clazz.defineMethod (c$, "Masked", \r
67 function (i, pt) {\r
68 return pt.cbits == null ? false : pt.cbits.get (i);\r
69 }, "~N,com.stevesoft.pat.Pthings");\r
70 Clazz.defineMethod (c$, "add", \r
71 function (p) {\r
72 if (this.next == null) {\r
73 if (p == null) {\r
74 return this;\r
75 }this.next = p;\r
76 p.parent = this.parent;\r
77 this.parent = null;\r
78 } else {\r
79 this.next.add (p);\r
80 }return this;\r
81 }, "com.stevesoft.pat.Pattern");\r
82 Clazz.defineMethod (c$, "minChars", \r
83 function () {\r
84 return  new com.stevesoft.pat.patInt (0);\r
85 });\r
86 Clazz.defineMethod (c$, "maxChars", \r
87 function () {\r
88 return  new com.stevesoft.pat.patInf ();\r
89 });\r
90 Clazz.defineMethod (c$, "countMinChars", \r
91 function () {\r
92 var p = this;\r
93 var sum =  new com.stevesoft.pat.patInt (0);\r
94 while (p != null) {\r
95 sum.pluseq (p.minChars ());\r
96 p = p.next;\r
97 }\r
98 return sum;\r
99 });\r
100 Clazz.defineMethod (c$, "countMaxChars", \r
101 function () {\r
102 var p = this;\r
103 var sum =  new com.stevesoft.pat.patInt (0);\r
104 while (p != null) {\r
105 sum.pluseq (p.maxChars ());\r
106 p = p.next;\r
107 }\r
108 return sum;\r
109 });\r
110 Clazz.defineMethod (c$, "testMatch", \r
111 function (p, pos, pt) {\r
112 var tab = null;\r
113 if (pt.marks != null) {\r
114 try {\r
115 tab =  Clazz.newIntArray (pt.marks.length, 0);\r
116 for (var i = 0; i < tab.length; i++) {\r
117 tab[i] = pt.marks[i];\r
118 }\r
119 } catch (t) {\r
120 }\r
121 }var ret = p.matchInternal (pos, pt);\r
122 if (ret < 0) {\r
123 pt.marks = tab;\r
124 }return ret;\r
125 }, "com.stevesoft.pat.Pattern,~N,com.stevesoft.pat.Pthings");\r
126 Clazz.defineMethod (c$, "clone1", \r
127 function (h) {\r
128 throw  new Error (com.stevesoft.pat.MessageManager.formatMessage ("error.no_such_method_as_clone1_for",  Clazz.newArray (-1, [this.getClass ().getName ()])));\r
129 }, "java.util.Hashtable");\r
130 Clazz.defineMethod (c$, "clone", \r
131 function (h) {\r
132 var p = h.get (this);\r
133 if (p != null) {\r
134 return p;\r
135 }p = this.clone1 (h);\r
136 if (p == null) {\r
137 throw  new Error (com.stevesoft.pat.MessageManager.getString ("error.null_from_clone1"));\r
138 }h.put (this, p);\r
139 h.put (p, p);\r
140 if (this.next != null) {\r
141 p.next = this.next.clone (h);\r
142 }if (this.parent != null) {\r
143 p.parent = this.parent.clone (h);\r
144 }return p;\r
145 }, "java.util.Hashtable");\r
146 Clazz.overrideMethod (c$, "equals", \r
147 function (o) {\r
148 return o === this;\r
149 }, "~O");\r
150 Clazz.defineStatics (c$,\r
151 "ESC", '\\',\r
152 "PROTECT_THESE", "[]{}(),$,-\"^.");\r
153 });\r