From 396259a0f88e6f908c6d841f13c113d5f0d0ec26 Mon Sep 17 00:00:00 2001 From: Alexandru Placinta Date: Thu, 10 Apr 2025 16:37:16 +0200 Subject: [PATCH] Add char_traits --- Release/include/cpprest/char_traits.h | 74 +++++++++++++++++++++++++++ Release/include/cpprest/streams.h | 1 + 2 files changed, 75 insertions(+) create mode 100644 Release/include/cpprest/char_traits.h diff --git a/Release/include/cpprest/char_traits.h b/Release/include/cpprest/char_traits.h new file mode 100644 index 0000000000..1e7d172bb0 --- /dev/null +++ b/Release/include/cpprest/char_traits.h @@ -0,0 +1,74 @@ +#include +#include +#include + +namespace std +{ +template<> +struct char_traits +{ + using char_type = uint8_t; + using int_type = unsigned int; + using off_type = std::streamoff; + using pos_type = std::streampos; + using state_type = std::mbstate_t; + + static void assign(char_type& c1, const char_type& c2) noexcept { c1 = c2; } + + static bool eq(char_type c1, char_type c2) noexcept { return c1 == c2; } + + static bool lt(char_type c1, char_type c2) noexcept { return c1 < c2; } + + static int compare(const char_type* s1, const char_type* s2, std::size_t n) noexcept + { + return std::memcmp(s1, s2, n); + } + + static std::size_t length(const char_type* s) noexcept + { + const char_type* p = s; + while (*p != 0) + ++p; + return p - s; + } + + static const char_type* find(const char_type* s, std::size_t n, const char_type& a) noexcept + { + for (std::size_t i = 0; i < n; ++i) + { + if (eq(s[i], a)) + { + return s + i; + } + } + + return nullptr; + } + + static char_type* move(char_type* s1, const char_type* s2, std::size_t n) noexcept + { + return static_cast(std::memmove(s1, s2, n)); + } + + static char_type* copy(char_type* s1, const char_type* s2, std::size_t n) noexcept + { + return static_cast(std::memcpy(s1, s2, n)); + } + + static char_type* assign(char_type* s, std::size_t n, char_type a) noexcept + { + std::fill_n(s, n, a); + return s; + } + + static int_type not_eof(int_type c) noexcept { return c == eof() ? ~eof() : c; } + + static char_type to_char_type(int_type c) noexcept { return static_cast(c); } + + static int_type to_int_type(char_type c) noexcept { return static_cast(c); } + + static bool eq_int_type(int_type c1, int_type c2) noexcept { return c1 == c2; } + + static int_type eof() noexcept { return static_cast(-1); } +}; +} // namespace std diff --git a/Release/include/cpprest/streams.h b/Release/include/cpprest/streams.h index b6c3864028..e505c841ef 100644 --- a/Release/include/cpprest/streams.h +++ b/Release/include/cpprest/streams.h @@ -15,6 +15,7 @@ #ifndef CASA_STREAMS_H #define CASA_STREAMS_H +#include "char_traits.h" #include "cpprest/astreambuf.h" #include #include