Skip to content

Commit

Permalink
Test 11
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Jun 6, 2024
1 parent 7216b65 commit f156407
Showing 1 changed file with 82 additions and 61 deletions.
143 changes: 82 additions & 61 deletions include/sexpp/sexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,88 @@
#include "sexp-public.h"
#include "sexp-error.h"

using octet_t = uint8_t;

namespace sexp {

struct octet_traits : public std::char_traits<octet_t> {
typedef octet_t char_type;
typedef int int_type;
typedef std::streampos pos_type;
typedef std::streamoff off_type;
typedef mbstate_t state_type;

static void assign(char_type& __c1, const char_type& __c2) noexcept
{
__c1 = __c2;
}

static constexpr bool eq(const char_type& __c1, const char_type& __c2) noexcept
{
return __c1 == __c2;
}

static constexpr bool lt(const char_type& __c1, const char_type& __c2) noexcept
{
return __c1 < __c2;
}

static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
{
return memcmp(__s1, __s2, __n);
}

static size_t length(const char_type* __s)
{
return strlen(reinterpret_cast<const char *>(__s));
}

static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
{
return static_cast<const char_type*>(memchr(__s, __a, __n));
}

static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
{
return static_cast<char_type*>(memmove(__s1, __s2, __n));
}

static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
{
return static_cast<char_type*>(memcpy(__s1, __s2, __n));
}

static char_type* assign(char_type* __s, size_t __n, char_type __a)
{
return static_cast<char_type*>(memset(__s, __a, __n));
}

static constexpr char_type to_char_type(const int_type& __c) noexcept
{
return static_cast<char_type>(__c);
}

// To keep both the byte 0xff and the eof symbol 0xffffffff
// from ending up as 0xffffffff.
static _GLIBCXX_CONSTEXPR int_type
to_int_type(const char_type& __c) noexcept
{ return static_cast<int_type>(static_cast<unsigned char>(__c)); }

static _GLIBCXX_CONSTEXPR bool
eq_int_type(const int_type& __c1, const int_type& __c2) noexcept
{ return __c1 == __c2; }

static _GLIBCXX_CONSTEXPR int_type
eof() noexcept
{ return static_cast<int_type>(_GLIBCXX_STDIO_EOF); }

static _GLIBCXX_CONSTEXPR int_type
not_eof(const int_type& __c) noexcept
{ return (__c == eof()) ? 0 : __c; }
};
}


namespace sexp {

/*
Expand Down Expand Up @@ -99,62 +181,6 @@ class sexp_input_stream_t;
* SEXP simple string
*/

using octet_t = uint8_t;

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) { 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<int_type>(EOF); }

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

using octet_string = std::basic_string<octet_t, octet_traits>;

class SEXP_PUBLIC_SYMBOL sexp_simple_string_t : public octet_string, private sexp_char_defs_t {
Expand Down Expand Up @@ -278,11 +304,6 @@ class SEXP_PUBLIC_SYMBOL sexp_string_t : public sexp_object_t {
sexp_string_t(void) : with_presentation_hint(false) {}
sexp_string_t(sexp_input_stream_t *sis) { parse(sis); };

~sexp_string_t()
{

}

const bool has_presentation_hint(void) const noexcept { return with_presentation_hint; }
const sexp_simple_string_t &get_string(void) const noexcept { return data_string; }
const sexp_simple_string_t &set_string(const sexp_simple_string_t &ss)
Expand Down

0 comments on commit f156407

Please sign in to comment.