try to fix some minor dropdown bugs
[potlatch2.git] / org / rxr / actionscript / io / StringReader.as
1 package org.rxr.actionscript.io\r
2 {\r
3         \r
4         public class StringReader\r
5         {\r
6                 private var source: String;\r
7                 private var sourceLength: uint;\r
8                 private var peekCache: String;\r
9                 protected var position: uint = 0;\r
10                         \r
11                 public function get charsAvailable(): uint\r
12                 {\r
13                         return sourceLength - position;\r
14                 }\r
15                                 \r
16                 public function StringReader(string:String="")\r
17                 {\r
18                         source = string;\r
19                         peekCache = source.charAt(0);\r
20                         sourceLength = source.length;\r
21                 }\r
22                 \r
23                 public function peek(offset: int = 0): String\r
24                 {\r
25                         if (offset == 0)\r
26                                 return peekCache;\r
27         \r
28                         return source.charAt(position + offset);\r
29                 }\r
30                 \r
31                 public function peekFor(length: uint, offset:int = 0): String\r
32                 {\r
33                         return source.substr(position + offset, length);\r
34                 }\r
35 \r
36                 public function peekRemaining(): String\r
37                 {\r
38                         return peekFor(charsAvailable);\r
39                 }\r
40 \r
41                 public function read(): String\r
42                 {\r
43                         var val: String = peekCache;\r
44                         forward();\r
45                         return val;\r
46                 }\r
47                 \r
48                 public function readFor(length:uint):String\r
49                 {\r
50                         var pos: uint = position;\r
51                         forwardBy(length);\r
52                         return source.substr(pos, length);\r
53                 }\r
54                 \r
55                 public function readRemaining(): String\r
56                 {\r
57                         return readFor(charsAvailable);\r
58                 }\r
59                                 \r
60                 public function writeChar(char:String):void\r
61                 {\r
62                         source += char;\r
63                         sourceLength = source.length;\r
64                 }               \r
65 \r
66                 public function forward(): void\r
67                 {\r
68                         position++;\r
69                         peekCache = source.charAt(position);\r
70                 }\r
71                 \r
72                 public function forwardBy(num: uint): void\r
73                 {\r
74                         position+=num;\r
75                         peekCache = source.charAt(position);\r
76                 }                       \r
77         }\r
78 }