@@ -44,7 +44,6 @@ static JsonParseErrorType parse_object(JsonLexContext *lex, JsonSemAction *sem);
44
44
static JsonParseErrorType parse_array_element (JsonLexContext * lex , JsonSemAction * sem );
45
45
static JsonParseErrorType parse_array (JsonLexContext * lex , JsonSemAction * sem );
46
46
static JsonParseErrorType report_parse_error (JsonParseContext ctx , JsonLexContext * lex );
47
- static int report_json_context (JsonLexContext * lex );
48
47
static char * extract_token (JsonLexContext * lex );
49
48
50
49
/* the null action object used for pure validation */
@@ -128,25 +127,13 @@ IsValidJsonNumber(const char *str, int len)
128
127
}
129
128
130
129
/*
131
- * makeJsonLexContext
130
+ * makeJsonLexContextCstringLen
132
131
*
133
- * lex constructor, with or without StringInfo object
134
- * for de-escaped lexemes.
132
+ * lex constructor, with or without StringInfo object for de-escaped lexemes.
135
133
*
136
134
* Without is better as it makes the processing faster, so only make one
137
135
* if really required.
138
- *
139
- * If you already have the json as a text* value, use the first of these
140
- * functions, otherwise use makeJsonLexContextCstringLen().
141
136
*/
142
- JsonLexContext *
143
- makeJsonLexContext (text * json , bool need_escapes )
144
- {
145
- return makeJsonLexContextCstringLen (VARDATA_ANY (json ),
146
- VARSIZE_ANY_EXHDR (json ),
147
- need_escapes );
148
- }
149
-
150
137
JsonLexContext *
151
138
makeJsonLexContextCstringLen (char * json , int len , bool need_escapes )
152
139
{
@@ -202,23 +189,6 @@ pg_parse_json(JsonLexContext *lex, JsonSemAction *sem)
202
189
return result ;
203
190
}
204
191
205
- /*
206
- * pg_parse_json_or_ereport
207
- *
208
- * This fuction is like pg_parse_json, except that it does not return a
209
- * JsonParseErrorType. Instead, in case of any failure, this function will
210
- * ereport(ERROR).
211
- */
212
- void
213
- pg_parse_json_or_ereport (JsonLexContext * lex , JsonSemAction * sem )
214
- {
215
- JsonParseErrorType result ;
216
-
217
- result = pg_parse_json (lex , sem );
218
- if (result != JSON_SUCCESS )
219
- json_ereport_error (result , lex );
220
- }
221
-
222
192
/*
223
193
* json_count_array_elements
224
194
*
@@ -1038,27 +1008,6 @@ report_parse_error(JsonParseContext ctx, JsonLexContext *lex)
1038
1008
}
1039
1009
}
1040
1010
1041
- /*
1042
- * Report a JSON error.
1043
- */
1044
- void
1045
- json_ereport_error (JsonParseErrorType error , JsonLexContext * lex )
1046
- {
1047
- if (error == JSON_UNICODE_HIGH_ESCAPE ||
1048
- error == JSON_UNICODE_CODE_POINT_ZERO )
1049
- ereport (ERROR ,
1050
- (errcode (ERRCODE_UNTRANSLATABLE_CHARACTER ),
1051
- errmsg ("unsupported Unicode escape sequence" ),
1052
- errdetail ("%s" , json_errdetail (error , lex )),
1053
- report_json_context (lex )));
1054
- else
1055
- ereport (ERROR ,
1056
- (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
1057
- errmsg ("invalid input syntax for type %s" , "json" ),
1058
- errdetail ("%s" , json_errdetail (error , lex )),
1059
- report_json_context (lex )));
1060
- }
1061
-
1062
1011
/*
1063
1012
* Construct a detail message for a JSON error.
1064
1013
*/
@@ -1118,78 +1067,6 @@ json_errdetail(JsonParseErrorType error, JsonLexContext *lex)
1118
1067
}
1119
1068
}
1120
1069
1121
- /*
1122
- * Report a CONTEXT line for bogus JSON input.
1123
- *
1124
- * lex->token_terminator must be set to identify the spot where we detected
1125
- * the error. Note that lex->token_start might be NULL, in case we recognized
1126
- * error at EOF.
1127
- *
1128
- * The return value isn't meaningful, but we make it non-void so that this
1129
- * can be invoked inside ereport().
1130
- */
1131
- static int
1132
- report_json_context (JsonLexContext * lex )
1133
- {
1134
- const char * context_start ;
1135
- const char * context_end ;
1136
- const char * line_start ;
1137
- int line_number ;
1138
- char * ctxt ;
1139
- int ctxtlen ;
1140
- const char * prefix ;
1141
- const char * suffix ;
1142
-
1143
- /* Choose boundaries for the part of the input we will display */
1144
- context_start = lex -> input ;
1145
- context_end = lex -> token_terminator ;
1146
- line_start = context_start ;
1147
- line_number = 1 ;
1148
- for (;;)
1149
- {
1150
- /* Always advance over newlines */
1151
- if (context_start < context_end && * context_start == '\n' )
1152
- {
1153
- context_start ++ ;
1154
- line_start = context_start ;
1155
- line_number ++ ;
1156
- continue ;
1157
- }
1158
- /* Otherwise, done as soon as we are close enough to context_end */
1159
- if (context_end - context_start < 50 )
1160
- break ;
1161
- /* Advance to next multibyte character */
1162
- if (IS_HIGHBIT_SET (* context_start ))
1163
- context_start += pg_mblen (context_start );
1164
- else
1165
- context_start ++ ;
1166
- }
1167
-
1168
- /*
1169
- * We add "..." to indicate that the excerpt doesn't start at the
1170
- * beginning of the line ... but if we're within 3 characters of the
1171
- * beginning of the line, we might as well just show the whole line.
1172
- */
1173
- if (context_start - line_start <= 3 )
1174
- context_start = line_start ;
1175
-
1176
- /* Get a null-terminated copy of the data to present */
1177
- ctxtlen = context_end - context_start ;
1178
- ctxt = palloc (ctxtlen + 1 );
1179
- memcpy (ctxt , context_start , ctxtlen );
1180
- ctxt [ctxtlen ] = '\0' ;
1181
-
1182
- /*
1183
- * Show the context, prefixing "..." if not starting at start of line, and
1184
- * suffixing "..." if not ending at end of line.
1185
- */
1186
- prefix = (context_start > line_start ) ? "..." : "" ;
1187
- suffix = (lex -> token_type != JSON_TOKEN_END && context_end - lex -> input < lex -> input_length && * context_end != '\n' && * context_end != '\r' ) ? "..." : "" ;
1188
-
1189
- return errcontext ("JSON data, line %d: %s%s%s" ,
1190
- line_number , prefix , ctxt , suffix );
1191
- }
1192
-
1193
1070
/*
1194
1071
* Extract the current token from a lexing context, for error reporting.
1195
1072
*/
0 commit comments