JAL-1807 test
[jalviewjs.git] / bin / com / stevesoft / pat / RegexWriter.js
1 Clazz.declarePackage ("com.stevesoft.pat");
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 () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.repr = null;
5 this.w = null;
6 this.ww = null;
7 this.sb = null;
8 this.wrap = null;
9 this.pos = 0;
10 this.epos = 0;
11 this.interval = 128;
12 this.bufferSize = 2048;
13 this.EOLchar = '\n';
14 this.max_lines = 2;
15 Clazz.instantialize (this, arguments);
16 }, com.stevesoft.pat, "RegexWriter", java.io.Writer);
17 Clazz.prepareFields (c$, function () {
18 this.sb =  new StringBuffer ();
19 this.wrap =  new com.stevesoft.pat.PartialBuffer (this.sb);
20 });
21 Clazz.makeConstructor (c$, 
22 function (t, w) {
23 Clazz.superConstructor (this, com.stevesoft.pat.RegexWriter, []);
24 this.w = w;
25 this.ww =  new com.stevesoft.pat.wrap.WriterWrap (w);
26 this.repr = t.getReplacer ();
27 this.repr.setBuffer ( new com.stevesoft.pat.StringBufferLike (this.ww));
28 this.repr.setSource (this.wrap);
29 }, "com.stevesoft.pat.Transformer,java.io.Writer");
30 Clazz.makeConstructor (c$, 
31 function (r, w) {
32 Clazz.superConstructor (this, com.stevesoft.pat.RegexWriter, []);
33 this.w = w;
34 this.ww =  new com.stevesoft.pat.wrap.WriterWrap (w);
35 this.repr = r.getReplacer ();
36 this.repr.setBuffer ( new com.stevesoft.pat.StringBufferLike (this.ww));
37 this.repr.setSource (this.wrap);
38 }, "com.stevesoft.pat.Regex,java.io.Writer");
39 Clazz.defineMethod (c$, "getEOLchar", 
40 function () {
41 return this.EOLchar;
42 });
43 Clazz.defineMethod (c$, "setEOLchar", 
44 function (c) {
45 this.EOLchar = c;
46 }, "~S");
47 Clazz.defineMethod (c$, "getMaxLines", 
48 function () {
49 return this.max_lines;
50 });
51 Clazz.defineMethod (c$, "setMaxLines", 
52 function (ml) {
53 this.max_lines = ml;
54 }, "~N");
55 Clazz.defineMethod (c$, "write", 
56 function () {
57 var rex = this.repr.getRegex ();
58 var eposOld = this.epos;
59 if (rex.matchAtLike (this.wrap, this.epos) && !this.wrap.overRun) {
60 while (this.pos < this.epos) {
61 this.w.write (this.sb.charCodeAt (this.pos++));
62 }
63 var to = rex.matchedTo ();
64 this.repr.setPos (to);
65 this.repr.apply (rex, rex.getReplaceRule ());
66 this.epos = this.pos = to;
67 if (this.epos == eposOld && this.epos < this.sb.length ()) {
68 this.epos++;
69 }} else if (!this.wrap.overRun && this.epos < this.sb.length ()) {
70 this.epos++;
71 }while (this.pos < this.epos) {
72 this.w.write (this.sb.charCodeAt (this.pos++));
73 }
74 if (this.epos == this.sb.length ()) {
75 this.sb.setLength (1);
76 this.pos = this.epos = 1;
77 } else if (this.pos > this.bufferSize) {
78 for (var i = this.bufferSize; i < this.sb.length (); i++) {
79 this.sb.setCharAt (i - this.bufferSize, this.sb.charAt (i));
80 }
81 this.pos -= this.bufferSize;
82 this.epos -= this.bufferSize;
83 this.sb.setLength (this.sb.length () - this.bufferSize);
84 }});
85 Clazz.defineMethod (c$, "write", 
86 function (ca, b, n) {
87 var m = b + n;
88 for (var i = b; i < m; i++) {
89 this.sb.append (ca[i]);
90 if (this.sb.length () % this.interval == this.interval - 1) {
91 this.wrap.overRun = false;
92 while (this.epos + this.interval < this.sb.length () && !this.wrap.overRun) {
93 this.write ();
94 }
95 }}
96 }, "~A,~N,~N");
97 Clazz.overrideMethod (c$, "flush", 
98 function () {
99 });
100 Clazz.defineMethod (c$, "close", 
101 function () {
102 this.wrap.allowOverRun = false;
103 this.wrap.overRun = false;
104 while (this.epos < this.sb.length ()) {
105 this.write ();
106 }
107 this.write ();
108 this.w.close ();
109 });
110 Clazz.defineMethod (c$, "length", 
111 function () {
112 return this.sb.length ();
113 });
114 Clazz.defineMethod (c$, "charAt", 
115 function (i) {
116 return this.sb.charAt (i);
117 }, "~N");
118 Clazz.defineMethod (c$, "setInterval", 
119 function (i) {
120 this.interval = i;
121 }, "~N");
122 Clazz.defineMethod (c$, "getInterval", 
123 function () {
124 return this.interval;
125 });
126 Clazz.defineMethod (c$, "getBufferSize", 
127 function () {
128 return this.bufferSize;
129 });
130 Clazz.defineMethod (c$, "setBufferSize", 
131 function (i) {
132 this.bufferSize = i;
133 }, "~N");
134 });