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