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

Function IsValidJsonNumber

src/common/jsonapi.c:114–144  ·  view source on GitHub ↗

* Utility function to check if a string is a valid JSON number. * * str is of length len, and need not be null-terminated. */

Source from the content-addressed store, hash-verified

112 * str is of length len, and need not be null-terminated.
113 */
114bool
115IsValidJsonNumber(const char *str, int len)
116{
117 bool numeric_error;
118 int total_len;
119 JsonLexContext dummy_lex;
120
121 if (len <= 0)
122 return false;
123
124 /*
125 * json_lex_number expects a leading '-' to have been eaten already.
126 *
127 * having to cast away the constness of str is ugly, but there's not much
128 * easy alternative.
129 */
130 if (*str == '-')
131 {
132 dummy_lex.input = unconstify(char *, str) + 1;
133 dummy_lex.input_length = len - 1;
134 }
135 else
136 {
137 dummy_lex.input = unconstify(char *, str);
138 dummy_lex.input_length = len;
139 }
140
141 json_lex_number(&dummy_lex, dummy_lex.input, &numeric_error, &total_len);
142
143 return (!numeric_error) && (total_len == dummy_lex.input_length);
144}
145
146/*
147 * makeJsonLexContextCstringLen

Callers 3

hstore_to_json_looseFunction · 0.85
hstore_to_jsonb_looseFunction · 0.85
datum_to_jsonFunction · 0.85

Calls 1

json_lex_numberFunction · 0.85

Tested by

no test coverage detected