Lines Matching refs:s

24 #define	YYCURSOR    s->cursor
25 #define YYLIMIT s->limit
26 #define YYMARKER s->marker
27 #define YYCTXMARKER s->ctxmarker
29 #define YYGETCONDITION() s->state
30 #define YYSETCONDITION(yystate) s->state = yystate
41 if (s->utf8_invalid) { \
49 #define PHP_JSON_SCANNER_COPY_ESC() php_json_scanner_copy_string(s, 0)
50 #define PHP_JSON_SCANNER_COPY_UTF() php_json_scanner_copy_string(s, 5)
51 #define PHP_JSON_SCANNER_COPY_UTF_SP() php_json_scanner_copy_string(s, 11)
56 static void php_json_scanner_copy_string(php_json_scanner *s, size_t esc_size)
58 size_t len = (size_t)(s->cursor - s->str_start - esc_size - 1);
60 memcpy(s->pstr, s->str_start, len);
61 s->pstr += len;
79 static int php_json_ucs2_to_int_ex(php_json_scanner *s, int size, int start)
82 php_json_ctype *pc = s->cursor - start;
89 static int php_json_ucs2_to_int(php_json_scanner *s, int size)
91 return php_json_ucs2_to_int_ex(s, size, 1);
94 void php_json_scanner_init(php_json_scanner *s, const char *str, size_t str_len, int options)
96 s->cursor = (php_json_ctype *) str;
97 s->limit = (php_json_ctype *) str + str_len;
98 s->options = options;
102 int php_json_scan(php_json_scanner *s)
104 ZVAL_NULL(&s->value);
107 s->token = s->cursor;
159 ZVAL_NULL(&s->value);
163 ZVAL_TRUE(&s->value);
167 ZVAL_FALSE(&s->value);
171 bool bigint = 0, negative = s->token[0] == '-';
172 size_t digits = (size_t) (s->cursor - s->token - negative);
175 int cmp = strncmp((char *) (s->token + negative), LONG_MIN_DIGITS, PHP_JSON_INT_MAX_LENGTH);
184 ZVAL_LONG(&s->value, ZEND_STRTOL((char *) s->token, NULL, 10));
186 } else if (s->options & PHP_JSON_BIGINT_AS_STRING) {
187 ZVAL_STRINGL(&s->value, (char *) s->token, (size_t)(s->cursor - s->token));
190 ZVAL_DOUBLE(&s->value, zend_strtod((char *) s->token, NULL));
195 ZVAL_DOUBLE(&s->value, zend_strtod((char *) s->token, NULL));
200 if (s->limit < s->cursor) {
203 s->errcode = PHP_JSON_ERROR_CTRL_CHAR;
208 s->str_start = s->cursor;
209 s->str_esc = 0;
210 s->utf8_invalid = 0;
211 s->utf8_invalid_count = 0;
215 s->errcode = PHP_JSON_ERROR_CTRL_CHAR;
219 s->errcode = PHP_JSON_ERROR_SYNTAX;
223 s->errcode = PHP_JSON_ERROR_UTF8;
228 s->errcode = PHP_JSON_ERROR_CTRL_CHAR;
232 s->str_esc += 5;
236 s->str_esc += 4;
240 s->str_esc += 3;
244 s->str_esc += 8;
248 s->errcode = PHP_JSON_ERROR_UTF16;
252 s->str_esc++;
256 s->errcode = PHP_JSON_ERROR_SYNTAX;
261 size_t len = (size_t)(s->cursor - s->str_start - s->str_esc - 1 + s->utf8_invalid_count);
264 ZVAL_EMPTY_STRING(&s->value);
269 ZVAL_STR(&s->value, str);
270 if (s->str_esc || s->utf8_invalid) {
271 s->pstr = (php_json_ctype *) Z_STRVAL(s->value);
272 s->cursor = s->str_start;
275 memcpy(Z_STRVAL(s->value), s->str_start, len);
282 if (s->options & (PHP_JSON_INVALID_UTF8_IGNORE | PHP_JSON_INVALID_UTF8_SUBSTITUTE)) {
283 if (s->options & PHP_JSON_INVALID_UTF8_SUBSTITUTE) {
284 if (s->utf8_invalid_count > INT_MAX - 2) {
285 s->errcode = PHP_JSON_ERROR_UTF8;
288 s->utf8_invalid_count += 2;
290 s->utf8_invalid_count--;
292 s->utf8_invalid = 1;
295 s->errcode = PHP_JSON_ERROR_UTF8;
300 int utf16 = php_json_ucs2_to_int(s, 2);
302 *(s->pstr++) = (unsigned char) utf16;
303 s->str_start = s->cursor;
307 int utf16 = php_json_ucs2_to_int(s, 3);
309 *(s->pstr++) = (unsigned char) (0xc0 | (utf16 >> 6));
310 *(s->pstr++) = (unsigned char) (0x80 | (utf16 & 0x3f));
311 s->str_start = s->cursor;
315 int utf16 = php_json_ucs2_to_int(s, 4);
317 *(s->pstr++) = (unsigned char) (0xe0 | (utf16 >> 12));
318 *(s->pstr++) = (unsigned char) (0x80 | ((utf16 >> 6) & 0x3f));
319 *(s->pstr++) = (unsigned char) (0x80 | (utf16 & 0x3f));
320 s->str_start = s->cursor;
325 utf16_hi = php_json_ucs2_to_int(s, 4);
326 utf16_lo = php_json_ucs2_to_int_ex(s, 4, 7);
329 *(s->pstr++) = (unsigned char) (0xf0 | (utf32 >> 18));
330 *(s->pstr++) = (unsigned char) (0x80 | ((utf32 >> 12) & 0x3f));
331 *(s->pstr++) = (unsigned char) (0x80 | ((utf32 >> 6) & 0x3f));
332 *(s->pstr++) = (unsigned char) (0x80 | (utf32 & 0x3f));
333 s->str_start = s->cursor;
339 switch (*s->cursor) {
357 esc = *s->cursor;
360 s->errcode = PHP_JSON_ERROR_SYNTAX;
363 *(s->pstr++) = esc;
365 s->str_start = s->cursor;
374 if (s->utf8_invalid) {
376 if (s->options & PHP_JSON_INVALID_UTF8_SUBSTITUTE) {
377 *(s->pstr++) = (unsigned char) (0xe0 | (0xfffd >> 12));
378 *(s->pstr++) = (unsigned char) (0x80 | ((0xfffd >> 6) & 0x3f));
379 *(s->pstr++) = (unsigned char) (0x80 | (0xfffd & 0x3f));
381 s->str_start = s->cursor;
388 s->errcode = PHP_JSON_ERROR_SYNTAX;