JSDOC/TextStream.vala
[gnome.introspection-doc-generator] / JSDOC / TextStream.vala
1 //<script type="text/javscript">
2
3  
4
5 /**
6         @constructor
7 */
8 namespace JSDOC {
9     
10     public class TextStreamChar : Object {
11         public char c;
12         public bool eof;
13         public TextStreamChar(char val, bool eof=false) {
14             this.c = val;
15             this.eof = eof;
16         }
17     }
18     
19     public class TextStream : Object {
20         
21         string text;
22         int cursor;
23         
24         public TextStream (string text = "")
25         {
26             
27             
28             this.text = text;
29             this.cursor = 0;
30         }
31         
32         public char look(int n = 0)
33         {
34                  
35             if (this.cursor+n < 0 || this.cursor+n >= this.text.length) {
36                 return '\0';
37             }
38             return  this.text[this.cursor+n];
39         },
40         
41         public bool lookEOF(int n = 0)
42         {
43             if (this.cursor+n < 0 || this.cursor+n >= this.text.length) {
44                 return true;
45             }
46             return  false
47         },
48         
49     
50         public char next(int n = 1,  out bool eof)
51         {
52             eof = false;
53             if (n < 1) { //?? eof???
54                 return '\0';
55             }
56                 
57             char pulled;
58             for (var i = 0; i < n; i++) {
59                 if (this.cursor+i < this.text.length) {
60                     pulled += this.text.charAt(this.cursor+i);
61                 } else {
62                     eof =true;
63                     return '\0';
64                     
65                     
66                 }
67             }
68             
69             this.cursor += n;
70             return pulled;
71            
72         }
73     }
74 }