1 Clazz.declarePackage ("com.stevesoft.pat");
\r
2 Clazz.load (["java.io.Writer", "com.stevesoft.pat.PartialBuffer", "java.lang.StringBuffer"], "com.stevesoft.pat.RegexWriter", ["com.stevesoft.pat.StringBufferLike", "com.stevesoft.pat.wrap.WriterWrap"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
11 this.interval = 128;
\r
12 this.bufferSize = 2048;
\r
13 this.EOLchar = '\n';
\r
15 Clazz.instantialize (this, arguments);
\r
16 }, com.stevesoft.pat, "RegexWriter", java.io.Writer);
\r
17 Clazz.prepareFields (c$, function () {
\r
18 this.sb = new StringBuffer ();
\r
19 this.wrap = new com.stevesoft.pat.PartialBuffer (this.sb);
\r
21 Clazz.makeConstructor (c$,
\r
23 Clazz.superConstructor (this, com.stevesoft.pat.RegexWriter, []);
\r
25 this.ww = new com.stevesoft.pat.wrap.WriterWrap (w);
\r
26 this.repr = t.getReplacer ();
\r
27 this.repr.setBuffer ( new com.stevesoft.pat.StringBufferLike (this.ww));
\r
28 this.repr.setSource (this.wrap);
\r
29 }, "com.stevesoft.pat.Transformer,java.io.Writer");
\r
30 Clazz.makeConstructor (c$,
\r
32 Clazz.superConstructor (this, com.stevesoft.pat.RegexWriter, []);
\r
34 this.ww = new com.stevesoft.pat.wrap.WriterWrap (w);
\r
35 this.repr = r.getReplacer ();
\r
36 this.repr.setBuffer ( new com.stevesoft.pat.StringBufferLike (this.ww));
\r
37 this.repr.setSource (this.wrap);
\r
38 }, "com.stevesoft.pat.Regex,java.io.Writer");
\r
39 Clazz.defineMethod (c$, "getEOLchar",
\r
41 return this.EOLchar;
\r
43 Clazz.defineMethod (c$, "setEOLchar",
\r
47 Clazz.defineMethod (c$, "getMaxLines",
\r
49 return this.max_lines;
\r
51 Clazz.defineMethod (c$, "setMaxLines",
\r
53 this.max_lines = ml;
\r
55 Clazz.defineMethod (c$, "write",
\r
57 var rex = this.repr.getRegex ();
\r
58 var eposOld = this.epos;
\r
59 if (rex.matchAtLike (this.wrap, this.epos) && !this.wrap.overRun) {
\r
60 while (this.pos < this.epos) {
\r
61 this.w.write (this.sb.charCodeAt (this.pos++));
\r
63 var to = rex.matchedTo ();
\r
64 this.repr.setPos (to);
\r
65 this.repr.apply (rex, rex.getReplaceRule ());
\r
66 this.epos = this.pos = to;
\r
67 if (this.epos == eposOld && this.epos < this.sb.length ()) {
\r
69 }} else if (!this.wrap.overRun && this.epos < this.sb.length ()) {
\r
71 }while (this.pos < this.epos) {
\r
72 this.w.write (this.sb.charCodeAt (this.pos++));
\r
74 if (this.epos == this.sb.length ()) {
\r
75 this.sb.setLength (1);
\r
76 this.pos = this.epos = 1;
\r
77 } else if (this.pos > this.bufferSize) {
\r
78 for (var i = this.bufferSize; i < this.sb.length (); i++) {
\r
79 this.sb.setCharAt (i - this.bufferSize, this.sb.charAt (i));
\r
81 this.pos -= this.bufferSize;
\r
82 this.epos -= this.bufferSize;
\r
83 this.sb.setLength (this.sb.length () - this.bufferSize);
\r
85 Clazz.defineMethod (c$, "write",
\r
86 function (ca, b, n) {
\r
88 for (var i = b; i < m; i++) {
\r
89 this.sb.append (ca[i]);
\r
90 if (this.sb.length () % this.interval == this.interval - 1) {
\r
91 this.wrap.overRun = false;
\r
92 while (this.epos + this.interval < this.sb.length () && !this.wrap.overRun) {
\r
97 Clazz.overrideMethod (c$, "flush",
\r
100 Clazz.defineMethod (c$, "close",
\r
102 this.wrap.allowOverRun = false;
\r
103 this.wrap.overRun = false;
\r
104 while (this.epos < this.sb.length ()) {
\r
110 Clazz.defineMethod (c$, "length",
\r
112 return this.sb.length ();
\r
114 Clazz.defineMethod (c$, "charAt",
\r
116 return this.sb.charAt (i);
\r
118 Clazz.defineMethod (c$, "setInterval",
\r
122 Clazz.defineMethod (c$, "getInterval",
\r
124 return this.interval;
\r
126 Clazz.defineMethod (c$, "getBufferSize",
\r
128 return this.bufferSize;
\r
130 Clazz.defineMethod (c$, "setBufferSize",
\r
132 this.bufferSize = i;
\r