MySQL 8.4.3
Source Code Documentation
collations.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 2024, 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 INCLUDE_MYSQL_STRINGS_COLLATIONS_H_
25#define INCLUDE_MYSQL_STRINGS_COLLATIONS_H_
26
27#include <cstddef>
28#include <string>
29
30#include "mysql/strings/api.h"
31
33struct CHARSET_INFO;
34
35namespace mysql {
36namespace collation {
37
38/**
39 Initialize character set/collation library
40
41 @note initialize() after shutdown() is UB (untested).
42
43 @param charset_dir Optional "/\0"-terminated path to the directory
44 containing Index.xml
45 @param loader Optional user-specified hooks to the character
46 set/collation parser/initializer.
47*/
48MYSQL_STRINGS_EXPORT void initialize(const char *charset_dir = nullptr,
49 MY_CHARSET_LOADER *loader = nullptr);
50
51/**
52 Shutdown character set/collation library
53
54 This call is mainly necessary in ASAN etc. builds.
55
56 @note initialize() after shutdown() is UB (untested).
57*/
59
60/**
61 Normalizes character set/collation names
62*/
64 public:
65 /**
66 Constructor
67
68 @note throws std::bad_alloc
69 */
70 explicit Name(const char *name);
71
72 /**
73 Constructor
74
75 @note throws std::bad_alloc
76 */
77 Name(const char *name, size_t size);
78
79 /**
80 Constructor
81
82 @note throws std::bad_alloc
83 */
84 Name(const Name &);
85
86 Name(Name &&) noexcept;
87
88 ~Name();
89
90 Name &operator=(const Name &);
91 Name &operator=(Name &&) noexcept;
92
93 /**
94 Returns normalized name as std::string
95 */
96 std::string operator()() const { return m_normalized; }
97
98 private:
99 const char *m_normalized{nullptr};
100};
101
102/**
103 Find collation by its name
104
105 @param name Collation name
106
107 @returns pointer to a collation object on success, nullptr if not found
108*/
110
111/**
112 Find collation by its name
113
114 @param name '\0'-terminated string of collation name
115 (not normalized name is fine)
116
117 @returns pointer to a collation object on success, nullptr if not found
118*/
119inline const CHARSET_INFO *find_by_name(const char *name) {
120 return find_by_name(Name{name});
121}
122
123/**
124 Find collation by its number
125
126 @param id Collation id (hardcoded in library sources or
127 specified in Index.xml)
128
129 @returns pointer to a collation object on success, nullptr if not found
130*/
132
133/**
134 Find primary collation by its character set name
135
136 @param cs_name Character set name
137
138 @returns pointer to a collation object on success, nullptr if not found
139*/
141
142/**
143 Find primary collation by its character set name
144
145 @param cs_name '\0'-terminated string of character set name
146 (not normalized name is fine)
147
148 @returns pointer to a collation object on success, nullptr if not found
149*/
150inline const CHARSET_INFO *find_primary(const char *cs_name) {
151 return find_primary(Name{cs_name});
152}
153
154/**
155 Find binary collation by its character set name
156
157 @param cs_name Character set name
158
159 @returns pointer to a collation object on success, nullptr if not found
160*/
162 const Name &cs_name);
163
164/**
165 Find binary collation by its character set name
166
167 @param cs_name '\0'-terminated character set name
168 (not normalized name is fine)
169
170 @returns pointer to a collation object on success, nullptr if not found
171*/
172inline const CHARSET_INFO *find_default_binary(const char *cs_name) {
173 return find_default_binary(Name{cs_name});
174}
175
176} // namespace collation
177} // namespace mysql
178
179#endif // INCLUDE_MYSQL_STRINGS_COLLATIONS_H_
#define MYSQL_STRINGS_EXPORT
Definition: api.h:47
static Mysys_charset_loader * loader
Definition: charset.cc:185
User-specified callback interface for collation parser/initializer.
Definition: m_ctype.h:190
Normalizes character set/collation names.
Definition: collations.h:63
Name & operator=(Name &&) noexcept
Name & operator=(const Name &)
const char * collation
Definition: audit_api_message_emit.cc:184
MYSQL_STRINGS_EXPORT const CHARSET_INFO * find_by_name(const Name &name)
Find collation by its name.
Definition: collations.cc:112
MYSQL_STRINGS_EXPORT const CHARSET_INFO * find_by_id(unsigned id)
Find collation by its number.
Definition: collations.cc:116
MYSQL_STRINGS_EXPORT void initialize(const char *charset_dir=nullptr, MY_CHARSET_LOADER *loader=nullptr)
Initialize character set/collation library.
Definition: collations.cc:98
MYSQL_STRINGS_EXPORT const CHARSET_INFO * find_default_binary(const Name &cs_name)
Find binary collation by its character set name.
Definition: collations.cc:126
MYSQL_STRINGS_EXPORT const CHARSET_INFO * find_primary(Name cs_name)
Find primary collation by its character set name.
Definition: collations.cc:120
MYSQL_STRINGS_EXPORT void shutdown()
Shutdown character set/collation library.
Definition: collations.cc:105
Definition: instrumented_condition_variable.h:32
size_t size(const char *const c)
Definition: base64.h:46
Definition: gcs_xcom_synode.h:64
case opt name
Definition: sslopt-case.h:29
Definition: m_ctype.h:423