JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / bin / com / stevesoft / pat / Transformer.js
1 Clazz.declarePackage ("com.stevesoft.pat");\r
2 Clazz.load (["com.stevesoft.pat.ReplaceRule", "$.Replacer"], ["com.stevesoft.pat.Transformer", "$.TransRepRule"], ["com.stevesoft.pat.MessageManager", "$.Regex", "$.TransPat", "com.stevesoft.pat.wrap.StringWrap", "java.lang.ArrayIndexOutOfBoundsException", "$.NullPointerException"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.t = null;\r
5 Clazz.instantialize (this, arguments);\r
6 }, com.stevesoft.pat, "TransRepRule", com.stevesoft.pat.ReplaceRule);\r
7 Clazz.makeConstructor (c$, \r
8 function (t) {\r
9 Clazz.superConstructor (this, com.stevesoft.pat.TransRepRule, []);\r
10 this.t = t;\r
11 }, "com.stevesoft.pat.Transformer");\r
12 Clazz.overrideMethod (c$, "toString1", \r
13 function () {\r
14 return "";\r
15 });\r
16 Clazz.overrideMethod (c$, "clone1", \r
17 function () {\r
18 return  new com.stevesoft.pat.TransRepRule (this.t);\r
19 });\r
20 Clazz.overrideMethod (c$, "apply", \r
21 function (sb, rr) {\r
22 this.next = this.t.tp.ra[this.t.tp.pn].getReplaceRule ();\r
23 }, "com.stevesoft.pat.StringBufferLike,com.stevesoft.pat.RegRes");\r
24 c$ = Clazz.decorateAsClass (function () {\r
25 this.tp = null;\r
26 this.rp = null;\r
27 this.auto_optimize = false;\r
28 this.repr = null;\r
29 Clazz.instantialize (this, arguments);\r
30 }, com.stevesoft.pat, "Transformer");\r
31 Clazz.prepareFields (c$, function () {\r
32 this.repr =  new com.stevesoft.pat.Replacer ();\r
33 });\r
34 Clazz.defineMethod (c$, "getReplacer", \r
35 function () {\r
36 return this.rp.getReplacer ();\r
37 });\r
38 Clazz.makeConstructor (c$, \r
39 function (auto) {\r
40 this.rp =  new com.stevesoft.pat.Regex (null, "");\r
41 this.auto_optimize = auto;\r
42 this.tp =  new com.stevesoft.pat.TransPat ();\r
43 this.rp.setReplaceRule ( new com.stevesoft.pat.TransRepRule (this));\r
44 this.rp.thePattern = this.tp;\r
45 }, "~B");\r
46 Clazz.defineMethod (c$, "add", \r
47 function (r) {\r
48 if (this.auto_optimize) {\r
49 r.optimize ();\r
50 }this.tp.ra[this.tp.ra_len++] = r;\r
51 if (this.tp.ra.length == this.tp.ra_len) {\r
52 var ra2 =  new Array (this.tp.ra_len + 10);\r
53 for (var i = 0; i < this.tp.ra_len; i++) {\r
54 ra2[i] = this.tp.ra[i];\r
55 }\r
56 this.tp.ra = ra2;\r
57 }this.rp.numSubs_ = r.numSubs_ > this.rp.numSubs_ ? r.numSubs_ : this.rp.numSubs_;\r
58 }, "com.stevesoft.pat.Regex");\r
59 Clazz.defineMethod (c$, "patterns", \r
60 function () {\r
61 return this.tp.ra_len;\r
62 });\r
63 Clazz.defineMethod (c$, "getRegexAt", \r
64 function (i) {\r
65 if (i >= this.tp.ra_len) {\r
66 throw  new ArrayIndexOutOfBoundsException ("i=" + i + ">=" + this.patterns ());\r
67 }if (i < 0) {\r
68 throw  new ArrayIndexOutOfBoundsException ("i=" + i + "< 0");\r
69 }return this.tp.ra[i];\r
70 }, "~N");\r
71 Clazz.defineMethod (c$, "setRegexAt", \r
72 function (rx, i) {\r
73 if (i >= this.tp.ra_len) {\r
74 throw  new ArrayIndexOutOfBoundsException ("i=" + i + ">=" + this.patterns ());\r
75 }if (i < 0) {\r
76 throw  new ArrayIndexOutOfBoundsException ("i=" + i + "< 0");\r
77 }this.tp.ra[i] = rx;\r
78 }, "com.stevesoft.pat.Regex,~N");\r
79 Clazz.defineMethod (c$, "add", \r
80 function (rs) {\r
81 var r = com.stevesoft.pat.Regex.perlCode (rs);\r
82 if (r == null) {\r
83 throw  new NullPointerException (com.stevesoft.pat.MessageManager.formatMessage ("exception.bad_pattern_to_regex_perl_code",  Clazz.newArray (-1, [rs])));\r
84 }this.add (r);\r
85 }, "~S");\r
86 Clazz.defineMethod (c$, "add", \r
87 function (array) {\r
88 for (var i = 0; i < array.length; i++) {\r
89 this.add (array[i]);\r
90 }\r
91 }, "~A");\r
92 Clazz.defineMethod (c$, "replaceAll", \r
93 function (s) {\r
94 return this.dorep (s, 0, s.length);\r
95 }, "~S");\r
96 Clazz.defineMethod (c$, "replaceAll", \r
97 function (s) {\r
98 return this.dorep (s, 0, s.length ());\r
99 }, "com.stevesoft.pat.StringLike");\r
100 Clazz.defineMethod (c$, "replaceAllFrom", \r
101 function (s, start) {\r
102 return this.dorep (s, start, s.length);\r
103 }, "~S,~N");\r
104 Clazz.defineMethod (c$, "replaceAllRegion", \r
105 function (s, start, end) {\r
106 return this.dorep (s, start, end);\r
107 }, "~S,~N,~N");\r
108 Clazz.defineMethod (c$, "dorep", \r
109 function (s, start, end) {\r
110 var tfmd = this.repr.replaceAllRegion (s, this.rp, start, end);\r
111 this.tp.lastMatchedTo = this.repr.$lastMatchedTo;\r
112 return tfmd;\r
113 }, "com.stevesoft.pat.StringLike,~N,~N");\r
114 Clazz.defineMethod (c$, "dorep", \r
115 function (s, start, end) {\r
116 return this.dorep ( new com.stevesoft.pat.wrap.StringWrap (s), start, end).toString ();\r
117 }, "~S,~N,~N");\r
118 Clazz.defineMethod (c$, "replaceFirst", \r
119 function (s) {\r
120 return this.dorep (s, 0, s.length);\r
121 }, "~S");\r
122 Clazz.defineMethod (c$, "replaceFirstFrom", \r
123 function (s, start) {\r
124 return this.dorep (s, start, s.length);\r
125 }, "~S,~N");\r
126 Clazz.defineMethod (c$, "replaceFirstRegion", \r
127 function (s, start, end) {\r
128 return this.dorep (s, start, end);\r
129 }, "~S,~N,~N");\r
130 });\r