MySQL 9.6.0
Source Code Documentation
boundary_set_text_format.h
Go to the documentation of this file.
1// Copyright (c) 2024, 2025, Oracle and/or its affiliates.
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License, version 2.0,
5// as published by the Free Software Foundation.
6//
7// This program is designed to work with certain software (including
8// but not limited to OpenSSL) that is licensed under separate terms,
9// as designated in a particular file or component or in included license
10// documentation. The authors of MySQL hereby grant you an additional
11// permission to link the program and your derivative works with the
12// separately licensed software that they have either included with
13// the program or referenced in the documentation.
14//
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License, version 2.0, for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
24#ifndef MYSQL_SETS_STRCONV_BOUNDARY_SET_TEXT_FORMAT_H
25#define MYSQL_SETS_STRCONV_BOUNDARY_SET_TEXT_FORMAT_H
26
27/// @file
28/// Experimental API header
29
30#include <string_view> // string_view
31#include "mysql/meta/is_specialization.h" // Is_specialization
32#include "mysql/sets/boundary_set_meta.h" // Is_boundary_set
33#include "mysql/sets/interval.h" // Interval
34#include "mysql/sets/interval_set_meta.h" // Is_interval_set
35#include "mysql/strconv/strconv.h" // Format_base
36
37/// @addtogroup GroupLibsMysqlSets
38/// @{
39
40namespace mysql::strconv {
41
42// NOLINTBEGIN(performance-enum-size): silence clang-tidy's pointless hint
43enum class Skip_whitespace { no, yes };
45enum class Allow_empty { no, yes };
46// NOLINTEND(performance-enum-size)
47
48/// Tag to identify the formatting algorithm for boundary sets of
49/// integrals, and provide the separator strings and logic to skip whitespace
50/// around tokens.
53 const std::string_view &boundary_separator = "-",
54 const std::string_view &interval_separator = ",",
55 Allow_redundant_separators allow_redundant_separators =
57 Allow_empty allow_empty = Allow_empty::yes,
58 Skip_whitespace skip_whitespace_arg = Skip_whitespace::yes) noexcept
59 : m_boundary_separator(boundary_separator),
60 m_interval_separator(interval_separator),
61 m_allow_redundant_separators(allow_redundant_separators),
62 m_allow_empty(allow_empty),
63 m_skip_whitespace(skip_whitespace_arg) {}
64
67
68 /// Fallback to Text_format to read/write types that don't have
69 /// encode_impl/decode_impl implemented for Boundary_set_text_format.
70 [[nodiscard]] constexpr auto parent() const { return Text_format{}; }
71
72 /// Separator between start and end of a single interval.
73 std::string_view m_boundary_separator;
74
75 /// Separator between end of one interval and start of next interval.
76 std::string_view m_interval_separator;
77
78 /// When true, accept and skip extra interval separators before and after
79 /// intervals.
81
82 /// When true, accept the empty set.
84
85 /// When true, accept and skip whitespace between tokens.
87
88 /// Skip whitespace before tokens, if m_skip_whitespace == true.
89 void before_token(Parser &parser) const {
91 }
92
93 /// Skip whitespace after tokens, if m_skip_whitespace == true.
94 void after_token(Parser &parser) const {
96 }
97};
98
99/// Make `mysql::strconv::encode_text` (and `encode(Text_format{}, ...)` use
100/// `Boundary_set_text_format` when the object to format is an Interval,
101/// Boundary sets, or Interval set.
102template <class Object_t>
106auto get_default_format(const Text_format &, const Object_t &) {
108}
109
110} // namespace mysql::strconv
111
112// addtogroup GroupLibsMysqlSets
113/// @}
114
115#endif // ifndef MYSQL_SETS_STRCONV_BOUNDARY_SET_TEXT_FORMAT_H
Experimental API header.
Object used to parse strings.
Definition: parser.h:69
Concept used to determine at compile time whether a given type Test is a template specialization of t...
Definition: is_specialization.h:68
True if Test is an interval set, i.e., provides a view over intervals sorted by their endpoints,...
Definition: boundary_set_meta.h:209
Definition: interval_set_meta.h:75
Experimental API header.
Experimental API header.
Experimental API header.
Experimental API header.
struct Parser parser
Definition: gtid_binary_format.h:41
void skip_whitespace(Parser &parser)
Move the position forward until end or non-whitespace.
Definition: whitespace.h:47
auto get_default_format(const Binary_format &, const Object_t &)
Definition: gtid_binary_format.h:114
Skip_whitespace
Definition: boundary_set_text_format.h:43
Allow_redundant_separators
Definition: boundary_set_text_format.h:44
Allow_empty
Definition: boundary_set_text_format.h:45
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
Tag to identify the formatting algorithm for boundary sets of integrals, and provide the separator st...
Definition: boundary_set_text_format.h:51
constexpr auto parent() const
Fallback to Text_format to read/write types that don't have encode_impl/decode_impl implemented for B...
Definition: boundary_set_text_format.h:70
Skip_whitespace m_skip_whitespace
When true, accept and skip whitespace between tokens.
Definition: boundary_set_text_format.h:86
Boundary_set_text_format(const Text_format &) noexcept
Definition: boundary_set_text_format.h:65
Allow_redundant_separators m_allow_redundant_separators
When true, accept and skip extra interval separators before and after intervals.
Definition: boundary_set_text_format.h:80
Boundary_set_text_format(const std::string_view &boundary_separator="-", const std::string_view &interval_separator=",", Allow_redundant_separators allow_redundant_separators=Allow_redundant_separators::yes, Allow_empty allow_empty=Allow_empty::yes, Skip_whitespace skip_whitespace_arg=Skip_whitespace::yes) noexcept
Definition: boundary_set_text_format.h:52
std::string_view m_boundary_separator
Separator between start and end of a single interval.
Definition: boundary_set_text_format.h:73
void before_token(Parser &parser) const
Skip whitespace before tokens, if m_skip_whitespace == true.
Definition: boundary_set_text_format.h:89
void after_token(Parser &parser) const
Skip whitespace after tokens, if m_skip_whitespace == true.
Definition: boundary_set_text_format.h:94
std::string_view m_interval_separator
Separator between end of one interval and start of next interval.
Definition: boundary_set_text_format.h:76
Allow_empty m_allow_empty
When true, accept the empty set.
Definition: boundary_set_text_format.h:83
Top of the hierarchy.
Definition: format.h:38
Format tag to identify text format.
Definition: text_format.h:38