| 
 | 1 | +#include <cstdint>  | 
 | 2 | +#include <cstring>  | 
 | 3 | +#include <string>  | 
 | 4 | + | 
 | 5 | +namespace std  | 
 | 6 | +{  | 
 | 7 | +template<>  | 
 | 8 | +struct char_traits<uint8_t>  | 
 | 9 | +{  | 
 | 10 | +    using char_type = uint8_t;  | 
 | 11 | +    using int_type = unsigned int;  | 
 | 12 | +    using off_type = std::streamoff;  | 
 | 13 | +    using pos_type = std::streampos;  | 
 | 14 | +    using state_type = std::mbstate_t;  | 
 | 15 | + | 
 | 16 | +    static void assign(char_type& c1, const char_type& c2) noexcept { c1 = c2; }  | 
 | 17 | + | 
 | 18 | +    static bool eq(char_type c1, char_type c2) noexcept { return c1 == c2; }  | 
 | 19 | + | 
 | 20 | +    static bool lt(char_type c1, char_type c2) noexcept { return c1 < c2; }  | 
 | 21 | + | 
 | 22 | +    static int compare(const char_type* s1, const char_type* s2, std::size_t n) noexcept  | 
 | 23 | +    {  | 
 | 24 | +        return std::memcmp(s1, s2, n);  | 
 | 25 | +    }  | 
 | 26 | + | 
 | 27 | +    static std::size_t length(const char_type* s) noexcept  | 
 | 28 | +    {  | 
 | 29 | +        const char_type* p = s;  | 
 | 30 | +        while (*p != 0)  | 
 | 31 | +            ++p;  | 
 | 32 | +        return p - s;  | 
 | 33 | +    }  | 
 | 34 | + | 
 | 35 | +    static const char_type* find(const char_type* s, std::size_t n, const char_type& a) noexcept  | 
 | 36 | +    {  | 
 | 37 | +        for (std::size_t i = 0; i < n; ++i)  | 
 | 38 | +        {  | 
 | 39 | +            if (eq(s[i], a))  | 
 | 40 | +            {  | 
 | 41 | +                return s + i;  | 
 | 42 | +            }  | 
 | 43 | +        }  | 
 | 44 | + | 
 | 45 | +        return nullptr;  | 
 | 46 | +    }  | 
 | 47 | + | 
 | 48 | +    static char_type* move(char_type* s1, const char_type* s2, std::size_t n) noexcept  | 
 | 49 | +    {  | 
 | 50 | +        return static_cast<char_type*>(std::memmove(s1, s2, n));  | 
 | 51 | +    }  | 
 | 52 | + | 
 | 53 | +    static char_type* copy(char_type* s1, const char_type* s2, std::size_t n) noexcept  | 
 | 54 | +    {  | 
 | 55 | +        return static_cast<char_type*>(std::memcpy(s1, s2, n));  | 
 | 56 | +    }  | 
 | 57 | + | 
 | 58 | +    static char_type* assign(char_type* s, std::size_t n, char_type a) noexcept  | 
 | 59 | +    {  | 
 | 60 | +        std::fill_n(s, n, a);  | 
 | 61 | +        return s;  | 
 | 62 | +    }  | 
 | 63 | + | 
 | 64 | +    static int_type not_eof(int_type c) noexcept { return c == eof() ? ~eof() : c; }  | 
 | 65 | + | 
 | 66 | +    static char_type to_char_type(int_type c) noexcept { return static_cast<char_type>(c); }  | 
 | 67 | + | 
 | 68 | +    static int_type to_int_type(char_type c) noexcept { return static_cast<int_type>(c); }  | 
 | 69 | + | 
 | 70 | +    static bool eq_int_type(int_type c1, int_type c2) noexcept { return c1 == c2; }  | 
 | 71 | + | 
 | 72 | +    static int_type eof() noexcept { return static_cast<int_type>(-1); }  | 
 | 73 | +};  | 
 | 74 | +} // namespace std  | 
0 commit comments