X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=bin%2Fcom%2Fstevesoft%2Fpat%2FRegexReader.js;h=d767d8068257d9d5b5c33adb36444a5ada998fe7;hp=301d8e7f5ddbeaf8cd3b68213716ba05f90b48e4;hb=8ffd05b3abe52c0b6b79b011c0966361f82d5fe6;hpb=6154cb57a6eac3bb1344b8342495f5bb701ee921 diff --git a/bin/com/stevesoft/pat/RegexReader.js b/bin/com/stevesoft/pat/RegexReader.js index 301d8e7..d767d80 100644 --- a/bin/com/stevesoft/pat/RegexReader.js +++ b/bin/com/stevesoft/pat/RegexReader.js @@ -1,164 +1,164 @@ -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 ().matchAtLike (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"); -}); +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 ().matchAtLike (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"); +});