diff --git a/include/sexpp/sexp.h b/include/sexpp/sexp.h index bb6ae4e..2a69083 100644 --- a/include/sexpp/sexp.h +++ b/include/sexpp/sexp.h @@ -99,14 +99,80 @@ class sexp_input_stream_t; * SEXP simple string */ -typedef uint8_t octet_t; +//typedef uint8_t octet_t; -class SEXP_PUBLIC_SYMBOL sexp_simple_string_t : public std::basic_string, +using octet_t = uint8_t; + +struct octet_traits : std::char_traits { + static void assign(char_type& r, const char_type& a) { + r = a; + } + + static bool eq(const char_type& c1, const char_type& c2) { + return c1 == c2; + } + + static bool lt(const char_type& c1, const char_type& c2) { + return c1 < c2; + } + + static int compare(const char_type* s1, const char_type* s2, std::size_t n) { + while ( n-- != 0 ) { + if ( *s1 < *s2 ) return -1; + if ( *s2++ < *s1++ ) return 1; + } + return 0; + } + + static const char_type* find(const char_type* s, std::size_t n, const char_type& a) { + while ( n-- != 0 ) { + if ( *s == a ) return s; + s++; + } + return nullptr; + } + + static char_type* move(char_type* s1, const char_type* s2, std::size_t n) { + return (char_type*)std::memmove(s1, s2, n); + } + + static char_type* copy(char_type* s1, const char_type* s2, std::size_t n) { + return (char_type*)std::memcpy(s1, s2, n); + } + + static char_type* assign(char_type* s, std::size_t n, char_type a) { + return (char_type*)std::memset(s, a, n); + } + + static char_type to_char_type(const int_type& c) { + return char_type(c); + } + + static int_type to_int_type(const char_type& c) { + return int_type(c); + } + + static bool eq_int_type(const int_type& c1, const int_type& c2) { + return c1 == c2; + } + + static int_type eof() { + return static_cast(EOF); + } + + static int_type not_eof(const int_type& c) { + return eq_int_type(c, eof()) ? 0 : c; + } +}; + +using octet_string = std::basic_string; + +class SEXP_PUBLIC_SYMBOL sexp_simple_string_t : public octet_string, private sexp_char_defs_t { public: sexp_simple_string_t(void) = default; - sexp_simple_string_t(const octet_t *dt) : std::basic_string{dt} {} - sexp_simple_string_t(const octet_t *bt, size_t ln) : std::basic_string{bt, ln} {} + sexp_simple_string_t(const octet_t *dt) : octet_string{dt} {} + sexp_simple_string_t(const octet_t *bt, size_t ln) : octet_string{bt, ln} {} sexp_simple_string_t &append(int c) { (*this) += (octet_t)(c & 0xFF);