277b51874959ad6aba5310a6c9e764d184cb0602
[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                 var result = new String("");
37                 result.eof = true;
38                 return result;
39             }
40             return this.text.charAt(this.cursor+n);
41         },
42     
43             next : function(n) {
44                 if (typeof n == "undefined") n = 1;
45                 if (n < 1) return null;
46                 
47                 var pulled = "";
48                 for (var i = 0; i < n; i++) {
49                     if (this.cursor+i < this.text.length) {
50                         pulled += this.text.charAt(this.cursor+i);
51                     }
52                     else {
53                         var result = new String("");
54                         result.eof = true;
55                         return result;
56                     }
57                 }
58     
59                 this.cursor += n;
60                 return pulled;
61             }
62     });