JSDOC/TextStream.vala
authorAlan Knowles <alan@roojs.com>
Thu, 10 Sep 2015 09:45:28 +0000 (17:45 +0800)
committerAlan Knowles <alan@roojs.com>
Thu, 10 Sep 2015 09:45:28 +0000 (17:45 +0800)
JSDOC/TextStream.vala

index e69de29..277b518 100644 (file)
@@ -0,0 +1,62 @@
+//<script type="text/javscript">
+
+
+/**
+       @constructor
+*/
+namespace JSDOC {
+    
+    public class TextStreamChar : Object {
+        public char c;
+        public bool eof;
+        public TextStreamChar(char val, bool eof=false) {
+            this.c = val;
+            this.eof = eof;
+        }
+    }
+    
+    public class TextStream : Object {
+        
+        string text;
+        int cursor;
+        
+        public TextStream (string text = "")
+        {
+            
+            
+            this.text = text;
+            this.cursor = 0;
+        }
+        
+        public char look(int n = 0) {
+                
+                
+            if (this.cursor+n < 0 || this.cursor+n >= this.text.length) {
+                var result = new String("");
+                result.eof = true;
+                return result;
+            }
+            return this.text.charAt(this.cursor+n);
+        },
+    
+            next : function(n) {
+                if (typeof n == "undefined") n = 1;
+                if (n < 1) return null;
+                
+                var pulled = "";
+                for (var i = 0; i < n; i++) {
+                    if (this.cursor+i < this.text.length) {
+                        pulled += this.text.charAt(this.cursor+i);
+                    }
+                    else {
+                        var result = new String("");
+                        result.eof = true;
+                        return result;
+                    }
+                }
+    
+                this.cursor += n;
+                return pulled;
+            }
+    });
\ No newline at end of file