![]() |
MySQL 9.6.0
Source Code Documentation
|
Object used to parse strings. More...
#include <parser.h>
Classes | |
| struct | Can_invoke_decode_impl_pred |
| Helper type predicate used by detail::resolve_format. More... | |
Public Member Functions | |
| Parser ()=default | |
| Be default-constructible. More... | |
| Parser (const std::string_view &source, std::size_t pos_arg=0) | |
| Construct a new Parser object. More... | |
| void | set_parse_error (const std::string_view &message) |
| Store a result representing that the requested object could not be parsed because the string is wrong at the current position. More... | |
| void | set_parse_error_expected_string (const std::string_view &expected_string) |
| Store a result representing that the requested object could not be parsed because the string is wrong at the current position. More... | |
| void | skip (const Is_parse_options_optional auto &opt, const std::string_view &sv) |
Skip occurrences of the literal string sv, if found. More... | |
| Return_status_t | skip (const Is_parse_options auto &opt, const std::string_view &sv) |
Skip occurrences of the literal string sv, if found. More... | |
| std::size_t | match_length (const Is_format auto &format, std::string_view str) |
Determine if a prefix of remaining_str() matches str and return the length. More... | |
| template<class Object_t > requires (!Is_out_str<Object_t>) | |
| Return_status_t | read (const Is_parse_options auto &opt, Object_t &obj) |
| Parse into the given object. More... | |
| Return_status_t | read_to_out_str (const Is_parse_options_nocheck auto &opt, const Is_out_str auto &out_str) |
| Read from this object to the given Output String Wrapper, using a decode_impl function that takes an Is_string_target output object. More... | |
| Return_status_t | read_to_out_str (const Is_string_producer auto &producer, const Is_out_str auto &out_str) |
| Invoke the given string producer function, which is assumed to read from the current Parser object and report errors to this object. More... | |
| Return_status_t | call (const std::invocable auto &func) |
| Parse using the given function, using empty parse options. More... | |
| Return_status_t | call (const Is_parse_options auto &opt, const std::invocable auto &func) |
| Parse using the given function, using the given parse options. More... | |
| template<class Format_t > | |
| Fluent_parser< Format_t > | fluent (const Format_t &format) |
Public Member Functions inherited from mysql::strconv::detail::Parse_position< Parser > | |
| Parse_position (const std::string_view &source, std::size_t int_pos=0) | |
| Construct a new Parse_position from the given range. More... | |
| Parse_position ()=default | |
| Construct a new object. More... | |
| const char * | get_pointer () const |
| Dereference the iterator and return the value. More... | |
| void | advance (std::ptrdiff_t delta) |
| Move the iterator delta steps. More... | |
| std::ptrdiff_t | distance_from (const Parse_position &other) const |
| Return the distance from iterator other to this. More... | |
| bool | is_sentinel () const |
| Return true if this iterator is at the end. More... | |
| void | set_int_pos (std::size_t int_pos_arg) |
| Set the position to the given one. More... | |
| std::size_t | int_pos () const |
| Return the current position as an integer. More... | |
| const char * | pos () const |
| Return the current position as a char pointer. More... | |
| const unsigned char * | upos () const |
| Return the current position as an unsigned char pointer. More... | |
| const std::byte * | bpos () const |
| Return the current position as an std::byte pointer. More... | |
| const char * | begin () const |
| Return pointer to the beginning of the underlying string. More... | |
| const unsigned char * | ubegin () const |
| Return pointer to the beginning of the underlying string. More... | |
| const std::byte * | bbegin () const |
| Return pointer to the beginning of the underlying string. More... | |
| const char * | end () const |
| Return pointer to the end of the underlying string. More... | |
| const unsigned char * | uend () const |
| Return pointer to the end of the underlying string. More... | |
| const std::byte * | bend () const |
| Return pointer to the end of the underlying string. More... | |
| std::size_t | remaining_size () const |
| Return the remaining size. More... | |
| std::size_t | str_size () const |
| Return the length of the underlying string. More... | |
| std::string_view | parsed_str () const |
| Return a string_view over the left part of the string, up to the position. More... | |
| std::string_view | remaining_str () const |
| Return a string_view over the remaining string. More... | |
| std::string_view | str () const |
| Return a string_view over the underlying string. More... | |
Public Member Functions inherited from mysql::iterators::Iterator_interface< Self_tp > | |
| decltype(auto) | operator* () const |
| Dereference operator, which returns the current value. More... | |
| auto | operator-> () const |
| Arrow operator, return a pointer (possibly a fancy pointer) to the current element. More... | |
| Self_t & | operator++ () |
| Pre-increment operator, which advances the position one step and returns a reference to the iterator itself. More... | |
| auto | operator++ (int) |
| Post-increment operator, which advances the position one step. More... | |
| Self_t & | operator-- () |
| Pre-decrement iterator, which moves one step back and returns a reference to the iterator itself. More... | |
| auto | operator-- (int) |
| Post-decrement operator, which moves one step back and returns a copy of the iterator before the decrement. More... | |
| Self_t & | operator+= (std::ptrdiff_t delta) |
| Addition assignment operator, which moves the iterator forward by the given number of steps, and returns a reference to the iterator itself. More... | |
| Self_t & | operator-= (std::ptrdiff_t delta) |
| Subtraction assignment operator, which moves the iterator backward by the given number of steps, and returns a reference to the iterator itself. More... | |
| Self_t | operator+ (std::ptrdiff_t delta) const |
| Addition operator, which returns a new iterator that is the given number of steps ahead of the current iterator. More... | |
| Self_t | operator- (std::ptrdiff_t delta) const |
| Subtraction-of-integer operator, which returns a new iterator that is the given number of steps behind of the current iterator. More... | |
| std::ptrdiff_t | operator- (const Self_t &other) const |
| Subtraction-of-iterator operator, which returns the number of steps from other this. More... | |
| decltype(auto) | operator[] (std::ptrdiff_t delta) const |
| Subscript operator, which returns a new iterator that is the given number of steps ahead of the current iterator. More... | |
Public Member Functions inherited from mysql::strconv::detail::Parse_result | |
| void | revert_parse_error_to_ok () noexcept |
| void | update_parse_error_pos (std::size_t position) |
| Update the position of a parse error to the given position. More... | |
| void | set_store_error (const std::string_view &message) noexcept |
| Store a result representing that the requested object could not be parsed because something went wrong which is not the string's fault. More... | |
| void | set_fullmatch_error () noexcept |
Store a result representing that an object was successfully parsed from a prefix of the string, but the user invoked a function such as decode which requires that the object description extends to the end of the string. More... | |
| void | set_oom () noexcept |
| Store a result representing that the requested object could not be parsed because and out-of-memory condition occurred. More... | |
| bool | is_ok () const |
| Return true if the last operation succeeded, i.e., either a full match was requested and an object was found which extended to the end of the string; or a prefix match was requested and an object was found, possibly followed by unparsed character; or an optional match was requested and the object was found or was completely absent (but no error occurred). More... | |
| bool | is_prefix_ok () const |
| Return true if either the last operation succeeded, or failed because a full match was requested and only a prefix match was found. More... | |
| std::size_t | found_count () const |
| Return the number of repetitions found in the last call. More... | |
| bool | is_found () const |
| Return true if found_count() != 0. More... | |
| bool | is_store_error () const |
| Return true if an environment error occurred. More... | |
| bool | is_parse_error () const |
| Return true if a parse error occurred. More... | |
| bool | is_fullmatch_error () const |
| Return true if the object was parsed successfully, but there were more characters after the end. More... | |
Private Types | |
| using | Return_status_t = mysql::utils::Return_status |
Private Member Functions | |
| Return_status_t | do_skip (const Is_parse_options auto &opt, const std::string_view &sv) |
Helper to implement the two overloads of skip. More... | |
| void | before_token (const Is_format auto &format) |
If format has a member function before_token, call it with *this as argument. More... | |
| void | after_token (const Is_format auto &format) |
If format has a member function after_token, call it with *this as argument. More... | |
| Return_status_t | do_read (const Is_parse_options auto &opt, auto &out) |
| Resolve the format, using the rules to deduce format based on default format and parent format, and parse the given object using the resolved format. More... | |
Additional Inherited Members | |
Public Types inherited from mysql::strconv::detail::Parse_position< Parser > | |
| using | Iterator_category_t = std::contiguous_iterator_tag |
Protected Types inherited from mysql::iterators::Iterator_interface< Self_tp > | |
| using | Self_t = Self_tp |
Protected Types inherited from mysql::strconv::detail::Parse_result | |
| enum class | Message_form { sentence , expected_string } |
| The form of the message stored in this object. More... | |
Protected Member Functions inherited from mysql::strconv::detail::Parse_result | |
| void | do_set_parse_error (const std::string_view &string, Message_form message_form, std::size_t position) |
Common implementation of set_parse_error and set_parse_error_expected_string. More... | |
| void | set_match_count (std::size_t count) noexcept |
| Store a result representing that the requested object was successfully parsed, overriding a previous error state. More... | |
Object used to parse strings.
This holds state, including the parsed string, position, success/failure status, and error messages. It is used and manipulated by decode_impl functions, and returned by decode.
It aggregates a Parse_position and a Parse_result. We extend it with higher-level functions that read from the string, advance the position, and store the success/failure status.
|
private |
|
default |
Be default-constructible.
The resulting Parser is a singular object, which may only be used as the target of an assignment operation.
|
inlineexplicit |
Construct a new Parser object.
| source | Source string. |
| pos_arg | Current position. Defaults to 0, i.e., the beginning. |
|
inlineprivate |
If format has a member function after_token, call it with *this as argument.
|
inlineprivate |
If format has a member function before_token, call it with *this as argument.
|
inline |
Parse using the given function, using the given parse options.
| opt | Parse options that describe how to parse. The Repeat component is used to determine the number of repetitions. The Format component is unused. The Checker component is used to validate the string after parsing (once per repeated element). |
| func | Function that parses a single token. This must be invocable without arguments, and update the status of this object in case an error occurs. |
|
inline |
Parse using the given function, using empty parse options.
| func | Function that parses a single token. This must be invocable without arguments, and update the status of this object in case an error occurs. |
|
inlineprivate |
Resolve the format, using the rules to deduce format based on default format and parent format, and parse the given object using the resolved format.
This invokes before_token and after_token for the format given by opt, not for the resolved format.
| opt | Parse options | |
| [in,out] | out | Object to parse. |
|
inlineprivate |
Helper to implement the two overloads of skip.
| opt | Parse options |
| sv | String to skip |
Return_status::error.
|
inline |
|
inline |
Determine if a prefix of remaining_str() matches str and return the length.
If the format has before_token and/or after_token members, they will be invoked before/after attempting the match.
This function does not alter the position or status of this object.
| format | The format: in case this has a before_token and/or an after_token member, those functions will be invoked before and after skipping sv. Otherwise, the format is unused (in which case you may use the overload that does not take a format parameter). |
| str | String to skip |
str.size(), but may be longer in case before_match and/or after_match advanced the position. If there is no match, returns 0.
|
inline |
Parse into the given object.
| opt | Parse options that describe how to parse. The Repeat component is used to determine the number of repetitions. The Format component is used to invoke the correct decode_impl function, and also the before_token and after_token members are invoked, if present. The Checker component is used to validate the object after parsing. |
| obj | Target object to parse into. |
|
inline |
Read from this object to the given Output String Wrapper, using a decode_impl function that takes an Is_string_target output object.
This function will create String Target objects wrapping the Output String Wrapper and pass them to decode_impl.
| opt | Parse Options that describe how to parse. The Repeat component is used to determine the number of repetitions. The Format component is used to invoke the correct decode_impl function, and also the before_token and after_token members are invoked, if present. |
For this function, the Parse Options must not have a Checker component. If validation is needed for the object type, perform the validation in decode_impl when passed a String_counter. (This pattern prevents allocation in case the string cannot be parsed. That would result in unnecessary allocations e.g. when this is invoked from a higher level object which is invoked using Repeat::any.)
| out_str | Output String Wrapper to parse into. |
is_ok returns false after the call, i.e., either the string could not be parsed, or an out-of-memory condition occurred when growing the output buffer. Otherwise, returns Return_status::ok.
|
inline |
Invoke the given string producer function, which is assumed to read from the current Parser object and report errors to this object.
The output willl be written to the given out_str object.
| producer | String producer to invoke. This accept take a single argument whose type is either String_writer or String_counter. |
| out_str | Output string wrapper used as back-end by the String_writer. This may be resized according to its resize policy. |
is_ok returns false after the call, i.e., either the string could not be parsed, or an out-of-memory condition occurred when growing the output buffer. Otherwise, returns Return_status::ok.
|
inline |
Store a result representing that the requested object could not be parsed because the string is wrong at the current position.
| message | Error message, in the form of a full sentence with leading capital but no period. The full message will be constructed by concatenating a string like " after N characters [...]" to the given message. |
|
inline |
Store a result representing that the requested object could not be parsed because the string is wrong at the current position.
| expected_string | A string that was expected but not found at the current position. For example, if a comma was expected, this should be ",". The full message will be constructed by escaping any special characters in expected_string and inserting it into a message like "Expected "expected_string" after N characters [...]"" |
|
inline |
Skip occurrences of the literal string sv, if found.
This overload is for parse options where the Repeat component may require 1 or more matches. Therefore, the function can fail and is declared [[nodiscard]].
| opt | Parse options that describe how to parse. The Repeat option is used to determine the number of repetitions. Any before_token and after_token members of the Format are invoked before and after skipping sv. |
| sv | String to skip. |
Return_status::ok or Return_status::error.
|
inline |
Skip occurrences of the literal string sv, if found.
This overload is for parse options where the Repeat component allows for 0 matches. Thus the function cannot fail and can return void.
| opt | Parse options that describe how to parse. The Repeat option is used to determine the number of repetitions. Any before_token and after_token members of the Format are invoked before and after skipping sv. |
| sv | String to skip. |