MySQL 9.3.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
collations.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 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 INCLUDE_MYSQL_STRINGS_COLLATIONS_H_
25#define INCLUDE_MYSQL_STRINGS_COLLATIONS_H_
26
27#include <cstddef>
28#include <string>
29#include <string_view>
30
31#include "mysql/strings/api.h"
32
34struct CHARSET_INFO;
35
36namespace mysql {
37namespace collation {
38
39/**
40 Initialize character set/collation library
41
42 @note initialize() after shutdown() is UB (untested).
43
44 @param charset_dir Optional "/\0"-terminated path to the directory
45 containing Index.xml
46 @param loader Optional user-specified hooks to the character
47 set/collation parser/initializer.
48*/
49MYSQL_STRINGS_EXPORT void initialize(const char *charset_dir = nullptr,
50 MY_CHARSET_LOADER *loader = nullptr);
51
52/**
53 Shutdown character set/collation library
54
55 This call is mainly necessary in ASAN etc. builds.
56
57 @note initialize() after shutdown() is UB (untested).
58*/
60
61/**
62 Normalizes character set/collation names
63*/
65 public:
66 /**
67 Constructor
68
69 @note throws std::bad_alloc
70 */
71 explicit Name(const char *name);
72
73 /**
74 Constructor
75
76 @note throws std::bad_alloc
77 */
78 Name(const char *name, size_t size);
79 ~Name() = default;
80
81 // These must be explicitly defined for clang on Windows due to
82 // __declspec(dllexport).
83 Name(const Name &) = default;
84 Name(Name &&) = default;
85 Name &operator=(const Name &) = default;
86 Name &operator=(Name &&) = default;
87
88 /**
89 Returns normalized name as std::string_view.
90 */
91 std::string_view to_string_view() const { return m_normalized; }
92
93 private:
94 std::string m_normalized;
95};
96
97/**
98 Find collation by its name
99
100 @param name Collation name
101
102 @returns pointer to a collation object on success, nullptr if not found
103*/
105
106/**
107 Find collation by its name
108
109 @param name '\0'-terminated string of collation name
110 (not normalized name is fine)
111
112 @returns pointer to a collation object on success, nullptr if not found
113*/
114inline const CHARSET_INFO *find_by_name(const char *name) {
115 return find_by_name(Name{name});
116}
117
118/**
119 Find collation by its number
120
121 @param id Collation id (hardcoded in library sources or
122 specified in Index.xml)
123
124 @returns pointer to a collation object on success, nullptr if not found
125*/
127
128/**
129 Find primary collation by its character set name
130
131 @param cs_name Character set name
132
133 @returns pointer to a collation object on success, nullptr if not found
134*/
136
137/**
138 Find primary collation by its character set name
139
140 @param cs_name '\0'-terminated string of character set name
141 (not normalized name is fine)
142
143 @returns pointer to a collation object on success, nullptr if not found
144*/
145inline const CHARSET_INFO *find_primary(const char *cs_name) {
146 return find_primary(Name{cs_name});
147}
148
149} // namespace collation
150} // namespace mysql
151
152#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:189
Normalizes character set/collation names.
Definition: collations.h:64
std::string_view to_string_view() const
Returns normalized name as std::string_view.
Definition: collations.h:91
Name(const Name &)=default
Name & operator=(Name &&)=default
Name & operator=(const Name &)=default
std::string m_normalized
Definition: collations.h:94
Name(Name &&)=default
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:76
MYSQL_STRINGS_EXPORT const CHARSET_INFO * find_by_id(unsigned id)
Find collation by its number.
Definition: collations.cc:80
MYSQL_STRINGS_EXPORT void initialize(const char *charset_dir=nullptr, MY_CHARSET_LOADER *loader=nullptr)
Initialize character set/collation library.
Definition: collations.cc:62
MYSQL_STRINGS_EXPORT const CHARSET_INFO * find_primary(Name cs_name)
Find primary collation by its character set name.
Definition: collations.cc:84
MYSQL_STRINGS_EXPORT void shutdown()
Shutdown character set/collation library.
Definition: collations.cc:69
Definition: instrumented_condition_variable.h:32
size_t size(const char *const c)
Definition: base64.h:46
case opt name
Definition: sslopt-case.h:29
Definition: m_ctype.h:421