From 4f6253aa9fec99260b8bb7b9b2e9003f5259b600 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 17 Sep 2018 10:02:07 +0200 Subject: Import arduinojson and ubjson. Only partially working at the moment --- .../lib/ArduinoJson/StringTraits/CharPointer.hpp | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 include/lib/ArduinoJson/StringTraits/CharPointer.hpp (limited to 'include/lib/ArduinoJson/StringTraits/CharPointer.hpp') diff --git a/include/lib/ArduinoJson/StringTraits/CharPointer.hpp b/include/lib/ArduinoJson/StringTraits/CharPointer.hpp new file mode 100644 index 0000000..98896cc --- /dev/null +++ b/include/lib/ArduinoJson/StringTraits/CharPointer.hpp @@ -0,0 +1,64 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +namespace ArduinoJson { +namespace Internals { + +template +struct CharPointerTraits { + class Reader { + const TChar* _ptr; + + public: + Reader(const TChar* ptr) + : _ptr(ptr ? ptr : reinterpret_cast("")) {} + + void move() { + ++_ptr; + } + + char current() const { + return char(_ptr[0]); + } + + char next() const { + return char(_ptr[1]); + } + }; + + static bool equals(const TChar* str, const char* expected) { + const char* actual = reinterpret_cast(str); + if (!actual || !expected) return actual == expected; + return strcmp(actual, expected) == 0; + } + + static bool is_null(const TChar* str) { + return !str; + } + + typedef const char* duplicate_t; + + template + static duplicate_t duplicate(const TChar* str, Buffer* buffer) { + if (!str) return NULL; + size_t size = strlen(reinterpret_cast(str)) + 1; + void* dup = buffer->alloc(size); + if (dup != NULL) memcpy(dup, str, size); + return static_cast(dup); + } + + static const bool has_append = false; + static const bool has_equals = true; + static const bool should_duplicate = !IsConst::value; +}; + +// char*, unsigned char*, signed char* +// const char*, const unsigned char*, const signed char* +template +struct StringTraits::value>::type> + : CharPointerTraits {}; +} // namespace Internals +} // namespace ArduinoJson -- cgit v1.2.3