24#ifndef MYSQL_STRCONV_DECODE_PARSER_H
25#define MYSQL_STRCONV_DECODE_PARSER_H
48template <Is_format Format_t>
54template <
class Format_t,
class Object_t>
82 explicit Parser(
const std::string_view &
source, std::size_t pos_arg = 0)
107 const std::string_view &expected_string) {
126 const std::string_view &sv) {
127 [[maybe_unused]]
auto ret =
do_skip(opt, sv);
146 const std::string_view &sv) {
169 std::string_view
str) {
170 assert(!
str.empty());
177 if (std::memcmp(this->
pos(), str.data(),
str.size()) != 0)
199 const std::string_view &sv) {
200 return call(opt, [&] {
222 template <
class Object_t>
234 format.before_token(*
this);
242 format.after_token(*
this);
254 template <
class Format_t,
class Object_t>
256 :
public std::bool_constant<
257 detail::Can_invoke_decode_impl<Format_t, Object_t>> {};
278 auto resolved_format =
281 return call(opt, [&] {
284 if (!
is_ok())
return;
322 return this->
do_read(opt, target);
351 using Target_t = std::remove_cvref_t<
decltype(target)>;
352 [[maybe_unused]]
auto before = this->
int_pos();
392 const std::invocable
auto &func) {
401 auto invoke_and_check = [&] {
418 std::size_t
count = 0;
453 template <
class Format_t>
459static_assert(std::contiguous_iterator<Parser>);
Fluent API for parsing strings.
Definition: fluent_parser.h:116
Object used to parse strings.
Definition: parser.h:69
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.
Definition: parser.h:168
Return_status_t call(const std::invocable auto &func)
Parse using the given function, using empty parse options.
Definition: parser.h:377
Return_status_t read(const Is_parse_options auto &opt, Object_t &obj)
Parse into the given object.
Definition: parser.h:225
mysql::utils::Return_status Return_status_t
Definition: parser.h:70
Fluent_parser< Format_t > fluent(const Format_t &format)
Definition: parser.h:454
void after_token(const Is_format auto &format)
If format has a member function after_token, call it with *this as argument.
Definition: parser.h:240
Parser()=default
Be default-constructible.
void before_token(const Is_format auto &format)
If format has a member function before_token, call it with *this as argument.
Definition: parser.h:232
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.
Definition: parser.h:391
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...
Definition: parser.h:94
Parser(const std::string_view &source, std::size_t pos_arg=0)
Construct a new Parser object.
Definition: parser.h:82
Return_status_t skip(const Is_parse_options auto &opt, const std::string_view &sv)
Skip occurrences of the literal string sv, if found.
Definition: parser.h:145
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,...
Definition: parser.h:272
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...
Definition: parser.h:106
Return_status_t do_skip(const Is_parse_options auto &opt, const std::string_view &sv)
Helper to implement the two overloads of skip.
Definition: parser.h:198
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 ...
Definition: parser.h:317
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 an...
Definition: parser.h:344
void skip(const Is_parse_options_optional auto &opt, const std::string_view &sv)
Skip occurrences of the literal string sv, if found.
Definition: parser.h:125
Base class for the current position of a string parser, holding both the parsed string and the positi...
Definition: parse_position.h:48
void advance(std::ptrdiff_t delta)
Move the iterator delta steps.
Definition: parse_position.h:79
std::size_t remaining_size() const
Return the remaining size.
Definition: parse_position.h:153
Parse_position()=default
Construct a new object.
const char * pos() const
Return the current position as a char pointer.
Definition: parse_position.h:110
std::string_view str() const
Return a string_view over the underlying string.
Definition: parse_position.h:167
std::size_t int_pos() const
Return the current position as an integer.
Definition: parse_position.h:107
void set_int_pos(std::size_t int_pos_arg)
Set the position to the given one.
Definition: parse_position.h:101
Class holding the result from parsing a string, in the form of a status and a message.
Definition: parse_result.h:45
void set_match_count(std::size_t count) noexcept
Store a result representing that the requested object was successfully parsed, overriding a previous ...
Definition: parse_result.h:175
void revert_parse_error_to_ok() noexcept
Definition: parse_result.h:47
@ sentence
The message is expressed as a full sentence, for example "Value out of range".
@ expected_string
The message is a string that was expected but not found at the current position.
void update_parse_error_pos(std::size_t position)
Update the position of a parse error to the given position.
Definition: parse_result.h:58
bool is_parse_error() const
Return true if a parse error occurred.
Definition: parse_result.h:126
void set_oom() noexcept
Store a result representing that the requested object could not be parsed because and out-of-memory c...
Definition: parse_result.h:88
bool is_ok() const
Return true if the last operation succeeded, i.e., either a full match was requested and an object wa...
Definition: parse_result.h:97
std::string_view message() const
Return the message.
Definition: parse_result.h:186
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.
Definition: parse_result.h:157
bool is_store_error() const
Return true if an environment error occurred.
Definition: parse_result.h:121
True if Test is an Output String Wrapper, i.e., derived from Out_str_base.
Definition: out_str.h:219
True for any kind of parse options: Format, Repeat, Checker, or Compound_parse_options.
Definition: parse_options.h:133
True for any kind of parse options for which get_repeat() returns Repeat_optional,...
Definition: parse_options.h:143
True for any kind of parse options: Format, Repeat, Checker, or Compound_parse_options.
Definition: parse_options.h:126
True for invocables that can be used with out_str_write, i.e., which accept either a String_writer & ...
Definition: out_str_write.h:88
Concept that holds for String_counter and String_writer.
Definition: string_target.h:111
True if decode_impl can be invoked with the given format type and object type.
Definition: parser.h:55
static int count
Definition: myisam_ftdump.cc:45
Definition: fts0fts.cc:236
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
constexpr auto resolve_format(const Format_t &format, const Object_t &object)
Return the format to pass to the implementation function, given the format and object type passed by ...
Definition: resolve_format.h:165
Definition: gtid_binary_format.h:41
void invoke_checker(const Is_parse_options auto &)
Invoke the Checker member of any parse options, if it exists; otherwise do nothing.
Definition: parse_options.h:172
auto get_repeat(const Is_parse_options auto &)
Return the Repeat component of any parse options, if it exists; otherwise a default-constructed Repea...
Definition: parse_options.h:162
mysql::utils::Return_status out_str_write(const Out_str_t &out_str, const Producer_counter_t &producer_counter, const Producer_writer_t &producer_writer, const Oom_action_t &oom_action=detail::nop)
Given an Is_out_str object, a String_producer_counter, and a String_producer_writer,...
Definition: out_str_write.h:178
auto get_format(const Is_parse_options auto &)
Return the Format component of any parse options that has one.
Definition: parse_options.h:152
void decode_impl(const Gtid_binary_format &format, Parser &parser, mysql::gtids::Is_tag auto &tag)
Definition: gtid_binary_format_conv.h:63
Return_status
Simple, strongly-typed enumeration to indicate internal status: ok, error.
Definition: return_status.h:40
Return_t void_to_ok(const Func_t &func, Args_t &&...args)
Helper that calls the given function and returns its result, or returns Return_status::ok if the func...
Definition: return_status.h:113
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:42
Definition: mysqltest.cc:395
Represents parse options consisting of a tuple where each of the following elements occurs optionally...
Definition: parse_options.h:94
Helper type predicate used by detail::resolve_format.
Definition: parser.h:257