JSDOC/TextStream.js
[gnome.introspection-doc-generator] / JSDOC / TextStream.js
1 //<script type="text/javscript">
2
3 XObject = imports.XObject.XObject;
4
5
6 /**
7         @constructor
8 */
9 TextStream = function(text) {
10         if (typeof(text) == "undefined") text = "";
11         text = ""+text;
12         this.text = text;
13         this.cursor = 0;
14 }
15
16 XObject.extend( TextStream.prototype, { 
17     
18     look : function(n) {
19         if (typeof n == "undefined") n = 0;
20         
21         if (this.cursor+n < 0 || this.cursor+n >= this.text.length) {
22             var result = new String("");
23             result.eof = true;
24             return result;
25         }
26         return this.text.charAt(this.cursor+n);
27     },
28
29     next : function(n) {
30         if (typeof n == "undefined") n = 1;
31         if (n < 1) return null;
32         
33         var pulled = "";
34         for (var i = 0; i < n; i++) {
35             if (this.cursor+i < this.text.length) {
36                 pulled += this.text.charAt(this.cursor+i);
37             }
38             else {
39                 var result = new String("");
40                 result.eof = true;
41                 return result;
42             }
43         }
44
45         this.cursor += n;
46         return pulled;
47     }
48 });