Lines Matching refs:s

26 #define	YYCURSOR    s->cursor
27 #define YYLIMIT s->limit
28 #define YYMARKER s->marker
29 #define YYCTXMARKER s->ctxmarker
31 #define YYGETCONDITION() s->state
32 #define YYSETCONDITION(yystate) s->state = yystate
43 if (s->utf8_invalid) { \
51 #define PHP_JSON_SCANNER_COPY_ESC() php_json_scanner_copy_string(s, 0)
52 #define PHP_JSON_SCANNER_COPY_UTF() php_json_scanner_copy_string(s, 5)
53 #define PHP_JSON_SCANNER_COPY_UTF_SP() php_json_scanner_copy_string(s, 11)
58 static void php_json_scanner_copy_string(php_json_scanner *s, int esc_size)
60 size_t len = s->cursor - s->str_start - esc_size - 1;
62 memcpy(s->pstr, s->str_start, len);
63 s->pstr += len;
81 static int php_json_ucs2_to_int_ex(php_json_scanner *s, int size, int start)
84 php_json_ctype *pc = s->cursor - start;
91 static int php_json_ucs2_to_int(php_json_scanner *s, int size)
93 return php_json_ucs2_to_int_ex(s, size, 1);
96 void php_json_scanner_init(php_json_scanner *s, char *str, size_t str_len, int options)
98 s->cursor = (php_json_ctype *) str;
99 s->limit = (php_json_ctype *) str + str_len;
100 s->options = options;
104 int php_json_scan(php_json_scanner *s)
106 ZVAL_NULL(&s->value);
109 s->token = s->cursor;
161 ZVAL_NULL(&s->value);
165 ZVAL_TRUE(&s->value);
169 ZVAL_FALSE(&s->value);
173 zend_bool bigint = 0, negative = s->token[0] == '-';
174 size_t digits = (size_t) (s->cursor - s->token - negative);
177 int cmp = strncmp((char *) (s->token + negative), LONG_MIN_DIGITS, PHP_JSON_INT_MAX_LENGTH);
186 ZVAL_LONG(&s->value, ZEND_STRTOL((char *) s->token, NULL, 10));
188 } else if (s->options & PHP_JSON_BIGINT_AS_STRING) {
189 ZVAL_STRINGL(&s->value, (char *) s->token, s->cursor - s->token);
192 ZVAL_DOUBLE(&s->value, zend_strtod((char *) s->token, NULL));
197 ZVAL_DOUBLE(&s->value, zend_strtod((char *) s->token, NULL));
202 if (s->limit < s->cursor) {
205 s->errcode = PHP_JSON_ERROR_CTRL_CHAR;
210 s->str_start = s->cursor;
211 s->str_esc = 0;
212 s->utf8_invalid = 0;
213 s->utf8_invalid_count = 0;
217 s->errcode = PHP_JSON_ERROR_CTRL_CHAR;
221 s->errcode = PHP_JSON_ERROR_SYNTAX;
225 s->errcode = PHP_JSON_ERROR_UTF8;
230 s->errcode = PHP_JSON_ERROR_CTRL_CHAR;
234 s->str_esc += 5;
238 s->str_esc += 4;
242 s->str_esc += 3;
246 s->str_esc += 8;
250 s->errcode = PHP_JSON_ERROR_UTF16;
254 s->str_esc++;
258 s->errcode = PHP_JSON_ERROR_SYNTAX;
263 size_t len = s->cursor - s->str_start - s->str_esc - 1 + s->utf8_invalid_count;
266 ZVAL_EMPTY_STRING(&s->value);
271 ZVAL_STR(&s->value, str);
272 if (s->str_esc || s->utf8_invalid) {
273 s->pstr = (php_json_ctype *) Z_STRVAL(s->value);
274 s->cursor = s->str_start;
277 memcpy(Z_STRVAL(s->value), s->str_start, len);
284 if (s->options & (PHP_JSON_INVALID_UTF8_IGNORE | PHP_JSON_INVALID_UTF8_SUBSTITUTE)) {
285 if (s->options & PHP_JSON_INVALID_UTF8_SUBSTITUTE) {
286 if (s->utf8_invalid_count > INT_MAX - 2) {
287 s->errcode = PHP_JSON_ERROR_UTF8;
290 s->utf8_invalid_count += 2;
292 s->utf8_invalid_count--;
294 s->utf8_invalid = 1;
297 s->errcode = PHP_JSON_ERROR_UTF8;
302 int utf16 = php_json_ucs2_to_int(s, 2);
304 *(s->pstr++) = (char) utf16;
305 s->str_start = s->cursor;
309 int utf16 = php_json_ucs2_to_int(s, 3);
311 *(s->pstr++) = (char) (0xc0 | (utf16 >> 6));
312 *(s->pstr++) = (char) (0x80 | (utf16 & 0x3f));
313 s->str_start = s->cursor;
317 int utf16 = php_json_ucs2_to_int(s, 4);
319 *(s->pstr++) = (char) (0xe0 | (utf16 >> 12));
320 *(s->pstr++) = (char) (0x80 | ((utf16 >> 6) & 0x3f));
321 *(s->pstr++) = (char) (0x80 | (utf16 & 0x3f));
322 s->str_start = s->cursor;
327 utf16_hi = php_json_ucs2_to_int(s, 4);
328 utf16_lo = php_json_ucs2_to_int_ex(s, 4, 7);
331 *(s->pstr++) = (char) (0xf0 | (utf32 >> 18));
332 *(s->pstr++) = (char) (0x80 | ((utf32 >> 12) & 0x3f));
333 *(s->pstr++) = (char) (0x80 | ((utf32 >> 6) & 0x3f));
334 *(s->pstr++) = (char) (0x80 | (utf32 & 0x3f));
335 s->str_start = s->cursor;
341 switch (*s->cursor) {
359 esc = *s->cursor;
362 s->errcode = PHP_JSON_ERROR_SYNTAX;
365 *(s->pstr++) = esc;
367 s->str_start = s->cursor;
376 if (s->utf8_invalid) {
378 if (s->options & PHP_JSON_INVALID_UTF8_SUBSTITUTE) {
379 *(s->pstr++) = (char) (0xe0 | (0xfffd >> 12));
380 *(s->pstr++) = (char) (0x80 | ((0xfffd >> 6) & 0x3f));
381 *(s->pstr++) = (char) (0x80 | (0xfffd & 0x3f));
383 s->str_start = s->cursor;
390 s->errcode = PHP_JSON_ERROR_SYNTAX;