MySQL 9.2.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
my_char_traits.h
Go to the documentation of this file.
1/* Copyright (c) 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 MY_CHAR_TRAITS_INCLUDED
25#define MY_CHAR_TRAITS_INCLUDED
26
27#include <compare>
28#include <cstdio>
29#include <cstring>
30#include <iosfwd>
31
32template <class CharT>
34
35/*
36 This is a standards-compliant, drop-in replacement for
37 std::char_traits<unsigned char>
38 We need this because clang libc++ is removing support for it in clang 19.
39 */
40template <>
41struct my_char_traits<unsigned char> {
42 using char_type = unsigned char;
43 using int_type = unsigned int;
44 using off_type = std::streamoff;
45 using pos_type = std::streampos;
46 using standards = std::mbstate_t;
47 using comparison_category = std::strong_ordering;
48
49 static constexpr void assign(char_type &c1, const char_type &c2) noexcept {
50 c1 = c2;
51 }
52 static constexpr bool eq(char_type c1, char_type c2) noexcept {
53 return c1 == c2;
54 }
55 static constexpr bool lt(char_type c1, char_type c2) noexcept {
56 return c1 < c2;
57 }
58
59 static int compare(const char_type *s1, const char_type *s2,
60 std::size_t n) noexcept {
61 if (n == 0) return 0;
62 return memcmp(s1, s2, n);
63 }
64 static size_t length(const char_type *s) noexcept {
65 return strlen(static_cast<const char *>(static_cast<const void *>(s)));
66 }
67 static const char_type *find(const char_type *s, size_t n,
68 const char_type &a) noexcept {
69 if (n == 0) return nullptr;
70 return static_cast<const char_type *>(memchr(s, a, n));
71 }
72 static char_type *move(char_type *s1, const char_type *s2,
73 std::size_t n) noexcept {
74 if (n == 0) return s1;
75 return static_cast<char_type *>(memmove(s1, s2, n));
76 }
77 static char_type *copy(char_type *s1, const char_type *s2,
78 std::size_t n) noexcept {
79 if (n == 0) return s1;
80 return static_cast<char_type *>(memcpy(s1, s2, n));
81 }
82 static char_type *assign(char_type *s, std::size_t n, char_type a) noexcept {
83 if (n == 0) return s;
84 return static_cast<char_type *>(memset(s, a, n));
85 }
86
87 static constexpr int_type not_eof(int_type c) noexcept {
88 return eq_int_type(c, eof()) ? ~eof() : c;
89 }
90 static constexpr char_type to_char_type(int_type c) noexcept {
91 return static_cast<char_type>(c);
92 }
93 static constexpr int_type to_int_type(char_type c) noexcept { return c; }
94 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept {
95 return c1 == c2;
96 }
97 static constexpr int_type eof() noexcept {
98 return static_cast<int_type>(EOF);
99 }
100};
101
102#endif // MY_CHAR_TRAITS_INCLUDED
std::streampos pos_type
Definition: my_char_traits.h:45
static const char_type * find(const char_type *s, size_t n, const char_type &a) noexcept
Definition: my_char_traits.h:67
static constexpr int_type to_int_type(char_type c) noexcept
Definition: my_char_traits.h:93
static constexpr bool eq(char_type c1, char_type c2) noexcept
Definition: my_char_traits.h:52
static char_type * assign(char_type *s, std::size_t n, char_type a) noexcept
Definition: my_char_traits.h:82
static constexpr void assign(char_type &c1, const char_type &c2) noexcept
Definition: my_char_traits.h:49
static char_type * move(char_type *s1, const char_type *s2, std::size_t n) noexcept
Definition: my_char_traits.h:72
std::streamoff off_type
Definition: my_char_traits.h:44
std::strong_ordering comparison_category
Definition: my_char_traits.h:47
static size_t length(const char_type *s) noexcept
Definition: my_char_traits.h:64
static constexpr int_type not_eof(int_type c) noexcept
Definition: my_char_traits.h:87
static constexpr char_type to_char_type(int_type c) noexcept
Definition: my_char_traits.h:90
std::mbstate_t standards
Definition: my_char_traits.h:46
static char_type * copy(char_type *s1, const char_type *s2, std::size_t n) noexcept
Definition: my_char_traits.h:77
static constexpr int_type eof() noexcept
Definition: my_char_traits.h:97
static constexpr bool lt(char_type c1, char_type c2) noexcept
Definition: my_char_traits.h:55
unsigned char char_type
Definition: my_char_traits.h:42
unsigned int int_type
Definition: my_char_traits.h:43
static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept
Definition: my_char_traits.h:94
static int compare(const char_type *s1, const char_type *s2, std::size_t n) noexcept
Definition: my_char_traits.h:59
Definition: my_char_traits.h:33
int n
Definition: xcom_base.cc:509