47 bool *num_err,
int *total_len);
58 NULL, NULL, NULL, NULL, NULL,
59 NULL, NULL, NULL, NULL, NULL
91 #define JSON_ALPHANUMERIC_CHAR(c) \
92 (((c) >= 'a' && (c) <= 'z') || \
93 ((c) >= 'A' && (c) <= 'Z') || \
94 ((c) >= '0' && (c) <= '9') || \
132 return (!numeric_error) && (total_len == dummy_lex.
input_length);
323 if ((ostart != NULL || oend != NULL) && lex->
strval != NULL)
337 (*ostart) (sem->
semstate, fname, isnull);
354 (*oend) (sem->
semstate, fname, isnull);
528 while (len < lex->input_length &&
529 (*s ==
' ' || *s ==
'\t' || *s ==
'\n' || *s ==
'\r'))
650 if (memcmp(s,
"true", 4) == 0)
652 else if (memcmp(s,
"null", 4) == 0)
657 else if (p - s == 5 && memcmp(s,
"false", 5) == 0)
676 int hi_surrogate = -1;
696 else if ((
unsigned char) *s < 32)
718 for (
i = 1;
i <= 4;
i++)
727 else if (*s >=
'0' && *s <=
'9')
728 ch = (ch * 16) + (*s -
'0');
729 else if (*s >=
'a' && *s <=
'f')
730 ch = (ch * 16) + (*s -
'a') + 10;
731 else if (*s >=
'A' && *s <=
'F')
732 ch = (ch * 16) + (*s -
'A') + 10;
746 if (hi_surrogate != -1)
753 if (hi_surrogate == -1)
759 if (hi_surrogate != -1)
801 else if (ch <= 0x007f)
811 else if (lex->
strval != NULL)
813 if (hi_surrogate != -1)
845 else if (strchr(
"\"\\/bfnrt", *s) == NULL)
859 else if (lex->
strval != NULL)
861 if (hi_surrogate != -1)
868 if (hi_surrogate != -1)
907 bool *num_err,
int *total_len)
916 if (len < lex->input_length && *s ==
'0')
921 else if (len < lex->input_length && *s >=
'1' && *s <=
'9')
927 }
while (len < lex->input_length && *s >=
'0' && *s <=
'9');
933 if (len < lex->input_length && *s ==
'.')
945 }
while (len < lex->input_length && *s >=
'0' && *s <=
'9');
950 if (len < lex->input_length && (*s ==
'e' || *s ==
'E'))
954 if (len < lex->input_length && (*s ==
'+' || *s ==
'-'))
967 }
while (len < lex->input_length && *s >=
'0' && *s <=
'9');
979 if (total_len != NULL)
1052 char *token =
palloc(toklen + 1);
1055 token[toklen] =
'\0';
1075 return psprintf(
_(
"Escape sequence \"\\%s\" is invalid."),
1078 return psprintf(
_(
"Character with value 0x%02x must be escaped."),
1081 return psprintf(
_(
"Expected end of input, but found \"%s\"."),
1084 return psprintf(
_(
"Expected array element or \"]\", but found \"%s\"."),
1087 return psprintf(
_(
"Expected \",\" or \"]\", but found \"%s\"."),
1090 return psprintf(
_(
"Expected \":\", but found \"%s\"."),
1093 return psprintf(
_(
"Expected JSON value, but found \"%s\"."),
1096 return _(
"The input string ended unexpectedly.");
1098 return psprintf(
_(
"Expected string or \"}\", but found \"%s\"."),
1101 return psprintf(
_(
"Expected \",\" or \"}\", but found \"%s\"."),
1104 return psprintf(
_(
"Expected string, but found \"%s\"."),
1107 return psprintf(
_(
"Token \"%s\" is invalid."),
1110 return _(
"\\u0000 cannot be converted to text.");
1112 return _(
"\"\\u\" must be followed by four hexadecimal digits.");
1115 return _(
"Unicode escape values cannot be used for code point values above 007F when the encoding is not UTF8.");
1117 return _(
"Unicode high surrogate must not follow a high surrogate.");
1119 return _(
"Unicode low surrogate must follow a high surrogate.");
1127 elog(
ERROR,
"unexpected json parse error type: %d", (
int)
error);
#define unconstify(underlying_type, expr)
@ 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)
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)
void(* json_struct_action)(void *state)
@ JSON_EXPECTED_ARRAY_FIRST
@ JSON_UNICODE_HIGH_SURROGATE
@ JSON_EXPECTED_OBJECT_FIRST
@ JSON_UNICODE_CODE_POINT_ZERO
@ JSON_UNICODE_ESCAPE_FORMAT
@ JSON_EXPECTED_OBJECT_NEXT
@ JSON_EXPECTED_ARRAY_NEXT
@ JSON_UNICODE_HIGH_ESCAPE
@ JSON_UNICODE_LOW_SURROGATE
void(* json_ofield_action)(void *state, char *fname, bool isnull)
@ JSON_TOKEN_OBJECT_START
void(* json_scalar_action)(void *state, char *token, JsonTokenType tokentype)
void(* json_aelem_action)(void *state, bool isnull)
Assert(fmt[strlen(fmt) - 1] !='\n')
void pg_unicode_to_server(pg_wchar c, unsigned char *s)
char * pstrdup(const char *in)
void * palloc0(Size size)
#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 char *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
int pg_encoding_mblen_bounded(int encoding, const char *mbstr)
unsigned char * unicode_to_utf8(pg_wchar c, unsigned char *utf8string)
int pg_utf_mblen(const unsigned char *s)