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