Skip to content

Commit

Permalink
Implemented char_traits for SEXP octet_t
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Jun 3, 2024
1 parent d5f9bae commit 8ffd5e0
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions include/sexpp/sexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,68 +99,82 @@ class sexp_input_stream_t;
* SEXP simple string
*/

//typedef uint8_t octet_t;

using octet_t = uint8_t;

struct octet_traits : std::char_traits<octet_t> {
static void assign(char_type& r, const char_type& a) {
struct octet_traits : std::char_traits<octet_t>
{
static void assign(char_type& r, const char_type& a)
{
r = a;
}

static bool eq(const char_type& c1, const char_type& c2) {
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) {
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) {
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 ) {
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) {
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) {
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) {
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) {
static char_type to_char_type(const int_type& c)
{
return char_type(c);
}

static int_type to_int_type(const 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) {
static bool eq_int_type(const int_type& c1, const int_type& c2)
{
return c1 == c2;
}

static int_type eof() {
static int_type eof()
{
return static_cast<int_type>(EOF);
}

static int_type not_eof(const int_type& c) {
static int_type not_eof(const int_type& c)
{
return eq_int_type(c, eof()) ? 0 : c;
}
};
Expand Down

0 comments on commit 8ffd5e0

Please sign in to comment.