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 () {
5 Clazz.instantialize (this, arguments);
6 }, com.stevesoft.pat, "TransRepRule", com.stevesoft.pat.ReplaceRule);
7 Clazz.makeConstructor (c$,
9 Clazz.superConstructor (this, com.stevesoft.pat.TransRepRule, []);
11 }, "com.stevesoft.pat.Transformer");
12 Clazz.overrideMethod (c$, "toString1",
16 Clazz.overrideMethod (c$, "clone1",
18 return new com.stevesoft.pat.TransRepRule (this.t);
20 Clazz.overrideMethod (c$, "apply",
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 () {
27 this.auto_optimize = false;
29 Clazz.instantialize (this, arguments);
30 }, com.stevesoft.pat, "Transformer");
31 Clazz.prepareFields (c$, function () {
32 this.repr = new com.stevesoft.pat.Replacer ();
34 Clazz.defineMethod (c$, "getReplacer",
36 return this.rp.getReplacer ();
38 Clazz.makeConstructor (c$,
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;
46 Clazz.defineMethod (c$, "add",
48 if (this.auto_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];
57 }this.rp.numSubs_ = r.numSubs_ > this.rp.numSubs_ ? r.numSubs_ : this.rp.numSubs_;
58 }, "com.stevesoft.pat.Regex");
59 Clazz.defineMethod (c$, "patterns",
61 return this.tp.ra_len;
63 Clazz.defineMethod (c$, "getRegexAt",
65 if (i >= this.tp.ra_len) {
66 throw new ArrayIndexOutOfBoundsException ("i=" + i + ">=" + this.patterns ());
68 throw new ArrayIndexOutOfBoundsException ("i=" + i + "< 0");
69 }return this.tp.ra[i];
71 Clazz.defineMethod (c$, "setRegexAt",
73 if (i >= this.tp.ra_len) {
74 throw new ArrayIndexOutOfBoundsException ("i=" + i + ">=" + this.patterns ());
76 throw new ArrayIndexOutOfBoundsException ("i=" + i + "< 0");
78 }, "com.stevesoft.pat.Regex,~N");
79 Clazz.defineMethod (c$, "add",
81 var r = com.stevesoft.pat.Regex.perlCode (rs);
83 throw new NullPointerException (com.stevesoft.pat.MessageManager.formatMessage ("exception.bad_pattern_to_regex_perl_code", Clazz.newArray (-1, [rs])));
86 Clazz.defineMethod (c$, "add",
88 for (var i = 0; i < array.length; i++) {
92 Clazz.defineMethod (c$, "replaceAll",
94 return this.dorep (s, 0, s.length);
96 Clazz.defineMethod (c$, "replaceAll",
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);
104 Clazz.defineMethod (c$, "replaceAllRegion",
105 function (s, start, end) {
106 return this.dorep (s, start, end);
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;
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 ();
118 Clazz.defineMethod (c$, "replaceFirst",
120 return this.dorep (s, 0, s.length);
122 Clazz.defineMethod (c$, "replaceFirstFrom",
123 function (s, start) {
124 return this.dorep (s, start, s.length);
126 Clazz.defineMethod (c$, "replaceFirstRegion",
127 function (s, start, end) {
128 return this.dorep (s, start, end);