1 | <?php |
||
11 | class Scanner |
||
12 | { |
||
13 | |||
14 | const CHARS_HEX = 'abcdefABCDEF01234567890'; |
||
15 | |||
16 | const CHARS_ALNUM = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890'; |
||
17 | |||
18 | const CHARS_ALPHA = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
||
19 | |||
20 | protected $is; |
||
21 | |||
22 | /** |
||
23 | * @var LoggerInterface |
||
24 | */ |
||
25 | protected $logger; |
||
26 | |||
27 | /** |
||
28 | * Create a new Scanner. |
||
29 | * |
||
30 | * @param InputStream $input An InputStream to be scanned. |
||
31 | * @param LoggerInterface $logger |
||
32 | */ |
||
33 | 126 | public function __construct(InputStream $input, LoggerInterface $logger = null) |
|
38 | |||
39 | /** |
||
40 | * Get the current position. |
||
41 | * |
||
42 | * @return int The current intiger byte position. |
||
43 | */ |
||
44 | 115 | public function position() |
|
48 | |||
49 | /** |
||
50 | * Take a peek at the next character in the data. |
||
51 | * |
||
52 | * @return string The next character. |
||
53 | */ |
||
54 | 12 | public function peek() |
|
58 | |||
59 | /** |
||
60 | * Get the next character. |
||
61 | * |
||
62 | * Note: This advances the pointer. |
||
63 | */ |
||
64 | 122 | public function next() |
|
68 | |||
69 | /** |
||
70 | * Get the current character. |
||
71 | * |
||
72 | * Note, this does not advance the pointer. |
||
73 | * |
||
74 | * @return mixed Any value can be returned. Typically the current character. |
||
75 | */ |
||
76 | 115 | public function current() |
|
85 | |||
86 | /** |
||
87 | * Silently consume N chars. |
||
88 | */ |
||
89 | 36 | public function consume($count = 1) |
|
95 | |||
96 | /** |
||
97 | * Unconsume some of the data. |
||
98 | * This moves the data pointer backwards. |
||
99 | * |
||
100 | * @param int $howMany |
||
101 | * The number of characters to move the pointer back. |
||
102 | */ |
||
103 | 52 | public function unconsume($howMany = 1) |
|
107 | |||
108 | /** |
||
109 | * Get the next group of that contains hex characters. |
||
110 | * |
||
111 | * Note, along with getting the characters the pointer in the data will be |
||
112 | * moved as well. |
||
113 | * |
||
114 | * @return string The next group that is hex characters. |
||
115 | */ |
||
116 | 4 | public function getHex() |
|
120 | |||
121 | /** |
||
122 | * Get the next group of characters that are ASCII Alpha characters. |
||
123 | * |
||
124 | * Note, along with getting the characters the pointer in the data will be |
||
125 | * moved as well. |
||
126 | * |
||
127 | * @return string The next group of ASCII alpha characters. |
||
128 | */ |
||
129 | 16 | public function getAsciiAlpha() |
|
133 | |||
134 | /** |
||
135 | * Get the next group of characters that are ASCII Alpha characters and numbers. |
||
136 | * |
||
137 | * Note, along with getting the characters the pointer in the data will be |
||
138 | * moved as well. |
||
139 | * |
||
140 | * @return string The next group of ASCII alpha characters and numbers. |
||
141 | */ |
||
142 | 4 | public function getAsciiAlphaNum() |
|
146 | |||
147 | /** |
||
148 | * Get the next group of numbers. |
||
149 | * |
||
150 | * Note, along with getting the characters the pointer in the data will be |
||
151 | * moved as well. |
||
152 | * |
||
153 | * @return string The next group of numbers. |
||
154 | */ |
||
155 | 2 | public function getNumeric() |
|
159 | |||
160 | /** |
||
161 | * Consume whitespace. |
||
162 | * |
||
163 | * Whitespace in HTML5 is: formfeed, tab, newline, space. |
||
164 | */ |
||
165 | 107 | public function whitespace() |
|
169 | |||
170 | /** |
||
171 | * Returns the current line that is being consumed. |
||
172 | * |
||
173 | * @return int The current line number. |
||
174 | */ |
||
175 | 14 | public function currentLine() |
|
179 | |||
180 | /** |
||
181 | * Read chars until something in the mask is encountered. |
||
182 | */ |
||
183 | 102 | public function charsUntil($mask) |
|
187 | |||
188 | /** |
||
189 | * Read chars as long as the mask matches. |
||
190 | */ |
||
191 | 104 | public function charsWhile($mask) |
|
195 | |||
196 | /** |
||
197 | * Returns the current column of the current line that the tokenizer is at. |
||
198 | * |
||
199 | * Newlines are column 0. The first char after a newline is column 1. |
||
200 | * |
||
201 | * @return int The column number. |
||
202 | */ |
||
203 | 14 | public function columnOffset() |
|
207 | |||
208 | /** |
||
209 | * Get all characters until EOF. |
||
210 | * |
||
211 | * This consumes characters until the EOF. |
||
212 | * |
||
213 | * @return int The number of characters remaining. |
||
214 | */ |
||
215 | 1 | public function remainingChars() |
|
219 | } |
||
220 |