From 637755d6f9e15215f2891eb1df13ae00040aa60d Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 8 Apr 2025 17:56:55 +0200 Subject: [PATCH] Fix ustring type relying on non-standard C++ behavior --- src/types.h | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/types.h b/src/types.h index 3700d58..c0c2b21 100644 --- a/src/types.h +++ b/src/types.h @@ -1,5 +1,40 @@ +#pragma once + #include -typedef std::basic_string ustring; +// Define custom char traits since std::char_traits is not part of C++ standard +struct uchar_traits : std::char_traits +{ + using super = std::char_traits; + using char_type = unsigned char; + + static void assign(char_type& c1, const char_type& c2) noexcept { + c1 = c2; + } + static char_type* assign(char_type* ptr, std::size_t count, char_type c2) { + return reinterpret_cast( + super::assign(reinterpret_cast(ptr), count, static_cast(c2))); + } + + static char_type* move(char_type* dest, const char_type* src, std::size_t count) { + return reinterpret_cast( + super::move(reinterpret_cast(dest), reinterpret_cast(src), count)); + } + + static char_type* copy(char_type* dest, const char_type* src, std::size_t count) { + return reinterpret_cast( + super::copy(reinterpret_cast(dest), reinterpret_cast(src), count)); + } + + static int compare(const char_type* s1, const char_type* s2, std::size_t count) { + return super::compare(reinterpret_cast(s1), reinterpret_cast(s2), count); + } + + static char_type to_char_type(int_type c) noexcept { + return static_cast(c); + } +}; + +typedef std::basic_string ustring; typedef unsigned int uint; typedef unsigned char u8;