- Notifications
You must be signed in to change notification settings - Fork 4k
/
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, 2025, 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
#defineMY_CHAR_TRAITS_INCLUDED
#include<compare>
#include<cstdio>
#include<cstring>
#include<iosfwd>
template <classCharT>
structmy_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 <>
structmy_char_traits<unsignedchar> {
using char_type = unsignedchar;
using int_type = unsignedint;
using off_type = std::streamoff;
using pos_type = std::streampos;
using standards = std::mbstate_t;
using comparison_category = std::strong_ordering;
staticconstexprvoidassign(char_type &c1, const char_type &c2) noexcept {
c1 = c2;
}
staticconstexprbooleq(char_type c1, char_type c2) noexcept {
return c1 == c2;
}
staticconstexprboollt(char_type c1, char_type c2) noexcept {
return c1 < c2;
}
staticintcompare(const char_type *s1, const char_type *s2,
std::size_t n) noexcept {
if (n == 0) return0;
returnmemcmp(s1, s2, n);
}
staticsize_tlength(const char_type *s) noexcept {
returnstrlen(static_cast<constchar *>(static_cast<constvoid *>(s)));
}
staticconst char_type *find(const char_type *s, size_t n,
const char_type &a) noexcept {
if (n == 0) returnnullptr;
returnstatic_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;
returnstatic_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;
returnstatic_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;
returnstatic_cast<char_type *>(memset(s, a, n));
}
staticconstexpr int_type not_eof(int_type c) noexcept {
returneq_int_type(c, eof()) ? ~eof() : c;
}
staticconstexpr char_type to_char_type(int_type c) noexcept {
returnstatic_cast<char_type>(c);
}
staticconstexpr int_type to_int_type(char_type c) noexcept { return c; }
staticconstexprbooleq_int_type(int_type c1, int_type c2) noexcept {
return c1 == c2;
}
staticconstexpr int_type eof() noexcept {
returnstatic_cast<int_type>(EOF);
}
};
#endif// MY_CHAR_TRAITS_INCLUDED