a68d2a7aa1ff32477d5be8bfd7a63ddf012f8bdb
[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         int length;
24         
25         public TextStream (string text = "")
26         {
27             
28             
29             this.text = text;
30             this.length = text.char_count()
31             this.cursor = 0;
32         }
33         
34         public char look(int n = 0)
35         {
36                  
37             if (this.cursor+n < 0 || this.cursor+n >= this.length) {
38                 return '\0';
39             }
40             return  this.get_char(this.cursor+n);
41         },
42         
43         public bool lookEOF(int n = 0)
44         {
45             if (this.cursor+n < 0 || this.cursor+n >= this.length)) {
46                 return true;
47             }
48             return  false
49         },
50         
51         /**
52          * @param n - number of characters to return..
53          */
54         public string next(int n = 1)
55         {
56             
57             if (n < 1) { //?? eof???
58                 return '\0';
59             }
60                 
61             string pulled;
62             var i = 0;
63             while (i < n) {
64                 if (this.cursor+i < this.length) {
65                     pulled += this.text.get_char(this.cursor+i);
66                     i += pulled.to_string.length();
67                 } else {
68                      
69                     return "";
70                     
71                     
72                 }
73             }
74             
75             this.cursor += n;
76             return pulled;
77            
78         }
79     }
80 }