forked from mysql/mysql-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_char_traits.h
102 lines (90 loc) · 3.63 KB
/
my_char_traits.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* Copyright (c) 2024, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#ifndef MY_CHAR_TRAITS_INCLUDED
#define MY_CHAR_TRAITS_INCLUDED
#include <compare>
#include <cstdio>
#include <cstring>
#include <iosfwd>
template <class CharT>
struct my_char_traits;
/*
This is a standards-compliant, drop-in replacement for
std::char_traits<unsigned char>
We need this because clang libc++ is removing support for it in clang 19.
*/
template <>
struct my_char_traits<unsigned char> {
using char_type = unsigned char;
using int_type = unsigned int;
using off_type = std::streamoff;
using pos_type = std::streampos;
using standards = std::mbstate_t;
using comparison_category = std::strong_ordering;
static constexpr void assign(char_type &c1, const char_type &c2) noexcept {
c1 = c2;
}
static constexpr bool eq(char_type c1, char_type c2) noexcept {
return c1 == c2;
}
static constexpr bool lt(char_type c1, char_type c2) noexcept {
return c1 < c2;
}
static int compare(const char_type *s1, const char_type *s2,
std::size_t n) noexcept {
if (n == 0) return 0;
return memcmp(s1, s2, n);
}
static size_t length(const char_type *s) noexcept {
return strlen(static_cast<const char *>(static_cast<const void *>(s)));
}
static const char_type *find(const char_type *s, size_t n,
const char_type &a) noexcept {
if (n == 0) return nullptr;
return static_cast<const char_type *>(memchr(s, a, n));
}
static char_type *move(char_type *s1, const char_type *s2,
std::size_t n) noexcept {
if (n == 0) return s1;
return static_cast<char_type *>(memmove(s1, s2, n));
}
static char_type *copy(char_type *s1, const char_type *s2,
std::size_t n) noexcept {
if (n == 0) return s1;
return static_cast<char_type *>(memcpy(s1, s2, n));
}
static char_type *assign(char_type *s, std::size_t n, char_type a) noexcept {
if (n == 0) return s;
return static_cast<char_type *>(memset(s, a, n));
}
static constexpr int_type not_eof(int_type c) noexcept {
return eq_int_type(c, eof()) ? ~eof() : c;
}
static constexpr char_type to_char_type(int_type c) noexcept {
return static_cast<char_type>(c);
}
static constexpr int_type to_int_type(char_type c) noexcept { return c; }
static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept {
return c1 == c2;
}
static constexpr int_type eof() noexcept {
return static_cast<int_type>(EOF);
}
};
#endif // MY_CHAR_TRAITS_INCLUDED