MCPcopy Create free account
hub / github.com/apache/cloudberry / json_lex_string

Function json_lex_string

src/common/jsonapi.c:679–885  ·  view source on GitHub ↗

* The next token in the input stream is known to be a string; lex it. */

Source from the content-addressed store, hash-verified

677 * The next token in the input stream is known to be a string; lex it.
678 */
679static inline JsonParseErrorType
680json_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');

Callers 1

json_lexFunction · 0.85

Calls 11

resetStringInfoFunction · 0.85
appendStringInfoStringFunction · 0.85
unicode_to_utf8Function · 0.85
pg_utf_mblenFunction · 0.85
appendBinaryStringInfoFunction · 0.85
appendStringInfoCharFunction · 0.85
is_utf16_surrogate_firstFunction · 0.50
pg_unicode_to_serverFunction · 0.50

Tested by

no test coverage detected