48 bool *num_err,
int *total_len);
59 NULL, NULL, NULL, NULL, NULL,
60 NULL, NULL, NULL, NULL, NULL
92 #define JSON_ALPHANUMERIC_CHAR(c) \
93 (((c) >= 'a' && (c) <= 'z') || \
94 ((c) >= 'A' && (c) <= 'Z') || \
95 ((c) >= '0' && (c) <= '9') || \
133 return (!numeric_error) && (total_len == dummy_lex.
input_length);
324 if ((ostart != NULL || oend != NULL) && lex->
strval != NULL)
339 result = (*ostart) (sem->
semstate, fname, isnull);
360 result = (*oend) (sem->
semstate, fname, isnull);
455 result = (*astart) (sem->
semstate, isnull);
478 result = (*aend) (sem->
semstate, isnull);
560 while (s < end && (*s ==
' ' || *s ==
'\t' || *s ==
'\n' || *s ==
'\r'))
680 if (memcmp(s,
"true", 4) == 0)
682 else if (memcmp(s,
"null", 4) == 0)
687 else if (p - s == 5 && memcmp(s,
"false", 5) == 0)
714 int hi_surrogate = -1;
717 #define FAIL_AT_CHAR_START(code) \
719 lex->token_terminator = s; \
722 #define FAIL_AT_CHAR_END(code) \
724 lex->token_terminator = \
725 s + pg_encoding_mblen_bounded(lex->input_encoding, s); \
753 for (
i = 1;
i <= 4;
i++)
758 else if (*s >=
'0' && *s <=
'9')
759 ch = (ch * 16) + (*s -
'0');
760 else if (*s >=
'a' && *s <=
'f')
761 ch = (ch * 16) + (*s -
'a') + 10;
762 else if (*s >=
'A' && *s <=
'F')
763 ch = (ch * 16) + (*s -
'A') + 10;
774 if (hi_surrogate != -1)
781 if (hi_surrogate == -1)
787 if (hi_surrogate != -1)
826 else if (ch <= 0x007f)
836 else if (lex->
strval != NULL)
838 if (hi_surrogate != -1)
874 else if (strchr(
"\"\\/bfnrt", *s) == NULL)
891 if (hi_surrogate != -1)
898 while (p < end -
sizeof(
Vector8) &&
906 if (*p ==
'\\' || *p ==
'"')
908 else if ((
unsigned char) *p <= 31)
931 if (hi_surrogate != -1)
942 #undef FAIL_AT_CHAR_START
943 #undef FAIL_AT_CHAR_END
976 bool *num_err,
int *total_len)
985 if (len < lex->input_length && *s ==
'0')
990 else if (len < lex->input_length && *s >=
'1' && *s <=
'9')
996 }
while (len < lex->input_length && *s >=
'0' && *s <=
'9');
1002 if (len < lex->input_length && *s ==
'.')
1014 }
while (len < lex->input_length && *s >=
'0' && *s <=
'9');
1019 if (len < lex->input_length && (*s ==
'e' || *s ==
'E'))
1023 if (len < lex->input_length && (*s ==
'+' || *s ==
'-'))
1036 }
while (len < lex->input_length && *s >=
'0' && *s <=
'9');
1048 if (total_len != NULL)
1051 if (num_err != NULL)
1124 token[toklen] =
'\0';
1144 return psprintf(
_(
"Escape sequence \"\\%s\" is invalid."),
1147 return psprintf(
_(
"Character with value 0x%02x must be escaped."),
1150 return psprintf(
_(
"Expected end of input, but found \"%s\"."),
1153 return psprintf(
_(
"Expected array element or \"]\", but found \"%s\"."),
1156 return psprintf(
_(
"Expected \",\" or \"]\", but found \"%s\"."),
1159 return psprintf(
_(
"Expected \":\", but found \"%s\"."),
1162 return psprintf(
_(
"Expected JSON value, but found \"%s\"."),
1165 return _(
"The input string ended unexpectedly.");
1167 return psprintf(
_(
"Expected string or \"}\", but found \"%s\"."),
1170 return psprintf(
_(
"Expected \",\" or \"}\", but found \"%s\"."),
1173 return psprintf(
_(
"Expected string, but found \"%s\"."),
1176 return psprintf(
_(
"Token \"%s\" is invalid."),
1179 return _(
"\\u0000 cannot be converted to text.");
1181 return _(
"\"\\u\" must be followed by four hexadecimal digits.");
1184 return _(
"Unicode escape values cannot be used for code point values above 007F when the encoding is not UTF8.");
1187 return psprintf(
_(
"Unicode escape value could not be translated to the server's encoding %s."),
1190 return _(
"Unicode high surrogate must not follow a high surrogate.");
1192 return _(
"Unicode low surrogate must follow a high surrogate.");
1203 elog(
ERROR,
"unexpected json parse error type: %d", (
int)
error);
#define unconstify(underlying_type, expr)
elog(ERROR, "%s: %s", p2, msg)
if(TABLE==NULL||TABLE_index==NULL)
@ JSON_PARSE_OBJECT_LABEL
@ JSON_PARSE_OBJECT_START
@ JSON_PARSE_OBJECT_COMMA
static JsonParseErrorType json_lex_string(JsonLexContext *lex)
#define JSON_ALPHANUMERIC_CHAR(c)
static JsonParseErrorType parse_object_field(JsonLexContext *lex, JsonSemAction *sem)
#define FAIL_AT_CHAR_START(code)
JsonLexContext * makeJsonLexContextCstringLen(char *json, int len, int encoding, bool need_escapes)
static JsonParseErrorType parse_array_element(JsonLexContext *lex, JsonSemAction *sem)
static char * extract_token(JsonLexContext *lex)
static JsonTokenType lex_peek(JsonLexContext *lex)
static JsonParseErrorType parse_object(JsonLexContext *lex, JsonSemAction *sem)
char * json_errdetail(JsonParseErrorType error, JsonLexContext *lex)
bool IsValidJsonNumber(const char *str, int len)
static JsonParseErrorType report_parse_error(JsonParseContext ctx, JsonLexContext *lex)
JsonSemAction nullSemAction
static JsonParseErrorType lex_expect(JsonParseContext ctx, JsonLexContext *lex, JsonTokenType token)
JsonParseErrorType pg_parse_json(JsonLexContext *lex, JsonSemAction *sem)
static JsonParseErrorType parse_array(JsonLexContext *lex, JsonSemAction *sem)
static JsonParseErrorType parse_scalar(JsonLexContext *lex, JsonSemAction *sem)
JsonParseErrorType json_lex(JsonLexContext *lex)
JsonParseErrorType json_count_array_elements(JsonLexContext *lex, int *elements)
static JsonParseErrorType json_lex_number(JsonLexContext *lex, char *s, bool *num_err, int *total_len)
#define FAIL_AT_CHAR_END(code)
JsonParseErrorType(* json_struct_action)(void *state)
JsonParseErrorType(* json_aelem_action)(void *state, bool isnull)
@ JSON_EXPECTED_ARRAY_FIRST
@ JSON_UNICODE_HIGH_SURROGATE
@ JSON_EXPECTED_OBJECT_FIRST
@ JSON_UNICODE_CODE_POINT_ZERO
@ JSON_UNICODE_ESCAPE_FORMAT
@ JSON_UNICODE_UNTRANSLATABLE
@ JSON_EXPECTED_OBJECT_NEXT
@ JSON_EXPECTED_ARRAY_NEXT
@ JSON_UNICODE_HIGH_ESCAPE
@ JSON_UNICODE_LOW_SURROGATE
JsonParseErrorType(* json_ofield_action)(void *state, char *fname, bool isnull)
@ JSON_TOKEN_OBJECT_START
JsonParseErrorType(* json_scalar_action)(void *state, char *token, JsonTokenType tokentype)
Assert(fmt[strlen(fmt) - 1] !='\n')
bool pg_unicode_to_server_noerror(pg_wchar c, unsigned char *s)
const char * GetDatabaseEncodingName(void)
char * pstrdup(const char *in)
void * palloc0(Size size)
static bool pg_lfind8_le(uint8 key, uint8 *base, uint32 nelem)
static bool pg_lfind8(uint8 key, uint8 *base, uint32 nelem)
#define MAX_UNICODE_EQUIVALENT_STRING
static pg_wchar surrogate_pair_to_codepoint(pg_wchar first, pg_wchar second)
static bool is_utf16_surrogate_first(pg_wchar c)
static bool is_utf16_surrogate_second(pg_wchar c)
void check_stack_depth(void)
char * psprintf(const char *fmt,...)
StringInfo makeStringInfo(void)
void resetStringInfo(StringInfo str)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
char * prev_token_terminator
json_struct_action array_end
json_struct_action object_start
json_ofield_action object_field_start
json_aelem_action array_element_start
json_scalar_action scalar
json_aelem_action array_element_end
json_struct_action array_start
json_struct_action object_end
json_ofield_action object_field_end
unsigned char * unicode_to_utf8(pg_wchar c, unsigned char *utf8string)
int pg_utf_mblen(const unsigned char *s)