* The next token in the input stream is known to be a string; lex it. */
| 677 | * The next token in the input stream is known to be a string; lex it. |
| 678 | */ |
| 679 | static inline JsonParseErrorType |
| 680 | json_lex_string(JsonLexContext *lex) |
| 681 | { |
| 682 | char *s; |
| 683 | int len; |
| 684 | int hi_surrogate = -1; |
| 685 | |
| 686 | if (lex->strval != NULL) |
| 687 | resetStringInfo(lex->strval); |
| 688 | |
| 689 | Assert(lex->input_length > 0); |
| 690 | s = lex->token_start; |
| 691 | len = lex->token_start - lex->input; |
| 692 | for (;;) |
| 693 | { |
| 694 | s++; |
| 695 | len++; |
| 696 | /* Premature end of the string. */ |
| 697 | if (len >= lex->input_length) |
| 698 | { |
| 699 | lex->token_terminator = s; |
| 700 | return JSON_INVALID_TOKEN; |
| 701 | } |
| 702 | else if (*s == '"') |
| 703 | break; |
| 704 | else if ((unsigned char) *s < 32) |
| 705 | { |
| 706 | /* Per RFC4627, these characters MUST be escaped. */ |
| 707 | /* Since *s isn't printable, exclude it from the context string */ |
| 708 | lex->token_terminator = s; |
| 709 | return JSON_ESCAPING_REQUIRED; |
| 710 | } |
| 711 | else if (*s == '\\') |
| 712 | { |
| 713 | /* OK, we have an escape character. */ |
| 714 | s++; |
| 715 | len++; |
| 716 | if (len >= lex->input_length) |
| 717 | { |
| 718 | lex->token_terminator = s; |
| 719 | return JSON_INVALID_TOKEN; |
| 720 | } |
| 721 | else if (*s == 'u') |
| 722 | { |
| 723 | int i; |
| 724 | int ch = 0; |
| 725 | |
| 726 | for (i = 1; i <= 4; i++) |
| 727 | { |
| 728 | s++; |
| 729 | len++; |
| 730 | if (len >= lex->input_length) |
| 731 | { |
| 732 | lex->token_terminator = s; |
| 733 | return JSON_INVALID_TOKEN; |
| 734 | } |
| 735 | else if (*s >= '0' && *s <= '9') |
| 736 | ch = (ch * 16) + (*s - '0'); |
no test coverage detected