From 39895a677e5d370824e702cfe90ebc67737b8482 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 12 May 2021 09:12:09 +0200 Subject: import ArduinoJson 6.18.0 --- .../ArduinoJson/Strings/ArduinoStringAdapter.hpp | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 include/lib/ArduinoJson/Strings/ArduinoStringAdapter.hpp (limited to 'include/lib/ArduinoJson/Strings/ArduinoStringAdapter.hpp') diff --git a/include/lib/ArduinoJson/Strings/ArduinoStringAdapter.hpp b/include/lib/ArduinoJson/Strings/ArduinoStringAdapter.hpp new file mode 100644 index 0000000..24646cc --- /dev/null +++ b/include/lib/ArduinoJson/Strings/ArduinoStringAdapter.hpp @@ -0,0 +1,62 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include + +#include +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +class ArduinoStringAdapter { + public: + ArduinoStringAdapter(const ::String& str) : _str(&str) {} + + void copyTo(char* p, size_t n) const { + memcpy(p, _str->c_str(), n); + } + + bool isNull() const { + // Arduino's String::c_str() can return NULL + return !_str->c_str(); + } + + int compare(const char* other) const { + // Arduino's String::c_str() can return NULL + const char* me = _str->c_str(); + return safe_strcmp(me, other); + } + + bool equals(const char* expected) const { + return compare(expected) == 0; + } + + size_t size() const { + return _str->length(); + } + + const char* begin() const { + return _str->c_str(); + } + + typedef storage_policies::store_by_copy storage_policy; + + private: + const ::String* _str; +}; + +template <> +struct IsString< ::String> : true_type {}; + +template <> +struct IsString< ::StringSumHelper> : true_type {}; + +inline ArduinoStringAdapter adaptString(const ::String& str) { + return ArduinoStringAdapter(str); +} + +} // namespace ARDUINOJSON_NAMESPACE -- cgit v1.2.3