* Converts C-string to a jsonpath value. * * Uses jsonpath parser to turn string into an AST, then * flattenJsonPathParseItem() does second pass turning AST into binary * representation of jsonpath. */
| 165 | * representation of jsonpath. |
| 166 | */ |
| 167 | static Datum |
| 168 | jsonPathFromCstring(char *in, int len) |
| 169 | { |
| 170 | JsonPathParseResult *jsonpath = parsejsonpath(in, len); |
| 171 | JsonPath *res; |
| 172 | StringInfoData buf; |
| 173 | |
| 174 | initStringInfo(&buf); |
| 175 | enlargeStringInfo(&buf, 4 * len /* estimation */ ); |
| 176 | |
| 177 | appendStringInfoSpaces(&buf, JSONPATH_HDRSZ); |
| 178 | |
| 179 | if (!jsonpath) |
| 180 | ereport(ERROR, |
| 181 | (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), |
| 182 | errmsg("invalid input syntax for type %s: \"%s\"", "jsonpath", |
| 183 | in))); |
| 184 | |
| 185 | flattenJsonPathParseItem(&buf, jsonpath->expr, 0, false); |
| 186 | |
| 187 | res = (JsonPath *) buf.data; |
| 188 | SET_VARSIZE(res, buf.len); |
| 189 | res->header = JSONPATH_VERSION; |
| 190 | if (jsonpath->lax) |
| 191 | res->header |= JSONPATH_LAX; |
| 192 | |
| 193 | PG_RETURN_JSONPATH_P(res); |
| 194 | } |
| 195 | |
| 196 | /* |
| 197 | * Converts jsonpath value to a C-string. |
no test coverage detected