24#ifndef MYSQL_GTIDS_TAG_H
25#define MYSQL_GTIDS_TAG_H
32#include <initializer_list>
55template <std::invocable<
unsigned char> Transform_tp,
56 unsigned char...
char_ranges_tp>
57 requires(
sizeof...(char_ranges_tp) % 2 == 0)
61 using Element_t = std::invoke_result_t<Transform_t, unsigned char>;
62 using Table_t = std::array<Element_t, 256>;
74 std::initializer_list<unsigned char> char_ranges) {
79 for (
const auto *it = char_ranges.begin(); it != char_ranges.end();
82 auto last = *std::next(it);
83 for (
unsigned char ch = first; ch <= last; ++ch)
148 [[nodiscard]]
static bool is_valid(
const std::string_view &sv) {
149 if (sv.empty())
return true;
150 if (sv.size() >
max_size)
return false;
154 for (
auto it = std::next(sv.begin()); it != sv.end(); ++it) {
171 const std::string_view &sv) {
172 if (sv.empty())
return 0;
177 std::size_t end = std::min(sv.size(),
max_size);
178 for (std::size_t pos = 1; pos != end; ++pos) {
181 if (sv.size() > end) {
192concept Is_tag = std::derived_from<Test, detail::Tag_base>;
210template <
class Self_tp>
223 assert(
is_valid(other.string_view()));
236 if (!
is_valid(sv))
throw std::domain_error(
"Invalid tag format.");
248 return mysql::utils::call_and_catch(
255 [[maybe_unused]]
auto ret =
assign(
"");
266 if (sv.empty())
return;
271 writer.write_char(ch);
277 [[nodiscard]] Self_tp &
self() {
return static_cast<Self_tp &
>(*this); }
278 [[nodiscard]]
const Self_tp &
self()
const {
279 return static_cast<const Self_tp &
>(*this);
377 const Is_tag auto &tag2) {
378 return tag1.string_view() == tag2.string_view();
383 const Is_tag auto &tag2) {
384 return !(tag1 == tag2);
Class representing a tag by storing the characters in a member array.
Definition: tag.h:296
friend Base_t
The base class needs to call out_str().
Definition: tag.h:338
std::size_t size() const
Return the number of characters of the tag: an integer between 0 and max_size.
Definition: tag.h:326
auto out_str()
Return an Output String Wrapper writing to this Tag.
Definition: tag.h:333
Tag_trivial() noexcept=default
Default constructor: This does not initialize the tag! Use Tag unless you need std::is_trivially_defa...
static auto throwing_make(const std::string_view &sv)
Return a new Tag, initialized with the given string.
Definition: tag.h:318
std::size_t m_size
Definition: tag.h:342
const char * data() const
Return a const pointer to the data.
Definition: tag.h:329
char m_data[max_size]
Tag represented as data + size.
Definition: tag.h:341
Class representing a tag by storing the characters in a member array.
Definition: tag.h:353
Tag() noexcept
Construct a new empty tag.
Definition: tag.h:358
static auto throwing_make(const std::string_view &sv)
Return a new Tag, initialized with the given string.
Definition: tag.h:368
Tag(const Is_tag auto &other) noexcept
Construct a new tag by copying the other tag.
Definition: tag.h:361
Tag_trivial Base_t
Definition: tag.h:354
Helper class to hold lookup tables indexed by ascii characters.
Definition: tag.h:58
std::array< Element_t, 256 > Table_t
Definition: tag.h:62
static Table_t & table()
Return reference to the table.
Definition: tag.h:65
Transform_tp Transform_t
Definition: tag.h:60
std::invoke_result_t< Transform_t, unsigned char > Element_t
Definition: tag.h:61
static Table_t & build_table(std::initializer_list< unsigned char > char_ranges)
Compute the table.
Definition: tag.h:73
Top of the hierarchy, defining the tag format.
Definition: tag.h:96
static constexpr std::ptrdiff_t max_ssize
Definition: tag.h:100
static constexpr std::size_t max_size
The maximum number of characters a tag.
Definition: tag.h:99
static bool is_valid(const std::string_view &sv)
Return true if the given string is a valid tag.
Definition: tag.h:148
static bool is_valid_nonfirst_char(int ch)
Return true if the given character is allowed in a tag, at other positions than the first.
Definition: tag.h:139
static bool is_valid_first_char(int ch)
Return true if the given character is allowed as the first character in a tag.
Definition: tag.h:125
static int get_normalized_first_char(int ch)
Return the character converted to lowercase, if it is allowed as the first character in a tag; otherw...
Definition: tag.h:117
static std::optional< std::size_t > valid_prefix_length(const std::string_view &sv)
Return the length of a tag that appears as an initial prefix of the given string, or no value if ther...
Definition: tag.h:170
static int get_normalized_nonfirst_char(int ch)
Return the character converted to lowercase, if it is allowed in a tag at other positions than the fi...
Definition: tag.h:131
decltype([](unsigned char ch) { return std::tolower(ch) Tolower_t
Lambda function that converts a character to lower case.
Definition: tag.h:104
CRTP base class defining a tag class given an implementation that provides a contiguous buffer as sto...
Definition: tag.h:212
mysql::utils::Return_status assign(const std::string_view &sv)
Copy from the given std::string_view into this tag.
Definition: tag.h:247
auto assign(const Is_tag auto &other)
Copy from the given tag into this tag.
Definition: tag.h:222
void throwing_assign(const std::string_view &sv)
Copy from the given std::string_view into this tag.
Definition: tag.h:235
void clear()
Set the tag to empty.
Definition: tag.h:253
auto assign_and_normalize(const std::string_view &sv)
Copy from the given string_view, changing character case to lower case.
Definition: tag.h:261
CRTP base class that provides a rich API for classes that behave like byte buffers.
Definition: buffer_interface.h:102
Class that serves as the target for encode(..., Is_string_target), which never writes anything and on...
Definition: string_counter.h:40
Class that serves as the target for encode(..., Is_string_target), which writes to a char * buffer wi...
Definition: string_writer.h:43
True if Test is one of the tag classes.
Definition: tag.h:192
static int count
Definition: myisam_ftdump.cc:45
uint counter
Definition: mysqlimport.cc:58
void build_table(const std::string &schema, const std::string &table, const std::string &partition, bool is_tmp, bool convert, std::string &dict_name)
Definition: dict0dd.cc:7567
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
char tolower(const char &ch)
Definition: parsing_helpers.h:41
bool operator!=(const Is_gtid auto >id1, const Is_gtid auto >id2)
Definition: gtid.h:328
bool operator==(const Is_gtid auto >id1, const Is_gtid auto >id2)
Definition: gtid.h:323
auto out_str_fixed_nz(mysql::meta::Is_pointer_to_charlike auto first, Size_t &length, Size_t capacity=0)
Return a wrapper around a non-growable, non-null-terminated output buffer, represented using a raw po...
Definition: out_str.h:818
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
Return_status
Simple, strongly-typed enumeration to indicate internal status: ok, error.
Definition: return_status.h:40
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76