mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 16:14:05 +01:00
Renamed function RawJson() to serialized()
This commit is contained in:
60
src/ArduinoJson/Strings/ArduinoString.hpp
Normal file
60
src/ArduinoJson/Strings/ArduinoString.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <WString.h>
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
class ArduinoString {
|
||||
public:
|
||||
ArduinoString(const ::String& str) : _str(&str) {}
|
||||
|
||||
template <typename Buffer>
|
||||
const char* save(Buffer* buffer) const {
|
||||
if (!_str->c_str()) return NULL; // <- Arduino string can return NULL
|
||||
size_t n = _str->length() + 1;
|
||||
void* dup = buffer->alloc(n);
|
||||
if (dup != NULL) memcpy(dup, _str->c_str(), n);
|
||||
return static_cast<const char*>(dup);
|
||||
}
|
||||
|
||||
bool is_null() const {
|
||||
// Arduino's String::c_str() can return NULL
|
||||
return _str->c_str();
|
||||
}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
// 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);
|
||||
}
|
||||
|
||||
const char* data() const {
|
||||
return _str->c_str();
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return _str->length();
|
||||
}
|
||||
|
||||
private:
|
||||
const ::String* _str;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct IsString< ::String> : true_type {};
|
||||
|
||||
template <>
|
||||
struct IsString< ::StringSumHelper> : true_type {};
|
||||
|
||||
inline ArduinoString makeString(const ::String& str) {
|
||||
return ArduinoString(str);
|
||||
}
|
||||
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
@@ -1,44 +0,0 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
template <typename TChar>
|
||||
struct CharPointerTraits {
|
||||
static bool equals(const TChar* str, const char* expected) {
|
||||
const char* actual = reinterpret_cast<const char*>(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 <typename Buffer>
|
||||
static duplicate_t duplicate(const TChar* str, Buffer* buffer) {
|
||||
if (!str) return NULL;
|
||||
size_t size = strlen(reinterpret_cast<const char*>(str)) + 1;
|
||||
void* dup = buffer->alloc(size);
|
||||
if (dup != NULL) memcpy(dup, str, size);
|
||||
return static_cast<duplicate_t>(dup);
|
||||
}
|
||||
|
||||
static const bool has_append = false;
|
||||
static const bool has_equals = true;
|
||||
static const bool should_duplicate = !is_const<TChar>::value;
|
||||
};
|
||||
|
||||
// char*, unsigned char*, signed char*
|
||||
// const char*, const unsigned char*, const signed char*
|
||||
template <typename TChar>
|
||||
struct StringTraits<TChar*, typename enable_if<sizeof(TChar) == 1>::type>
|
||||
: CharPointerTraits<TChar> {};
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
47
src/ArduinoJson/Strings/FixedSizeFlashString.hpp
Normal file
47
src/ArduinoJson/Strings/FixedSizeFlashString.hpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
class FixedSizeFlashString {
|
||||
public:
|
||||
FixedSizeFlashString(const __FlashStringHelper* str, size_t sz)
|
||||
: _str(str), _size(sz) {}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
const char* actual = reinterpret_cast<const char*>(_str);
|
||||
if (!actual || !expected) return actual == expected;
|
||||
return strcmp_P(actual, expected) == 0;
|
||||
}
|
||||
|
||||
bool is_null() const {
|
||||
return !_str;
|
||||
}
|
||||
|
||||
template <typename Buffer>
|
||||
const char* save(Buffer* buffer) const {
|
||||
if (!_str) return NULL;
|
||||
void* dup = buffer->alloc(_size);
|
||||
if (dup != NULL) memcpy_P(dup, (const char*)_str, _size);
|
||||
return static_cast<const char*>(dup);
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return strlen_P(reinterpret_cast<const char*>(_str));
|
||||
}
|
||||
|
||||
private:
|
||||
const __FlashStringHelper* _str;
|
||||
size_t _size;
|
||||
};
|
||||
|
||||
inline FixedSizeFlashString makeString(const __FlashStringHelper* str,
|
||||
size_t sz) {
|
||||
return FixedSizeFlashString(str, sz);
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
48
src/ArduinoJson/Strings/FixedSizeRamString.hpp
Normal file
48
src/ArduinoJson/Strings/FixedSizeRamString.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
class FixedSizeRamString {
|
||||
public:
|
||||
FixedSizeRamString(const char* str, size_t n) : _str(str), _size(n) {}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
const char* actual = reinterpret_cast<const char*>(_str);
|
||||
if (!actual || !expected) return actual == expected;
|
||||
return strcmp(actual, expected) == 0;
|
||||
}
|
||||
|
||||
bool is_null() const {
|
||||
return !_str;
|
||||
}
|
||||
|
||||
template <typename Buffer>
|
||||
const char* save(Buffer* buffer) const {
|
||||
if (!_str) return NULL;
|
||||
void* dup = buffer->alloc(_size);
|
||||
if (!dup) return NULL;
|
||||
memcpy(dup, _str, _size);
|
||||
return static_cast<const char*>(dup);
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return strlen(reinterpret_cast<const char*>(_str));
|
||||
}
|
||||
|
||||
private:
|
||||
const char* _str;
|
||||
size_t _size;
|
||||
};
|
||||
|
||||
template <typename TChar>
|
||||
inline FixedSizeRamString makeString(const TChar* str, size_t size) {
|
||||
return FixedSizeRamString(reinterpret_cast<const char*>(str), size);
|
||||
}
|
||||
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
@@ -1,41 +0,0 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#if ARDUINOJSON_ENABLE_PROGMEM
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
template <>
|
||||
struct StringTraits<const __FlashStringHelper*, void> {
|
||||
static bool equals(const __FlashStringHelper* str, const char* expected) {
|
||||
const char* actual = reinterpret_cast<const char*>(str);
|
||||
if (!actual || !expected) return actual == expected;
|
||||
return strcmp_P(expected, actual) == 0;
|
||||
}
|
||||
|
||||
static bool is_null(const __FlashStringHelper* str) {
|
||||
return !str;
|
||||
}
|
||||
|
||||
typedef const char* duplicate_t;
|
||||
|
||||
template <typename Buffer>
|
||||
static duplicate_t duplicate(const __FlashStringHelper* str, Buffer* buffer) {
|
||||
if (!str) return NULL;
|
||||
size_t size = strlen_P((const char*)str) + 1;
|
||||
void* dup = buffer->alloc(size);
|
||||
if (dup != NULL) memcpy_P(dup, (const char*)str, size);
|
||||
return static_cast<duplicate_t>(dup);
|
||||
}
|
||||
|
||||
static const bool has_append = false;
|
||||
static const bool has_equals = true;
|
||||
static const bool should_duplicate = true;
|
||||
};
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
|
||||
#endif
|
||||
@@ -1,73 +0,0 @@
|
||||
// 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 <WString.h>
|
||||
#endif
|
||||
|
||||
#if ARDUINOJSON_ENABLE_STD_STRING
|
||||
#include <string>
|
||||
#endif
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
template <typename TString>
|
||||
struct StdStringTraits {
|
||||
typedef const char* duplicate_t;
|
||||
|
||||
template <typename Buffer>
|
||||
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<duplicate_t>(dup);
|
||||
}
|
||||
|
||||
static bool is_null(const TString& str) {
|
||||
// Arduino's String::c_str() can return NULL
|
||||
return !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<String, void> : StdStringTraits<String> {};
|
||||
template <>
|
||||
struct StringTraits<StringSumHelper, void> : StdStringTraits<StringSumHelper> {
|
||||
};
|
||||
#endif
|
||||
|
||||
#if ARDUINOJSON_ENABLE_STD_STRING
|
||||
template <>
|
||||
struct StringTraits<std::string, void> : StdStringTraits<std::string> {};
|
||||
#endif
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
|
||||
#endif
|
||||
52
src/ArduinoJson/Strings/StlString.hpp
Normal file
52
src/ArduinoJson/Strings/StlString.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
class StlString {
|
||||
public:
|
||||
StlString(const std::string& str) : _str(&str) {}
|
||||
|
||||
template <typename Buffer>
|
||||
const char* save(Buffer* buffer) const {
|
||||
size_t n = _str->length() + 1;
|
||||
void* dup = buffer->alloc(n);
|
||||
if (dup != NULL) memcpy(dup, _str->c_str(), n);
|
||||
return static_cast<const char*>(dup);
|
||||
}
|
||||
|
||||
bool is_null() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
return *_str == expected;
|
||||
}
|
||||
|
||||
const char* data() const {
|
||||
return _str->data();
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return _str->size();
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string* _str;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct IsString<std::string> : true_type {};
|
||||
|
||||
inline StlString makeString(const std::string& str) {
|
||||
return StlString(str);
|
||||
}
|
||||
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
@@ -1,30 +0,0 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string.h>
|
||||
#include "../Configuration.hpp"
|
||||
#include "../Polyfills/type_traits.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
template <typename TString, typename Enable = void>
|
||||
struct StringTraits {
|
||||
static const bool has_append = false;
|
||||
static const bool has_equals = false;
|
||||
};
|
||||
|
||||
template <typename TString>
|
||||
struct StringTraits<const TString, void> : StringTraits<TString> {};
|
||||
|
||||
template <typename TString>
|
||||
struct StringTraits<TString&, void> : StringTraits<TString> {};
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
|
||||
#include "CharPointer.hpp"
|
||||
#include "FlashString.hpp"
|
||||
#include "StdString.hpp"
|
||||
36
src/ArduinoJson/Strings/StringTypes.hpp
Normal file
36
src/ArduinoJson/Strings/StringTypes.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Polyfills/type_traits.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
template <typename>
|
||||
struct IsString : false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct IsString<const T> : IsString<T> {};
|
||||
|
||||
template <typename T>
|
||||
struct IsString<T&> : IsString<T> {};
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
|
||||
#include "FixedSizeRamString.hpp"
|
||||
#include "ZeroTerminatedRamString.hpp"
|
||||
|
||||
#if ARDUINOJSON_ENABLE_STD_STRING
|
||||
#include "StlString.hpp"
|
||||
#endif
|
||||
|
||||
#if ARDUINOJSON_ENABLE_ARDUINO_STRING
|
||||
#include "ArduinoString.hpp"
|
||||
#endif
|
||||
|
||||
#if ARDUINOJSON_ENABLE_PROGMEM
|
||||
#include "FixedSizeFlashString.hpp"
|
||||
#include "ZeroTerminatedFlashString.hpp"
|
||||
#endif
|
||||
48
src/ArduinoJson/Strings/ZeroTerminatedFlashString.hpp
Normal file
48
src/ArduinoJson/Strings/ZeroTerminatedFlashString.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
class ZeroTerminatedFlashString {
|
||||
public:
|
||||
ZeroTerminatedFlashString(const __FlashStringHelper* str) : _str(str) {}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
const char* actual = reinterpret_cast<const char*>(_str);
|
||||
if (!actual || !expected) return actual == expected;
|
||||
return strcmp_P(actual, expected) == 0;
|
||||
}
|
||||
|
||||
bool is_null() const {
|
||||
return !_str;
|
||||
}
|
||||
|
||||
template <typename Buffer>
|
||||
const char* save(Buffer* buffer) const {
|
||||
if (!_str) return NULL;
|
||||
size_t n = size() + 1; // copy the terminator
|
||||
void* dup = buffer->alloc(n);
|
||||
if (dup != NULL) memcpy_P(dup, (const char*)_str, n);
|
||||
return static_cast<const char*>(dup);
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return strlen_P(reinterpret_cast<const char*>(_str));
|
||||
}
|
||||
|
||||
private:
|
||||
const __FlashStringHelper* _str;
|
||||
};
|
||||
|
||||
inline ZeroTerminatedFlashString makeString(const __FlashStringHelper* str) {
|
||||
return ZeroTerminatedFlashString(str);
|
||||
}
|
||||
|
||||
template <>
|
||||
struct IsString<const __FlashStringHelper*> : true_type {};
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
53
src/ArduinoJson/Strings/ZeroTerminatedRamString.hpp
Normal file
53
src/ArduinoJson/Strings/ZeroTerminatedRamString.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
class ZeroTerminatedRamString {
|
||||
public:
|
||||
ZeroTerminatedRamString(const char* str) : _str(str) {}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
const char* actual = reinterpret_cast<const char*>(_str);
|
||||
if (!actual || !expected) return actual == expected;
|
||||
return strcmp(actual, expected) == 0;
|
||||
}
|
||||
|
||||
bool is_null() const {
|
||||
return !_str;
|
||||
}
|
||||
|
||||
template <typename Buffer>
|
||||
const char* save(Buffer* buffer) const {
|
||||
if (!_str) return NULL;
|
||||
size_t n = size() + 1;
|
||||
void* dup = buffer->alloc(n);
|
||||
if (!dup) return NULL;
|
||||
memcpy(dup, _str, n);
|
||||
return static_cast<const char*>(dup);
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return strlen(reinterpret_cast<const char*>(_str));
|
||||
}
|
||||
|
||||
private:
|
||||
const char* _str;
|
||||
};
|
||||
|
||||
template <typename TChar>
|
||||
inline ZeroTerminatedRamString makeString(const TChar* str) {
|
||||
return ZeroTerminatedRamString(reinterpret_cast<const char*>(str));
|
||||
}
|
||||
|
||||
template <typename TChar>
|
||||
struct IsString<TChar*> {
|
||||
static const bool value = sizeof(TChar) == 1;
|
||||
};
|
||||
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
Reference in New Issue
Block a user