MySQL 9.1.0
Source Code Documentation
|
This file contains implementation support for the JSON path abstraction. More...
#include "sql-common/json_path.h"
#include "my_rapidjson_size_t.h"
#include <assert.h>
#include <stddef.h>
#include <algorithm>
#include <string>
#include <string_view>
#include <rapidjson/encodings.h>
#include <rapidjson/error/error.h>
#include <rapidjson/memorystream.h>
#include <rapidjson/reader.h>
#include "my_inttypes.h"
#include "mysql/strings/m_ctype.h"
#include "sql-common/json_dom.h"
#include "sql/psi_memory_key.h"
#include "sql/sql_const.h"
#include "sql_string.h"
#include "string_with_len.h"
Classes | |
class | anonymous_namespace{json_path.cc}::Stream |
A simple input stream class for the JSON path parser. More... | |
class | anonymous_namespace{json_path.cc}::MemberNameHandler |
A RapidJSON handler which accepts a scalar string and nothing else. More... | |
Namespaces | |
namespace | anonymous_namespace{json_path.cc} |
Functions | |
static bool | is_ecmascript_identifier (const std::string_view &name) |
Returns true if the name is a valid ECMAScript identifier. More... | |
static bool | is_digit (unsigned codepoint) |
Return true if the codepoint is a Unicode digit. More... | |
static bool | is_whitespace (char ch) |
Is this a whitespace character? More... | |
static bool | parse_path (Stream *stream, Json_path *path) |
Fills in a Json_path from a path expression. More... | |
static bool | parse_path_leg (Stream *stream, Json_path *path) |
Parses a single path leg and appends it to a Json_path object. More... | |
static bool | parse_ellipsis_leg (Stream *stream, Json_path *path) |
Parses a single ellipsis leg and appends it to a Json_path object. More... | |
static bool | parse_array_leg (Stream *stream, Json_path *path) |
Parses a single array leg and appends it to a Json_path object. More... | |
static bool | parse_member_leg (Stream *stream, Json_path *path) |
Parses a single member leg and appends it to a Json_path object. More... | |
static bool | append_array_index (String *buf, size_t index, bool from_end) |
bool | parse_path (size_t path_length, const char *path_expression, Json_path *path, size_t *bad_index) |
Top level parsing factory method. More... | |
static bool | parse_array_index (Stream *stream, uint32 *array_index, bool *from_end) |
Parse an array index in an array cell index or array range path leg. More... | |
static const char * | find_end_of_member_name (const char *start, const char *end) |
Find the end of a member name in a JSON path. More... | |
bool | parse_name_with_rapidjson (const char *str, size_t len, String *name) |
Parse a quoted member name using the rapidjson parser, so that we get the name without the enclosing quotes and with any escape sequences replaced with the actual characters. More... | |
static bool | unicode_combining_mark (unsigned codepoint) |
Return true if the character is a unicode combining mark. More... | |
static bool | is_letter (unsigned codepoint) |
Return true if the codepoint is a Unicode letter. More... | |
static bool | is_connector_punctuation (unsigned codepoint) |
Return true if the codepoint is Unicode connector punctuation. More... | |
bool | clone_without_autowrapping (const Json_path *source_path, Json_path_clone *target_path, Json_wrapper *doc, PSI_memory_key key) |
Clone a source path to a target path, stripping out legs which are made redundant by the auto-wrapping rule from the WL#7909 spec and further extended in the WL#9831 spec: More... | |
Variables | |
constexpr char | anonymous_namespace{json_path.cc}::SCOPE = '$' |
constexpr char | anonymous_namespace{json_path.cc}::BEGIN_MEMBER = '.' |
constexpr char | anonymous_namespace{json_path.cc}::BEGIN_ARRAY = '[' |
constexpr char | anonymous_namespace{json_path.cc}::END_ARRAY = ']' |
constexpr char | anonymous_namespace{json_path.cc}::DOUBLE_QUOTE = '"' |
constexpr char | anonymous_namespace{json_path.cc}::WILDCARD = '*' |
constexpr char | anonymous_namespace{json_path.cc}::MINUS = '-' |
constexpr char | anonymous_namespace{json_path.cc}::LAST [] = "last" |
This file contains implementation support for the JSON path abstraction.
The path abstraction is described by the functional spec attached to WL#7909.
|
static |
bool clone_without_autowrapping | ( | const Json_path * | source_path, |
Json_path_clone * | target_path, | ||
Json_wrapper * | doc, | ||
PSI_memory_key | key | ||
) |
Clone a source path to a target path, stripping out legs which are made redundant by the auto-wrapping rule from the WL#7909 spec and further extended in the WL#9831 spec:
"If an array cell path leg or an array range path leg is evaluated against a non-array value, the result of the evaluation is the same as if the non-array value had been wrapped in a single-element array."
[in] | source_path | The original path. |
[in,out] | target_path | The clone to be filled in. |
[in] | doc | The document to seek through. |
[in] | key | Instrumented memory key |
|
static |
Find the end of a member name in a JSON path.
The name could be either a quoted or an unquoted identifier.
start | the start of the member name |
end | the end of the JSON path expression |
|
static |
Return true if the codepoint is Unicode connector punctuation.
|
static |
Return true if the codepoint is a Unicode digit.
This was the best recommendation from the old-times about how to answer this question.
|
static |
Returns true if the name is a valid ECMAScript identifier.
The name must be a sequence of UTF8-encoded bytes. All escape sequences have been replaced with UTF8-encoded bytes.
[in] | name | name to check |
|
static |
Return true if the codepoint is a Unicode letter.
This was the best recommendation from the old-timers about how to answer this question. But as you can see from the need to call unicode_combining_mark(), my_isalpha() isn't good enough. It probably has many other defects.
FIXME
|
inlinestatic |
Is this a whitespace character?
|
static |
Parse an array index in an array cell index or array range path leg.
An array index is either a non-negative integer (a 0-based index relative to the beginning of the array), or the keyword "last" (which means the last element in the array), or the keyword "last" followed by a minus ("-") and a non-negative integer (which is the 0-based index relative to the end of the array).
[in,out] | stream | the stream to read the path expression from |
[out] | array_index | gets set to the parsed array index |
[out] | from_end | gets set to true if the array index is relative to the end of the array |
|
static |
Parses a single array leg and appends it to a Json_path object.
[in,out] | stream | The stream to read the path expression from. |
[in,out] | path | The Json_path object to fill. |
|
static |
Parses a single ellipsis leg and appends it to a Json_path object.
[in,out] | stream | The stream to read the path expression from. |
[in,out] | path | The Json_path object to fill. |
|
static |
Parses a single member leg and appends it to a Json_path object.
[in,out] | stream | The stream to read the path expression from. |
[in,out] | path | The Json_path object to fill. |
bool parse_name_with_rapidjson | ( | const char * | str, |
size_t | len, | ||
String * | name | ||
) |
Parse a quoted member name using the rapidjson parser, so that we get the name without the enclosing quotes and with any escape sequences replaced with the actual characters.
It is the caller's responsibility to destroy the returned Json_string when it's done with it.
str | the input string | |
len | the length of the input string | |
[out] | name | the member name |
bool parse_path | ( | size_t | path_length, |
const char * | path_expression, | ||
Json_path * | path, | ||
size_t * | bad_index | ||
) |
Top level parsing factory method.
Initialize a Json_path from a path expression.
|
static |
Fills in a Json_path from a path expression.
[in,out] | stream | The stream to read the path expression from. |
[in,out] | path | The Json_path object to fill. |
|
static |
Parses a single path leg and appends it to a Json_path object.
[in,out] | stream | The stream to read the path expression from. |
[in,out] | path | The Json_path object to fill. |
|
inlinestatic |
Return true if the character is a unicode combining mark.
codepoint | A unicode codepoint. |