1 Clazz.declarePackage ("com.stevesoft.pat");
2 Clazz.load (null, ["com.stevesoft.pat.RegHolder", "$.Replacer", "$.CodeVal"], ["com.stevesoft.pat.AmpersandRule", "$.ChangeRule", "$.MessageManager", "$.PopRule", "$.PushRule", "$.RuleHolder", "$.SpecialRule", "$.StringBufferLike", "$.WantMoreTextReplaceRule", "com.stevesoft.pat.wrap.StringWrap", "java.lang.NullPointerException"], function () {
3 c$ = Clazz.decorateAsClass (function () {
6 Clazz.instantialize (this, arguments);
7 }, com.stevesoft.pat, "RegHolder");
8 c$ = Clazz.decorateAsClass (function () {
11 Clazz.instantialize (this, arguments);
12 }, com.stevesoft.pat, "CodeVal");
13 Clazz.makeConstructor (c$,
18 Clazz.overrideMethod (c$, "toString",
20 return "(" + this.pos + "," + this.code + ")";
22 c$ = Clazz.decorateAsClass (function () {
28 this.want_more_text = false;
29 this.want_more_text_enable = false;
30 this.$lastMatchedTo = 0;
31 Clazz.instantialize (this, arguments);
32 }, com.stevesoft.pat, "Replacer");
33 Clazz.prepareFields (c$, function () {
34 this.rh = new com.stevesoft.pat.RegHolder ();
36 Clazz.makeConstructor (c$,
39 Clazz.defineMethod (c$, "replaceFirstRegion",
40 function (s, r, start, end) {
41 return this.replaceFirstRegion ( new com.stevesoft.pat.wrap.StringWrap (s), r, start, end);
42 }, "~S,com.stevesoft.pat.Regex,~N,~N");
43 Clazz.defineMethod (c$, "replaceFirstRegion",
44 function (s, r, start, end) {
48 return this.dorep (s, start, end);
49 }, "com.stevesoft.pat.StringLike,com.stevesoft.pat.Regex,~N,~N");
50 Clazz.defineMethod (c$, "replaceFirst",
52 return this.replaceFirstRegion (s, 0, s.length ());
53 }, "com.stevesoft.pat.StringLike");
54 Clazz.defineMethod (c$, "replaceFirstFrom",
56 return this.replaceFirstRegion (s, start, s.length ());
57 }, "com.stevesoft.pat.StringLike,~N");
58 Clazz.defineMethod (c$, "replaceFirstRegion",
59 function (s, start, end) {
61 return this.dorep (s, start, end);
62 }, "com.stevesoft.pat.StringLike,~N,~N");
63 Clazz.defineMethod (c$, "replaceAllRegion",
64 function (s, r, start, end) {
65 return this.replaceAllRegion ( new com.stevesoft.pat.wrap.StringWrap (s), r, start, end);
66 }, "~S,com.stevesoft.pat.Regex,~N,~N");
67 Clazz.defineMethod (c$, "replaceAllRegion",
68 function (s, r, start, end) {
72 return this.dorep (s, start, end);
73 }, "com.stevesoft.pat.StringLike,com.stevesoft.pat.Regex,~N,~N");
74 Clazz.defineMethod (c$, "replaceAll",
76 return this.replaceAllRegion (s, 0, s.length ());
77 }, "com.stevesoft.pat.StringLike");
78 Clazz.defineMethod (c$, "replaceAllFrom",
80 return this.replaceAllRegion (s, start, s.length ());
81 }, "com.stevesoft.pat.StringLike,~N");
82 Clazz.defineMethod (c$, "replaceAllRegion",
83 function (s, start, end) {
85 return this.dorep (s, start, end);
86 }, "com.stevesoft.pat.StringLike,~N,~N");
87 Clazz.defineMethod (c$, "replaceAll",
89 return this.replaceAllRegion ( new com.stevesoft.pat.wrap.StringWrap (s), 0, s.length).toString ();
91 Clazz.defineMethod (c$, "replaceAllFrom",
93 return this.replaceAllRegion ( new com.stevesoft.pat.wrap.StringWrap (s), start, s.length).toString ();
95 Clazz.defineMethod (c$, "replaceAllRegion",
96 function (s, start, end) {
98 return this.dorep ( new com.stevesoft.pat.wrap.StringWrap (s), start, end).toString ();
100 Clazz.defineMethod (c$, "isSpecial",
103 if (Clazz.instanceOf (x, com.stevesoft.pat.SpecialRule) || (Clazz.instanceOf (x, com.stevesoft.pat.RuleHolder) && Clazz.instanceOf ((x).held, com.stevesoft.pat.SpecialRule))) {
108 }, "com.stevesoft.pat.ReplaceRule");
109 Clazz.defineMethod (c$, "apply1",
112 this.apply (rr, null);
114 }, "com.stevesoft.pat.RegRes");
115 Clazz.defineMethod (c$, "dorep",
116 function (s, start, end) {
118 this.want_more_text = false;
119 this.$lastMatchedTo = 0;
120 if (this.rh.me == null) {
121 throw new NullPointerException (com.stevesoft.pat.MessageManager.getString ("exception.replace_null_regex_pointer"));
122 }if (this.rh.me._searchLike (s, start, end)) {
123 var rmn = this.rh.me.matchedTo ();
124 if (this.rh.me.charsMatched () == 0 && !this.isSpecial (this.rh.me.getReplaceRule ())) {
125 this.apply1 (this.rh.me);
127 }this.apply (this.rh.me);
129 for (var i = rmn; !this.want_more_text && this.rh.me._searchLike (s, i, end); i = rmn) {
130 rmn = this.rh.me.matchedTo ();
131 if (this.rh.me.charsMatched () == 0) {
132 if (!this.isSpecial (this.rh.me.getReplaceRule ())) {
133 this.apply1 (this.rh.me);
135 }this.apply (this.rh.me);
137 }ret = this.finish ();
138 ret = ret == null ? s : ret;
140 }, "com.stevesoft.pat.StringLike,~N,~N");
141 Clazz.defineMethod (c$, "apply",
143 if (rp == null || (rp.next == null && Clazz.instanceOf (rp, com.stevesoft.pat.AmpersandRule))) {
145 }if (r.didMatch ()) {
146 if (this.src == null) {
147 this.src = r.getStringLike ();
148 }if (this.sb == null) {
149 this.sb = new com.stevesoft.pat.StringBufferLike (this.src.newStringBufferLike ());
150 }var rmf = r.matchedFrom ();
151 for (var ii = this.pos; ii < rmf; ii++) {
152 this.sb.appendC (this.src.charAt (ii));
154 for (var x = rp; x != null; x = x.next) {
155 x.apply (this.sb, r);
156 if (Clazz.instanceOf (x, com.stevesoft.pat.SpecialRule)) {
157 if (Clazz.instanceOf (x, com.stevesoft.pat.WantMoreTextReplaceRule) && this.want_more_text_enable) {
158 this.want_more_text = true;
159 } else if (Clazz.instanceOf (x, com.stevesoft.pat.PushRule)) {
160 var rh2 = new com.stevesoft.pat.RegHolder ();
161 rh2.me = (x).NewRule;
164 } else if (Clazz.instanceOf (x, com.stevesoft.pat.PopRule)) {
165 if (this.rh.prev != null) {
166 this.rh = this.rh.prev;
167 }} else if (Clazz.instanceOf (x, com.stevesoft.pat.ChangeRule)) {
168 this.rh.me = (x).NewRule;
170 if (!this.want_more_text) {
171 this.pos = r.matchedTo ();
172 }}}, "com.stevesoft.pat.RegRes,com.stevesoft.pat.ReplaceRule");
173 Clazz.defineMethod (c$, "WantMoreText",
175 return this.want_more_text;
177 Clazz.defineMethod (c$, "apply",
179 this.apply (r, r.getReplaceRule ());
180 }, "com.stevesoft.pat.Regex");
181 Clazz.defineMethod (c$, "finish",
183 if (this.src == null) {
185 }var s_end = this.src.length ();
186 for (var ii = this.pos; ii < s_end; ii++) {
187 this.sb.appendC (this.src.charAt (ii));
190 this.$lastMatchedTo = this.pos;
192 var retstr = this.sb.toStringLike ();
196 Clazz.overrideMethod (c$, "clone",
198 var r = new com.stevesoft.pat.Replacer ();
199 r.first = this.first;
203 r.$lastMatchedTo = this.$lastMatchedTo;
204 r.want_more_text = this.want_more_text;
205 r.want_more_text_enable = this.want_more_text_enable;
206 r.rh.me = this.rh.me;
207 r.rh.prev = this.rh.prev;
210 Clazz.defineMethod (c$, "lastMatchedTo",
212 return this.$lastMatchedTo;
214 Clazz.defineMethod (c$, "getRegex",
218 Clazz.defineMethod (c$, "setSource",
221 }, "com.stevesoft.pat.StringLike");
222 Clazz.defineMethod (c$, "setBuffer",
225 }, "com.stevesoft.pat.StringBufferLike");
226 Clazz.defineMethod (c$, "setPos",