5151#define PHP_JSON_INT_MAX_LENGTH (MAX_LENGTH_OF_LONG - 1 )
5252
5353#define PHP_JSON_TOKEN_LENGTH () ((size_t ) (s->cursor - s->token))
54- #define PHP_JSON_TOKEN_LOCATION (location ) (s)->errloc.location
5554
5655static void php_json_scanner_copy_string (php_json_scanner *s, size_t esc_size)
5756{
@@ -96,10 +95,8 @@ void php_json_scanner_init(php_json_scanner *s, const char *str, size_t str_len,
9695 s->cursor = (php_json_ctype *) str;
9796 s->limit = (php_json_ctype *) str + str_len;
9897 s->options = options;
99- PHP_JSON_TOKEN_LOCATION (first_column) = 1 ;
100- PHP_JSON_TOKEN_LOCATION (first_line) = 1 ;
101- PHP_JSON_TOKEN_LOCATION (last_column) = 1 ;
102- PHP_JSON_TOKEN_LOCATION (last_line) = 1 ;
98+ s->line = 1 ;
99+ s->line_start = (php_json_ctype *) str;
103100 PHP_JSON_CONDITION_SET (JS );
104101}
105102
@@ -108,8 +105,6 @@ int php_json_scan(php_json_scanner *s)
108105 ZVAL_NULL (&s->value );
109106
110107std:
111- PHP_JSON_TOKEN_LOCATION (first_column) = s->errloc .last_column ;
112- PHP_JSON_TOKEN_LOCATION (first_line) = s->errloc .last_line ;
113108 s->token = s->cursor ;
114109
115110/* !re2c
@@ -155,49 +150,27 @@ std:
155150 UTF16_3 = UTFPREF ( ( ( HEXC | [efEF] ) HEX ) | ( [dD] HEX7 ) ) HEX{2} ;
156151 UTF16_4 = UTFPREF [dD] [89abAB] HEX{2} UTFPREF [dD] [c-fC-F] HEX{2} ;
157152
158- <JS>"{" {
159- PHP_JSON_TOKEN_LOCATION(last_column)++;
160- return '{';
161- }
162- <JS>"}" {
163- PHP_JSON_TOKEN_LOCATION(last_column)++;
164- return '}';
165- }
166- <JS>"[" {
167- PHP_JSON_TOKEN_LOCATION(last_column)++;
168- return '[';
169- }
170- <JS>"]" {
171- PHP_JSON_TOKEN_LOCATION(last_column)++;
172- return ']';
173- }
174- <JS>":" {
175- PHP_JSON_TOKEN_LOCATION(last_column)++;
176- return ':';
177- }
178- <JS>"," {
179- PHP_JSON_TOKEN_LOCATION(last_column)++;
180- return ',';
181- }
153+ <JS>"{" { return '{'; }
154+ <JS>"}" { return '}'; }
155+ <JS>"[" { return '['; }
156+ <JS>"]" { return ']'; }
157+ <JS>":" { return ':'; }
158+ <JS>"," { return ','; }
182159 <JS>"null" {
183- PHP_JSON_TOKEN_LOCATION(last_column) += 4;
184160 ZVAL_NULL(&s->value);
185161 return PHP_JSON_T_NUL;
186162 }
187163 <JS>"true" {
188- PHP_JSON_TOKEN_LOCATION(last_column) += 4;
189164 ZVAL_TRUE(&s->value);
190165 return PHP_JSON_T_TRUE;
191166 }
192167 <JS>"false" {
193- PHP_JSON_TOKEN_LOCATION(last_column) += 5;
194168 ZVAL_FALSE(&s->value);
195169 return PHP_JSON_T_FALSE;
196170 }
197171 <JS>INT {
198172 bool bigint = 0, negative = s->token[0] == '-';
199173 size_t digits = PHP_JSON_TOKEN_LENGTH();
200- PHP_JSON_TOKEN_LOCATION(last_column) += digits;
201174 digits -= negative;
202175 if (digits >= PHP_JSON_INT_MAX_LENGTH) {
203176 if (digits == PHP_JSON_INT_MAX_LENGTH) {
@@ -221,19 +194,15 @@ std:
221194 }
222195 }
223196 <JS>FLOAT|EXP {
224- PHP_JSON_TOKEN_LOCATION(last_column) += PHP_JSON_TOKEN_LENGTH();
225197 ZVAL_DOUBLE(&s->value, zend_strtod((char *) s->token, NULL));
226198 return PHP_JSON_T_DOUBLE;
227199 }
228200 <JS>NL {
229- PHP_JSON_TOKEN_LOCATION(last_line)++;
230- PHP_JSON_TOKEN_LOCATION(last_column) = 1;
231- goto std;
232- }
233- <JS>WS {
234- PHP_JSON_TOKEN_LOCATION(last_column) += PHP_JSON_TOKEN_LENGTH();
201+ s->line++;
202+ s->line_start = s->cursor;
235203 goto std;
236204 }
205+ <JS>WS { goto std; }
237206 <JS>EOI {
238207 if (s->limit < s->cursor) {
239208 return PHP_JSON_T_EOI;
243212 }
244213 }
245214 <JS>["] {
246- PHP_JSON_TOKEN_LOCATION(last_column)++;
247215 s->str_start = s->cursor;
248216 s->str_esc = 0;
249217 s->utf8_invalid = 0;
@@ -275,22 +243,18 @@ std:
275243 return PHP_JSON_T_ERROR;
276244 }
277245 <STR_P1>UTF16_1 {
278- PHP_JSON_TOKEN_LOCATION(last_column) += 1;
279246 s->str_esc += 5;
280247 PHP_JSON_CONDITION_GOTO(STR_P1);
281248 }
282249 <STR_P1>UTF16_2 {
283- PHP_JSON_TOKEN_LOCATION(last_column) += 1;
284250 s->str_esc += 4;
285251 PHP_JSON_CONDITION_GOTO(STR_P1);
286252 }
287253 <STR_P1>UTF16_3 {
288- PHP_JSON_TOKEN_LOCATION(last_column) += 1;
289254 s->str_esc += 3;
290255 PHP_JSON_CONDITION_GOTO(STR_P1);
291256 }
292257 <STR_P1>UTF16_4 {
293- PHP_JSON_TOKEN_LOCATION(last_column) += 1;
294258 s->str_esc += 8;
295259 PHP_JSON_CONDITION_GOTO(STR_P1);
296260 }
299263 return PHP_JSON_T_ERROR;
300264 }
301265 <STR_P1>ESC {
302- PHP_JSON_TOKEN_LOCATION(last_column) += 2;
303266 s->str_esc++;
304267 PHP_JSON_CONDITION_GOTO(STR_P1);
305268 }
308271 return PHP_JSON_T_ERROR;
309272 }
310273 <STR_P1>["] {
311- PHP_JSON_TOKEN_LOCATION(last_column)++;
312274 zend_string *str;
313275 size_t len = (size_t)(s->cursor - s->str_start - s->str_esc - 1 + s->utf8_invalid_count);
314276 if (len == 0) {
@@ -329,22 +291,7 @@ std:
329291 return PHP_JSON_T_STRING;
330292 }
331293 }
332- <STR_P1>UTF8_1 {
333- PHP_JSON_TOKEN_LOCATION(last_column)++;
334- PHP_JSON_CONDITION_GOTO(STR_P1);
335- }
336- <STR_P1>UTF8_2 {
337- PHP_JSON_TOKEN_LOCATION(last_column) += 1;
338- PHP_JSON_CONDITION_GOTO(STR_P1);
339- }
340- <STR_P1>UTF8_3 {
341- PHP_JSON_TOKEN_LOCATION(last_column) += 1;
342- PHP_JSON_CONDITION_GOTO(STR_P1);
343- }
344- <STR_P1>UTF8_4 {
345- PHP_JSON_TOKEN_LOCATION(last_column) += 1;
346- PHP_JSON_CONDITION_GOTO(STR_P1);
347- }
294+ <STR_P1>UTF8 { PHP_JSON_CONDITION_GOTO(STR_P1); }
348295 <STR_P1>ANY {
349296 if (s->options & (PHP_JSON_INVALID_UTF8_IGNORE | PHP_JSON_INVALID_UTF8_SUBSTITUTE)) {
350297 if (s->options & PHP_JSON_INVALID_UTF8_SUBSTITUTE) {
0 commit comments