1 | <?php |
||
42 | class StringInputStream implements InputStream |
||
43 | { |
||
44 | |||
45 | /** |
||
46 | * The string data we're parsing. |
||
47 | */ |
||
48 | private $data; |
||
49 | |||
50 | /** |
||
51 | * The current integer byte position we are in $data |
||
52 | */ |
||
53 | private $char; |
||
54 | |||
55 | /** |
||
56 | * Length of $data; when $char === $data, we are at the end-of-file. |
||
57 | */ |
||
58 | private $EOF; |
||
59 | |||
60 | /** |
||
61 | * Parse errors. |
||
62 | */ |
||
63 | public $errors = array(); |
||
64 | |||
65 | /** |
||
66 | * Create a new InputStream wrapper. |
||
67 | * |
||
68 | * @param $data Data |
||
69 | * to parse |
||
70 | */ |
||
71 | 150 | public function __construct($data, $encoding = 'UTF-8') |
|
85 | |||
86 | /** |
||
87 | * Replace linefeed characters according to the spec. |
||
88 | */ |
||
89 | 150 | protected function replaceLinefeeds($data) |
|
102 | |||
103 | /** |
||
104 | * Returns the current line that the tokenizer is at. |
||
105 | */ |
||
106 | 16 | public function currentLine() |
|
115 | |||
116 | /** |
||
117 | * |
||
118 | * @deprecated |
||
119 | * |
||
120 | */ |
||
121 | public function getCurrentLine() |
||
125 | |||
126 | /** |
||
127 | * Returns the current column of the current line that the tokenizer is at. |
||
128 | * |
||
129 | * Newlines are column 0. The first char after a newline is column 1. |
||
130 | * |
||
131 | * @return int The column number. |
||
132 | */ |
||
133 | 16 | public function columnOffset() |
|
158 | |||
159 | /** |
||
160 | * |
||
161 | * @deprecated |
||
162 | * |
||
163 | */ |
||
164 | public function getColumnOffset() |
||
168 | |||
169 | /** |
||
170 | * Get the current character. |
||
171 | * |
||
172 | * @return string The current character. |
||
173 | */ |
||
174 | 121 | public function current() |
|
178 | |||
179 | /** |
||
180 | * Advance the pointer. |
||
181 | * This is part of the Iterator interface. |
||
182 | */ |
||
183 | 137 | public function next() |
|
187 | |||
188 | /** |
||
189 | * Rewind to the start of the string. |
||
190 | */ |
||
191 | public function rewind() |
||
195 | |||
196 | /** |
||
197 | * Is the current pointer location valid. |
||
198 | * |
||
199 | * @return bool Is the current pointer location valid. |
||
200 | */ |
||
201 | 115 | public function valid() |
|
209 | |||
210 | /** |
||
211 | * Get all characters until EOF. |
||
212 | * |
||
213 | * This reads to the end of the file, and sets the read marker at the |
||
214 | * end of the file. |
||
215 | * |
||
216 | * @note This performs bounds checking |
||
217 | * |
||
218 | * @return string Returns the remaining text. If called when the InputStream is |
||
219 | * already exhausted, it returns an empty string. |
||
220 | */ |
||
221 | 7 | public function remainingChars() |
|
232 | |||
233 | /** |
||
234 | * Read to a particular match (or until $max bytes are consumed). |
||
235 | * |
||
236 | * This operates on byte sequences, not characters. |
||
237 | * |
||
238 | * Matches as far as possible until we reach a certain set of bytes |
||
239 | * and returns the matched substring. |
||
240 | * |
||
241 | * @param string $bytes |
||
242 | * Bytes to match. |
||
243 | * @param int $max |
||
244 | * Maximum number of bytes to scan. |
||
245 | * @return mixed Index or false if no match is found. You should use strong |
||
246 | * equality when checking the result, since index could be 0. |
||
247 | */ |
||
248 | 104 | public function charsUntil($bytes, $max = null) |
|
265 | |||
266 | /** |
||
267 | * Returns the string so long as $bytes matches. |
||
268 | * |
||
269 | * Matches as far as possible with a certain set of bytes |
||
270 | * and returns the matched substring. |
||
271 | * |
||
272 | * @param string $bytes |
||
273 | * A mask of bytes to match. If ANY byte in this mask matches the |
||
274 | * current char, the pointer advances and the char is part of the |
||
275 | * substring. |
||
276 | * @param int $max |
||
277 | * The max number of chars to read. |
||
278 | */ |
||
279 | 118 | public function charsWhile($bytes, $max = null) |
|
295 | |||
296 | /** |
||
297 | * Unconsume characters. |
||
298 | * |
||
299 | * @param int $howMany |
||
300 | * The number of characters to unconsume. |
||
301 | */ |
||
302 | 52 | public function unconsume($howMany = 1) |
|
308 | |||
309 | /** |
||
310 | * Look ahead without moving cursor. |
||
311 | */ |
||
312 | 14 | public function peek() |
|
320 | |||
321 | 117 | public function key() |
|
325 | } |
||
326 |