mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 00:38:27 +01:00
Renamed function RawJson() to serialized()
This commit is contained in:
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