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