From f801fc1fe85f1e3444f0c1aa7636f52d7c1b7966 Mon Sep 17 00:00:00 2001 From: neebyA <126654084+neebyA@users.noreply.github.com> Date: Sun, 11 May 2025 15:08:25 -0700 Subject: [PATCH] Fix Mac build for Xcode 16.3 (#1558) --- src/util/helpers/StringHelpers.h | 86 ++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/src/util/helpers/StringHelpers.h b/src/util/helpers/StringHelpers.h index 54141808..a98344d6 100644 --- a/src/util/helpers/StringHelpers.h +++ b/src/util/helpers/StringHelpers.h @@ -2,6 +2,92 @@ #include "boost/nowide/convert.hpp" #include +// Definition for removed templates in Apple Clang 17 +#if defined(__apple_build_version__) && (__apple_build_version__ >= 17000000) +namespace std { + template<> + struct char_traits { + using char_type = uint16be; + using int_type = int; + using off_type = streamoff; + using pos_type = streampos; + using state_type = mbstate_t; + + static inline void constexpr assign(char_type& c1, const char_type& c2) noexcept { + c1 = c2; + } + + static inline constexpr bool eq(char_type c1, char_type c2) noexcept { + return c1 == c2; + } + + static inline constexpr bool lt(char_type c1, char_type c2) noexcept { + return c1 < c2; + } + + static constexpr int compare(const char_type* s1, const char_type* s2, size_t n) { + for (; n; --n, ++s1, ++s2) { + if (lt(*s1, *s2)) return -1; + if (lt(*s2, *s1)) return 1; + } + return 0; + } + + static constexpr size_t length(const char_type* s) { + size_t len = 0; + for (; !eq(*s, char_type(0)); ++s) ++len; + return len; + } + + static constexpr const char_type* find(const char_type* s, size_t n, const char_type& a) { + for (; n; --n) { + if (eq(*s, a)) + return s; + ++s; + } + return nullptr; + } + + static constexpr char_type* move(char_type* s1, const char_type* s2, size_t n) { + if (n == 0) return s1; + return static_cast(memmove(s1, s2, n * sizeof(char_type))); + } + + static constexpr char_type* copy(char_type* s1, const char_type* s2, size_t n) { + if (n == 0) return s1; + return static_cast(memcpy(s1, s2, n * sizeof(char_type))); + } + + static constexpr char_type* assign(char_type* s, size_t n, char_type a) { + char_type* r = s; + for (; n; --n, ++s) + assign(*s, a); + return r; + } + + static inline constexpr char_type to_char_type(int_type c) noexcept { + return char_type(c); + } + + static inline constexpr int_type to_int_type(char_type c) noexcept { + return int_type(c); + } + + static inline constexpr bool eq_int_type(int_type c1, int_type c2) noexcept { + return c1 == c2; + } + + static inline constexpr int_type eof() noexcept { + return static_cast(EOF); + } + + static inline constexpr int_type not_eof(int_type c) noexcept { + return eq_int_type(c, eof()) ? ~eof() : c; + } + }; +} +#endif + // todo - move the Cafe/PPC specific parts to CafeString.h eventually namespace StringHelpers {