mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-03-07 19:47:50 +08:00
Reindent json.c and jsonfuncs.c.
This will help in preparation of clean patches for upcoming json work.
This commit is contained in:
parent
6c36f383df
commit
243ee26633
@ -751,11 +751,12 @@ json_lex_string(JsonLexContext *lex)
|
|||||||
report_json_context(lex)));
|
report_json_context(lex)));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For UTF8, replace the escape sequence by the actual utf8
|
* For UTF8, replace the escape sequence by the actual
|
||||||
* character in lex->strval. Do this also for other encodings
|
* utf8 character in lex->strval. Do this also for other
|
||||||
* if the escape designates an ASCII character, otherwise
|
* encodings if the escape designates an ASCII character,
|
||||||
* raise an error. We don't ever unescape a \u0000, since that
|
* otherwise raise an error. We don't ever unescape a
|
||||||
* would result in an impermissible nul byte.
|
* \u0000, since that would result in an impermissible nul
|
||||||
|
* byte.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (ch == 0)
|
if (ch == 0)
|
||||||
@ -771,8 +772,9 @@ json_lex_string(JsonLexContext *lex)
|
|||||||
else if (ch <= 0x007f)
|
else if (ch <= 0x007f)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* This is the only way to designate things like a form feed
|
* This is the only way to designate things like a
|
||||||
* character in JSON, so it's useful in all encodings.
|
* form feed character in JSON, so it's useful in all
|
||||||
|
* encodings.
|
||||||
*/
|
*/
|
||||||
appendStringInfoChar(lex->strval, (char) ch);
|
appendStringInfoChar(lex->strval, (char) ch);
|
||||||
}
|
}
|
||||||
@ -866,7 +868,7 @@ json_lex_string(JsonLexContext *lex)
|
|||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
||||||
errmsg("invalid input syntax for type json"),
|
errmsg("invalid input syntax for type json"),
|
||||||
errdetail("Unicode low surrogate must follow a high surrogate."),
|
errdetail("Unicode low surrogate must follow a high surrogate."),
|
||||||
report_json_context(lex)));
|
report_json_context(lex)));
|
||||||
|
|
||||||
/* Hooray, we found the end of the string! */
|
/* Hooray, we found the end of the string! */
|
||||||
@ -1221,7 +1223,7 @@ datum_to_json(Datum val, bool is_null, StringInfo result,
|
|||||||
{
|
{
|
||||||
char *outputstr;
|
char *outputstr;
|
||||||
text *jsontext;
|
text *jsontext;
|
||||||
bool numeric_error;
|
bool numeric_error;
|
||||||
JsonLexContext dummy_lex;
|
JsonLexContext dummy_lex;
|
||||||
|
|
||||||
if (is_null)
|
if (is_null)
|
||||||
@ -1246,13 +1248,14 @@ datum_to_json(Datum val, bool is_null, StringInfo result,
|
|||||||
break;
|
break;
|
||||||
case TYPCATEGORY_NUMERIC:
|
case TYPCATEGORY_NUMERIC:
|
||||||
outputstr = OidOutputFunctionCall(typoutputfunc, val);
|
outputstr = OidOutputFunctionCall(typoutputfunc, val);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Don't call escape_json here if it's a valid JSON number.
|
* Don't call escape_json here if it's a valid JSON number.
|
||||||
*/
|
*/
|
||||||
dummy_lex.input = *outputstr == '-' ? outputstr + 1 : outputstr;
|
dummy_lex.input = *outputstr == '-' ? outputstr + 1 : outputstr;
|
||||||
dummy_lex.input_length = strlen(dummy_lex.input);
|
dummy_lex.input_length = strlen(dummy_lex.input);
|
||||||
json_lex_number(&dummy_lex, dummy_lex.input, &numeric_error);
|
json_lex_number(&dummy_lex, dummy_lex.input, &numeric_error);
|
||||||
if (! numeric_error)
|
if (!numeric_error)
|
||||||
appendStringInfoString(result, outputstr);
|
appendStringInfoString(result, outputstr);
|
||||||
else
|
else
|
||||||
escape_json(result, outputstr);
|
escape_json(result, outputstr);
|
||||||
@ -1808,34 +1811,34 @@ json_typeof(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
JsonLexContext *lex = makeJsonLexContext(json, false);
|
JsonLexContext *lex = makeJsonLexContext(json, false);
|
||||||
JsonTokenType tok;
|
JsonTokenType tok;
|
||||||
char *type;
|
char *type;
|
||||||
|
|
||||||
/* Lex exactly one token from the input and check its type. */
|
/* Lex exactly one token from the input and check its type. */
|
||||||
json_lex(lex);
|
json_lex(lex);
|
||||||
tok = lex_peek(lex);
|
tok = lex_peek(lex);
|
||||||
switch (tok)
|
switch (tok)
|
||||||
{
|
{
|
||||||
case JSON_TOKEN_OBJECT_START:
|
case JSON_TOKEN_OBJECT_START:
|
||||||
type = "object";
|
type = "object";
|
||||||
break;
|
break;
|
||||||
case JSON_TOKEN_ARRAY_START:
|
case JSON_TOKEN_ARRAY_START:
|
||||||
type = "array";
|
type = "array";
|
||||||
break;
|
break;
|
||||||
case JSON_TOKEN_STRING:
|
case JSON_TOKEN_STRING:
|
||||||
type = "string";
|
type = "string";
|
||||||
break;
|
break;
|
||||||
case JSON_TOKEN_NUMBER:
|
case JSON_TOKEN_NUMBER:
|
||||||
type = "number";
|
type = "number";
|
||||||
break;
|
break;
|
||||||
case JSON_TOKEN_TRUE:
|
case JSON_TOKEN_TRUE:
|
||||||
case JSON_TOKEN_FALSE:
|
case JSON_TOKEN_FALSE:
|
||||||
type = "boolean";
|
type = "boolean";
|
||||||
break;
|
break;
|
||||||
case JSON_TOKEN_NULL:
|
case JSON_TOKEN_NULL:
|
||||||
type = "null";
|
type = "null";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
elog(ERROR, "unexpected json token: %d", tok);
|
elog(ERROR, "unexpected json token: %d", tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
PG_RETURN_TEXT_P(cstring_to_text(type));
|
PG_RETURN_TEXT_P(cstring_to_text(type));
|
||||||
|
@ -106,7 +106,7 @@ typedef struct OkeysState
|
|||||||
int result_size;
|
int result_size;
|
||||||
int result_count;
|
int result_count;
|
||||||
int sent_count;
|
int sent_count;
|
||||||
} OkeysState;
|
} OkeysState;
|
||||||
|
|
||||||
/* state for json_get* functions */
|
/* state for json_get* functions */
|
||||||
typedef struct GetState
|
typedef struct GetState
|
||||||
@ -127,14 +127,14 @@ typedef struct GetState
|
|||||||
bool *pathok;
|
bool *pathok;
|
||||||
int *array_level_index;
|
int *array_level_index;
|
||||||
int *path_level_index;
|
int *path_level_index;
|
||||||
} GetState;
|
} GetState;
|
||||||
|
|
||||||
/* state for json_array_length */
|
/* state for json_array_length */
|
||||||
typedef struct AlenState
|
typedef struct AlenState
|
||||||
{
|
{
|
||||||
JsonLexContext *lex;
|
JsonLexContext *lex;
|
||||||
int count;
|
int count;
|
||||||
} AlenState;
|
} AlenState;
|
||||||
|
|
||||||
/* state for json_each */
|
/* state for json_each */
|
||||||
typedef struct EachState
|
typedef struct EachState
|
||||||
@ -147,7 +147,7 @@ typedef struct EachState
|
|||||||
bool normalize_results;
|
bool normalize_results;
|
||||||
bool next_scalar;
|
bool next_scalar;
|
||||||
char *normalized_scalar;
|
char *normalized_scalar;
|
||||||
} EachState;
|
} EachState;
|
||||||
|
|
||||||
/* state for json_array_elements */
|
/* state for json_array_elements */
|
||||||
typedef struct ElementsState
|
typedef struct ElementsState
|
||||||
@ -157,7 +157,7 @@ typedef struct ElementsState
|
|||||||
TupleDesc ret_tdesc;
|
TupleDesc ret_tdesc;
|
||||||
MemoryContext tmp_cxt;
|
MemoryContext tmp_cxt;
|
||||||
char *result_start;
|
char *result_start;
|
||||||
} ElementsState;
|
} ElementsState;
|
||||||
|
|
||||||
/* state for get_json_object_as_hash */
|
/* state for get_json_object_as_hash */
|
||||||
typedef struct JhashState
|
typedef struct JhashState
|
||||||
@ -168,7 +168,7 @@ typedef struct JhashState
|
|||||||
char *save_json_start;
|
char *save_json_start;
|
||||||
bool use_json_as_text;
|
bool use_json_as_text;
|
||||||
char *function_name;
|
char *function_name;
|
||||||
} JHashState;
|
} JHashState;
|
||||||
|
|
||||||
/* used to build the hashtable */
|
/* used to build the hashtable */
|
||||||
typedef struct JsonHashEntry
|
typedef struct JsonHashEntry
|
||||||
@ -177,7 +177,7 @@ typedef struct JsonHashEntry
|
|||||||
char *val;
|
char *val;
|
||||||
char *json;
|
char *json;
|
||||||
bool isnull;
|
bool isnull;
|
||||||
} JsonHashEntry;
|
} JsonHashEntry;
|
||||||
|
|
||||||
/* these two are stolen from hstore / record_out, used in populate_record* */
|
/* these two are stolen from hstore / record_out, used in populate_record* */
|
||||||
typedef struct ColumnIOData
|
typedef struct ColumnIOData
|
||||||
@ -209,7 +209,7 @@ typedef struct PopulateRecordsetState
|
|||||||
HeapTupleHeader rec;
|
HeapTupleHeader rec;
|
||||||
RecordIOData *my_extra;
|
RecordIOData *my_extra;
|
||||||
MemoryContext fn_mcxt; /* used to stash IO funcs */
|
MemoryContext fn_mcxt; /* used to stash IO funcs */
|
||||||
} PopulateRecordsetState;
|
} PopulateRecordsetState;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SQL function json_object-keys
|
* SQL function json_object-keys
|
||||||
@ -1239,7 +1239,7 @@ json_populate_record(PG_FUNCTION_ARGS)
|
|||||||
if (!type_is_rowtype(argtype))
|
if (!type_is_rowtype(argtype))
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||||
errmsg("first argument of json_populate_record must be a row type")));
|
errmsg("first argument of json_populate_record must be a row type")));
|
||||||
|
|
||||||
if (PG_ARGISNULL(0))
|
if (PG_ARGISNULL(0))
|
||||||
{
|
{
|
||||||
@ -1836,7 +1836,7 @@ populate_recordset_array_element_start(void *state, bool isnull)
|
|||||||
_state->lex->token_type != JSON_TOKEN_OBJECT_START)
|
_state->lex->token_type != JSON_TOKEN_OBJECT_START)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||||
errmsg("must call json_populate_recordset on an array of objects")));
|
errmsg("must call json_populate_recordset on an array of objects")));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user