Skip to content

Commit f801fc1

Browse files
authored
Fix Mac build for Xcode 16.3 (#1558)
1 parent 6148459 commit f801fc1

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

src/util/helpers/StringHelpers.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,92 @@
22
#include "boost/nowide/convert.hpp"
33
#include <charconv>
44

5+
// Definition for removed templates in Apple Clang 17
6+
#if defined(__apple_build_version__) && (__apple_build_version__ >= 17000000)
7+
namespace std {
8+
template<>
9+
struct char_traits<uint16be> {
10+
using char_type = uint16be;
11+
using int_type = int;
12+
using off_type = streamoff;
13+
using pos_type = streampos;
14+
using state_type = mbstate_t;
15+
16+
static inline void constexpr assign(char_type& c1, const char_type& c2) noexcept {
17+
c1 = c2;
18+
}
19+
20+
static inline constexpr bool eq(char_type c1, char_type c2) noexcept {
21+
return c1 == c2;
22+
}
23+
24+
static inline constexpr bool lt(char_type c1, char_type c2) noexcept {
25+
return c1 < c2;
26+
}
27+
28+
static constexpr int compare(const char_type* s1, const char_type* s2, size_t n) {
29+
for (; n; --n, ++s1, ++s2) {
30+
if (lt(*s1, *s2)) return -1;
31+
if (lt(*s2, *s1)) return 1;
32+
}
33+
return 0;
34+
}
35+
36+
static constexpr size_t length(const char_type* s) {
37+
size_t len = 0;
38+
for (; !eq(*s, char_type(0)); ++s) ++len;
39+
return len;
40+
}
41+
42+
static constexpr const char_type* find(const char_type* s, size_t n, const char_type& a) {
43+
for (; n; --n) {
44+
if (eq(*s, a))
45+
return s;
46+
++s;
47+
}
48+
return nullptr;
49+
}
50+
51+
static constexpr char_type* move(char_type* s1, const char_type* s2, size_t n) {
52+
if (n == 0) return s1;
53+
return static_cast<char_type*>(memmove(s1, s2, n * sizeof(char_type)));
54+
}
55+
56+
static constexpr char_type* copy(char_type* s1, const char_type* s2, size_t n) {
57+
if (n == 0) return s1;
58+
return static_cast<char_type*>(memcpy(s1, s2, n * sizeof(char_type)));
59+
}
60+
61+
static constexpr char_type* assign(char_type* s, size_t n, char_type a) {
62+
char_type* r = s;
63+
for (; n; --n, ++s)
64+
assign(*s, a);
65+
return r;
66+
}
67+
68+
static inline constexpr char_type to_char_type(int_type c) noexcept {
69+
return char_type(c);
70+
}
71+
72+
static inline constexpr int_type to_int_type(char_type c) noexcept {
73+
return int_type(c);
74+
}
75+
76+
static inline constexpr bool eq_int_type(int_type c1, int_type c2) noexcept {
77+
return c1 == c2;
78+
}
79+
80+
static inline constexpr int_type eof() noexcept {
81+
return static_cast<int_type>(EOF);
82+
}
83+
84+
static inline constexpr int_type not_eof(int_type c) noexcept {
85+
return eq_int_type(c, eof()) ? ~eof() : c;
86+
}
87+
};
88+
}
89+
#endif
90+
591
// todo - move the Cafe/PPC specific parts to CafeString.h eventually
692
namespace StringHelpers
793
{

0 commit comments

Comments
 (0)