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 --- include/lib/ArduinoJson/StringTraits/StdString.hpp | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 include/lib/ArduinoJson/StringTraits/StdString.hpp (limited to 'include/lib/ArduinoJson/StringTraits/StdString.hpp') diff --git a/include/lib/ArduinoJson/StringTraits/StdString.hpp b/include/lib/ArduinoJson/StringTraits/StdString.hpp new file mode 100644 index 0000000..35f4461 --- /dev/null +++ b/include/lib/ArduinoJson/StringTraits/StdString.hpp @@ -0,0 +1,77 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#if ARDUINOJSON_ENABLE_STD_STRING || ARDUINOJSON_ENABLE_ARDUINO_STRING + +#if ARDUINOJSON_ENABLE_ARDUINO_STRING +#include +#endif + +#if ARDUINOJSON_ENABLE_STD_STRING +#include +#endif + +namespace ArduinoJson { +namespace Internals { + +template +struct StdStringTraits { + typedef const char* duplicate_t; + + template + static duplicate_t duplicate(const TString& str, Buffer* buffer) { + if (!str.c_str()) return NULL; // <- Arduino string can return NULL + size_t size = str.length() + 1; + void* dup = buffer->alloc(size); + if (dup != NULL) memcpy(dup, str.c_str(), size); + return static_cast(dup); + } + + static bool is_null(const TString& str) { + // Arduino's String::c_str() can return NULL + return !str.c_str(); + } + + struct Reader : CharPointerTraits::Reader { + Reader(const TString& str) : CharPointerTraits::Reader(str.c_str()) {} + }; + + static bool equals(const TString& str, const char* expected) { + // Arduino's String::c_str() can return NULL + const char* actual = str.c_str(); + if (!actual || !expected) return actual == expected; + return 0 == strcmp(actual, expected); + } + + static void append(TString& str, char c) { + str += c; + } + + static void append(TString& str, const char* s) { + str += s; + } + + static const bool has_append = true; + static const bool has_equals = true; + static const bool should_duplicate = true; +}; + +#if ARDUINOJSON_ENABLE_ARDUINO_STRING +template <> +struct StringTraits : StdStringTraits {}; +template <> +struct StringTraits : StdStringTraits { +}; +#endif + +#if ARDUINOJSON_ENABLE_STD_STRING +template <> +struct StringTraits : StdStringTraits {}; +#endif +} // namespace Internals +} // namespace ArduinoJson + +#endif -- cgit v1.2.3