--- include/cpprest/details/char_traits.h.orig 2025-07-02 14:23:43 UTC +++ include/cpprest/details/char_traits.h @@ -0,0 +1,102 @@ +// +// Created by sigsegv on 6/28/25. +// + +#ifndef CPPRESTSDK_ROOT_CHAR_TRAITS_H +#define CPPRESTSDK_ROOT_CHAR_TRAITS_H + +#include +#include + +namespace utility { + +namespace detail { + +template struct IntTypeFor { + typedef typename std::conditional::value, unsigned long long int, long long int>::type type; +}; +template <> struct IntTypeFor { + typedef typename std::char_traits::int_type type; +}; +template <> struct IntTypeFor { + typedef typename std::make_unsigned::int_type>::type type; +}; + +template class DetailCharTraits +{ +public: + using char_type = T; + using int_type = typename IntTypeFor::type; + using off_type = std::streamoff; + using pos_type = std::streampos; + using state_type = mbstate_t; + + static void assign(char_type& r, const char_type& a) noexcept { r = a; } + static char_type to_char_type(int_type c) noexcept { return char_type(c); } + static int_type to_int_type(char_type c) noexcept { return c; } + static bool eq(char_type a, char_type b) noexcept { return a == b; } + static bool lt(char_type a, char_type b) noexcept { return a < b; } + static int compare(const char_type* s1,const char_type* s2,size_t n){ + for (; n--; ++s1, ++s2) { + if (!eq(*s1, *s2)) + return lt(*s1,*s2)?-1:1; + } + return 0; + } + static size_t length(const char_type* s){ + const char_type* p = s; + while (*p) + ++p; + return size_t(p - s); + } + static const char_type* find(const char_type* s,size_t n,const char_type& a){ + for (; n--; ++s) + { + if (eq(*s, a)) + return s; + return nullptr; + } + } + static char_type* move (char_type* r,const char_type* s,size_t n){ + return (char_type*)memmove(r, s, n * sizeof(char_type)); + } + static char_type* copy (char_type* r,const char_type* s,size_t n){ + return (char_type*)memcpy (r, s, n * sizeof(char_type)); + } + static char_type* assign(char_type* r,size_t n,char_type a){ + if (sizeof(char_type) == 1) + { + return (char_type*)memset(r, a, n); + } + else + { + for (char_type *s = r; n--; ++s) + { + *s = a; + } + } + } + static int_type eof() noexcept { return ~0u; } + static int_type not_eof(int_type c) noexcept { return c == eof() ? 0 : c; } +}; + +template struct CanUseStdCharTraits : public std::false_type +{ +public: + typedef DetailCharTraits TraitsType; +}; + +template struct CanUseStdCharTraits::eq(std::declval(), std::declval()))> : public std::true_type +{ +public: + typedef std::char_traits TraitsType; +}; + +} + +template struct CanUseStdCharTraits : detail::CanUseStdCharTraits::type>::type> { +}; + +} + +#endif // CPPRESTSDK_ROOT_CHAR_TRAITS_H