Clazz.declarePackage ("com.stevesoft.pat"); Clazz.load (["java.io.Reader", "com.stevesoft.pat.PartialBuffer", "$.RBuffer", "java.lang.StringBuffer"], "com.stevesoft.pat.RegexReader", ["com.stevesoft.pat.StringBufferLike", "com.stevesoft.pat.wrap.StringBufferWrap"], function () { c$ = Clazz.decorateAsClass (function () { this.rb = null; this.wrap = null; this.moreToRead = true; this.r = null; this.rp = null; this.nmax = 2048; this.max_lines = 2; this.EOLchar = '\n'; Clazz.instantialize (this, arguments); }, com.stevesoft.pat, "RegexReader", java.io.Reader); Clazz.prepareFields (c$, function () { this.rb = new com.stevesoft.pat.RBuffer ( new StringBuffer ()); this.wrap = new com.stevesoft.pat.PartialBuffer (this.rb.sb); }); Clazz.makeConstructor (c$, function (rex, r) { Clazz.superConstructor (this, com.stevesoft.pat.RegexReader, []); this.r = r; this.rp = rex.getReplacer (); }, "com.stevesoft.pat.Regex,java.io.Reader"); Clazz.makeConstructor (c$, function (tex, r) { Clazz.superConstructor (this, com.stevesoft.pat.RegexReader, []); this.r = r; this.rp = tex.getReplacer (); }, "com.stevesoft.pat.Transformer,java.io.Reader"); Clazz.defineMethod (c$, "reset", function () { this.r.reset (); this.rb = new com.stevesoft.pat.RBuffer ( new StringBuffer ()); this.wrap = new com.stevesoft.pat.PartialBuffer (this.rb.sb); this.moreToRead = true; }); Clazz.defineMethod (c$, "readData", function () { var c; var n = 0; while ((c = this.r.read ()) != -1) { this.rb.sb.append (String.fromCharCode (c)); if (n++ > this.nmax) { break; }} if (c == -1 && n == 0) { this.moreToRead = false; this.wrap.allowOverRun = false; }}); Clazz.defineMethod (c$, "getMoreData", function () { while (this.rb.pos >= this.rb.epos) { this.wrap.overRun = false; if (this.rb.next != null) { this.rb = this.rb.next; } else if (this.rb.done) { break; } else if (this.rb.epos >= this.rb.sb.length () && this.rb.epos > this.nmax) { this.rb.pos = 1; this.rb.epos = 1; this.rb.sb.setLength (1); this.readData (); } else if (this.rb.epos >= this.rb.sb.length () && this.moreToRead) { this.readData (); } else if (this.rp.getRegex ().matchAt (this.wrap, this.rb.epos)) { if (this.wrap.overRun) { this.readData (); } else { var sbw = new com.stevesoft.pat.wrap.StringBufferWrap (); var sbl = new com.stevesoft.pat.StringBufferLike (sbw); var rex = this.rp.getRegex (); var npos = rex.matchedTo (); this.rp.setBuffer (sbl); this.rp.setSource (this.wrap); this.rp.setPos (npos); this.rp.apply (rex, rex.getReplaceRule ()); var opos = this.rb.epos; var rb2 = new com.stevesoft.pat.RBuffer (sbw.unwrap ()); rb2.epos = rb2.sb.length (); var rb3 = new com.stevesoft.pat.RBuffer (this.rb.sb); this.rb.next = rb2; rb2.next = rb3; if (npos == opos) { rb3.epos = npos + 1; if (rb3.epos > rb3.sb.length ()) { if (this.rb.pos >= this.rb.epos) { this.rb = this.rb.next; }rb3.pos = rb3.epos = 0; rb3.done = true; }rb3.pos = npos; } else { rb3.pos = rb3.epos = npos; }}} else { if (this.wrap.overRun) { this.readData (); } else if (this.rb.epos < this.rb.sb.length ()) { this.rb.epos++; } else { break; }}} }); Clazz.defineMethod (c$, "read", function () { if (this.rb.pos >= this.rb.epos) { this.getMoreData (); if (this.rb.pos >= this.rb.epos) { return -1; }}return this.rb.sb.charAt (this.rb.pos++); }); Clazz.defineMethod (c$, "read", function (buf, off, len) { var c = -1; var end = off + len; for (var i = off; i < end; i++) { c = this.read (); if (c < 0) { if (i == off) { return -1; }return i - off; }buf[i] = String.fromCharCode (c); } return len; }, "~A,~N,~N"); Clazz.defineMethod (c$, "close", function () { this.r.close (); }); Clazz.overrideMethod (c$, "markSupported", function () { return false; }); Clazz.defineMethod (c$, "getBufferSize", function () { return this.nmax; }); Clazz.defineMethod (c$, "setBufferSize", function (n) { this.nmax = n; }, "~N"); Clazz.defineMethod (c$, "getMaxLines", function () { return this.max_lines; }); Clazz.defineMethod (c$, "setMaxLines", function (ml) { this.max_lines = ml; }, "~N"); Clazz.defineMethod (c$, "getEOLchar", function () { return this.EOLchar; }); Clazz.defineMethod (c$, "setEOLchar", function (c) { this.EOLchar = c; }, "~S"); Clazz.overrideMethod (c$, "skip", function (d) { var n = 0; while (n < d && this.read () != -1) { n++; } return n; }, "~N"); });