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