MySQL 8.2.0
Source Code Documentation
collations.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 2023, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef INCLUDE_MYSQL_STRINGS_COLLATIONS_H_
24#define INCLUDE_MYSQL_STRINGS_COLLATIONS_H_
25
26#include <cstddef>
27#include <string>
28
29#include "mysql/strings/api.h"
30
32struct CHARSET_INFO;
33
34namespace mysql {
35namespace collation {
36
37/**
38 Initialize character set/collation library
39
40 @note initialize() after shutdown() is UB (untested).
41
42 @param charset_dir Optional "/\0"-terminated path to the directory
43 containing Index.xml
44 @param loader Optional user-specified hooks to the character
45 set/collation parser/initializer.
46*/
47MYSQL_STRINGS_EXPORT void initialize(const char *charset_dir = nullptr,
48 MY_CHARSET_LOADER *loader = nullptr);
49
50/**
51 Shutdown character set/collation library
52
53 This call is mainly necessary in ASAN etc. builds.
54
55 @note initialize() after shutdown() is UB (untested).
56*/
58
59/**
60 Normalizes character set/collation names
61*/
63 public:
64 /**
65 Constructor
66
67 @note throws std::bad_alloc
68 */
69 explicit Name(const char *name);
70
71 /**
72 Constructor
73
74 @note throws std::bad_alloc
75 */
76 Name(const char *name, size_t size);
77
78 /**
79 Constructor
80
81 @note throws std::bad_alloc
82 */
83 Name(const Name &);
84
85 Name(Name &&) noexcept;
86
87 ~Name();
88
89 Name &operator=(const Name &);
90 Name &operator=(Name &&) noexcept;
91
92 /**
93 Returns normalized name as std::string
94 */
95 std::string operator()() const { return m_normalized; }
96
97 private:
98 const char *m_normalized{nullptr};
99};
100
101/**
102 Find collation by its name
103
104 @param name Collation name
105
106 @returns pointer to a collation object on success, nullptr if not found
107*/
109
110/**
111 Find collation by its name
112
113 @param name '\0'-terminated string of collation name
114 (not normalized name is fine)
115
116 @returns pointer to a collation object on success, nullptr if not found
117*/
118inline const CHARSET_INFO *find_by_name(const char *name) {
119 return find_by_name(Name{name});
120}
121
122/**
123 Find collation by its number
124
125 @param id Collation id (hardcoded in library sources or
126 specified in Index.xml)
127
128 @returns pointer to a collation object on success, nullptr if not found
129*/
131
132/**
133 Find primary collation by its character set name
134
135 @param cs_name Character set name
136
137 @returns pointer to a collation object on success, nullptr if not found
138*/
140
141/**
142 Find primary collation by its character set name
143
144 @param cs_name '\0'-terminated string of character set name
145 (not normalized name is fine)
146
147 @returns pointer to a collation object on success, nullptr if not found
148*/
149inline const CHARSET_INFO *find_primary(const char *cs_name) {
150 return find_primary(Name{cs_name});
151}
152
153/**
154 Find binary collation by its character set name
155
156 @param cs_name Character set name
157
158 @returns pointer to a collation object on success, nullptr if not found
159*/
161 const Name &cs_name);
162
163/**
164 Find binary collation by its character set name
165
166 @param cs_name '\0'-terminated character set name
167 (not normalized name is fine)
168
169 @returns pointer to a collation object on success, nullptr if not found
170*/
171inline const CHARSET_INFO *find_default_binary(const char *cs_name) {
172 return find_default_binary(Name{cs_name});
173}
174
175} // namespace collation
176} // namespace mysql
177
178#endif // INCLUDE_MYSQL_STRINGS_COLLATIONS_H_
#define MYSQL_STRINGS_EXPORT
Definition: api.h:46
static Mysys_charset_loader * loader
Definition: charset.cc:184
User-specified callback interface for collation parser/initializer.
Definition: m_ctype.h:189
Normalizes character set/collation names.
Definition: collations.h:62
Name & operator=(Name &&) noexcept
Name & operator=(const Name &)
const char * collation
Definition: audit_api_message_emit.cc:183
MYSQL_STRINGS_EXPORT const CHARSET_INFO * find_by_name(const Name &name)
Find collation by its name.
Definition: collations.cc:111
MYSQL_STRINGS_EXPORT void initialize(const char *charset_dir=nullptr, MY_CHARSET_LOADER *loader=nullptr)
Initialize character set/collation library.
Definition: collations.cc:97
MYSQL_STRINGS_EXPORT const CHARSET_INFO * find_default_binary(const Name &cs_name)
Find binary collation by its character set name.
Definition: collations.cc:123
MYSQL_STRINGS_EXPORT const CHARSET_INFO * find_by_id(unsigned id)
Find collation by its number.
MYSQL_STRINGS_EXPORT const CHARSET_INFO * find_primary(Name cs_name)
Find primary collation by its character set name.
Definition: collations.cc:117
MYSQL_STRINGS_EXPORT void shutdown()
Shutdown character set/collation library.
Definition: collations.cc:104
Definition: instrumented_condition_variable.h:31
Definition: varlen_sort.h:183
case opt name
Definition: sslopt-case.h:32
Definition: m_ctype.h:422