X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=JSDOC%2FTextStream.vala;h=f5bb7258fce7e3965ceb9fc1f595af5dd86f1873;hb=47d710e1ad8352be849a59e4728f421627e568a6;hp=277b51874959ad6aba5310a6c9e764d184cb0602;hpb=cbb5544918bffae8800967a6fe947aa883ffcd6b;p=gnome.introspection-doc-generator diff --git a/JSDOC/TextStream.vala b/JSDOC/TextStream.vala index 277b518..f5bb725 100644 --- a/JSDOC/TextStream.vala +++ b/JSDOC/TextStream.vala @@ -20,43 +20,60 @@ namespace JSDOC { string text; int cursor; + int length; public TextStream (string text = "") { this.text = text; + this.length = text.length; // text.char_count(); this.cursor = 0; } - public char look(int n = 0) { - - - if (this.cursor+n < 0 || this.cursor+n >= this.text.length) { - var result = new String(""); - result.eof = true; - return result; + public char look(int n = 0) + { + + if (this.cursor+n < 0 || this.cursor+n >= this.length) { + return '\0'; + } + return this.text[this.cursor+n]; // this.text.get_char(this.cursor+n); + } + + public bool lookEOF(int n = 0) + { + if (this.cursor+n < 0 || this.cursor+n >= this.length) { + return true; + } + return false; + } + + /** + * @param n - number of characters to return.. + */ + public string next(int n = 1) + { + + if (n < 1) { //?? eof??? + return "\0"; } - return this.text.charAt(this.cursor+n); - }, - - next : function(n) { - if (typeof n == "undefined") n = 1; - if (n < 1) return null; - var pulled = ""; - for (var i = 0; i < n; i++) { - if (this.cursor+i < this.text.length) { - pulled += this.text.charAt(this.cursor+i); - } - else { - var result = new String(""); - result.eof = true; - return result; - } + string pulled = ""; + var i = 0; + while (i < n) { + if (this.cursor+i < this.length) { + var add = this.text[this.cursor+i]; //this.text.get_char(this.cursor+i).to_string(); + pulled += add.to_string(); + i += 1;// add.length; + } else { + return ""; + } - - this.cursor += n; - return pulled; } - }); \ No newline at end of file + + this.cursor += pulled.length; + return pulled; + + } + } +} \ No newline at end of file