1 | <?php |
||
45 | class StringInputStream implements InputStream |
||
46 | { |
||
47 | /** |
||
48 | * The string data we're parsing. |
||
49 | */ |
||
50 | private $data; |
||
51 | |||
52 | /** |
||
53 | * The current integer byte position we are in $data |
||
54 | */ |
||
55 | private $char; |
||
56 | |||
57 | /** |
||
58 | * Length of $data; when $char === $data, we are at the end-of-file. |
||
59 | */ |
||
60 | private $EOF; |
||
61 | |||
62 | /** |
||
63 | * Parse errors. |
||
64 | */ |
||
65 | public $errors = array(); |
||
66 | |||
67 | /** |
||
68 | * Create a new InputStream wrapper. |
||
69 | * |
||
70 | * @param string $data Data to parse |
||
71 | * @param string $encoding The encoding to use for the data. |
||
72 | * @param string $debug A fprintf format to use to echo the data on stdout. |
||
73 | */ |
||
74 | public function __construct($data, $encoding = 'UTF-8', $debug = '') |
||
92 | |||
93 | public function __toString() |
||
97 | |||
98 | /** |
||
99 | * Replace linefeed characters according to the spec. |
||
100 | */ |
||
101 | protected function replaceLinefeeds($data) |
||
118 | |||
119 | /** |
||
120 | * Returns the current line that the tokenizer is at. |
||
121 | */ |
||
122 | public function currentLine() |
||
131 | |||
132 | /** |
||
133 | * |
||
134 | * @deprecated |
||
135 | * |
||
136 | */ |
||
137 | public function getCurrentLine() |
||
141 | |||
142 | /** |
||
143 | * Returns the current column of the current line that the tokenizer is at. |
||
144 | * |
||
145 | * Newlines are column 0. The first char after a newline is column 1. |
||
146 | * |
||
147 | * @return int The column number. |
||
148 | */ |
||
149 | public function columnOffset() |
||
174 | |||
175 | /** |
||
176 | * |
||
177 | * @deprecated |
||
178 | * |
||
179 | */ |
||
180 | public function getColumnOffset() |
||
184 | |||
185 | /** |
||
186 | * Get the current character. |
||
187 | * |
||
188 | * @return string The current character. |
||
189 | */ |
||
190 | public function current() |
||
194 | |||
195 | /** |
||
196 | * Advance the pointer. |
||
197 | * This is part of the Iterator interface. |
||
198 | */ |
||
199 | public function next() |
||
203 | |||
204 | /** |
||
205 | * Rewind to the start of the string. |
||
206 | */ |
||
207 | public function rewind() |
||
211 | |||
212 | /** |
||
213 | * Is the current pointer location valid. |
||
214 | * |
||
215 | * @return bool Is the current pointer location valid. |
||
216 | */ |
||
217 | public function valid() |
||
225 | |||
226 | /** |
||
227 | * Get all characters until EOF. |
||
228 | * |
||
229 | * This reads to the end of the file, and sets the read marker at the |
||
230 | * end of the file. |
||
231 | * |
||
232 | * @note This performs bounds checking |
||
233 | * |
||
234 | * @return string Returns the remaining text. If called when the InputStream is |
||
235 | * already exhausted, it returns an empty string. |
||
236 | */ |
||
237 | public function remainingChars() |
||
248 | |||
249 | /** |
||
250 | * Read to a particular match (or until $max bytes are consumed). |
||
251 | * |
||
252 | * This operates on byte sequences, not characters. |
||
253 | * |
||
254 | * Matches as far as possible until we reach a certain set of bytes |
||
255 | * and returns the matched substring. |
||
256 | * |
||
257 | * @param string $bytes |
||
258 | * Bytes to match. |
||
259 | * @param int $max |
||
260 | * Maximum number of bytes to scan. |
||
261 | * @return mixed Index or false if no match is found. You should use strong |
||
262 | * equality when checking the result, since index could be 0. |
||
263 | */ |
||
264 | public function charsUntil($bytes, $max = null) |
||
281 | |||
282 | /** |
||
283 | * Returns the string so long as $bytes matches. |
||
284 | * |
||
285 | * Matches as far as possible with a certain set of bytes |
||
286 | * and returns the matched substring. |
||
287 | * |
||
288 | * @param string $bytes |
||
289 | * A mask of bytes to match. If ANY byte in this mask matches the |
||
290 | * current char, the pointer advances and the char is part of the |
||
291 | * substring. |
||
292 | * @param int $max |
||
293 | * The max number of chars to read. |
||
294 | * |
||
295 | * @return string |
||
296 | */ |
||
297 | public function charsWhile($bytes, $max = null) |
||
313 | |||
314 | /** |
||
315 | * Unconsume characters. |
||
316 | * |
||
317 | * @param int $howMany |
||
318 | * The number of characters to unconsume. |
||
319 | */ |
||
320 | public function unconsume($howMany = 1) |
||
326 | |||
327 | /** |
||
328 | * Look ahead without moving cursor. |
||
329 | */ |
||
330 | public function peek() |
||
338 | |||
339 | public function key() |
||
343 | } |
||
344 |