|
| 1 | +#pragma once |
| 2 | + |
1 | 3 | #include <string>
|
2 | 4 |
|
3 |
| -typedef std::basic_string<unsigned char> ustring; |
| 5 | +// Define custom char traits since std::char_traits<unsigend char> is not part of C++ standard |
| 6 | +struct uchar_traits : std::char_traits<char> |
| 7 | +{ |
| 8 | + using super = std::char_traits<char>; |
| 9 | + using char_type = unsigned char; |
| 10 | + |
| 11 | + static void assign(char_type& c1, const char_type& c2) noexcept { |
| 12 | + c1 = c2; |
| 13 | + } |
| 14 | + static char_type* assign(char_type* ptr, std::size_t count, char_type c2) { |
| 15 | + return reinterpret_cast<char_type*>( |
| 16 | + super::assign(reinterpret_cast<char*>(ptr), count, static_cast<char>(c2))); |
| 17 | + } |
| 18 | + |
| 19 | + static char_type* move(char_type* dest, const char_type* src, std::size_t count) { |
| 20 | + return reinterpret_cast<char_type*>( |
| 21 | + super::move(reinterpret_cast<char*>(dest), reinterpret_cast<const char*>(src), count)); |
| 22 | + } |
| 23 | + |
| 24 | + static char_type* copy(char_type* dest, const char_type* src, std::size_t count) { |
| 25 | + return reinterpret_cast<char_type*>( |
| 26 | + super::copy(reinterpret_cast<char*>(dest), reinterpret_cast<const char*>(src), count)); |
| 27 | + } |
| 28 | + |
| 29 | + static int compare(const char_type* s1, const char_type* s2, std::size_t count) { |
| 30 | + return super::compare(reinterpret_cast<const char*>(s1), reinterpret_cast<const char*>(s2), count); |
| 31 | + } |
| 32 | + |
| 33 | + static char_type to_char_type(int_type c) noexcept { |
| 34 | + return static_cast<char_type>(c); |
| 35 | + } |
| 36 | +}; |
| 37 | + |
| 38 | +typedef std::basic_string<unsigned char, uchar_traits> ustring; |
4 | 39 | typedef unsigned int uint;
|
5 | 40 | typedef unsigned char u8;
|
0 commit comments