User can now use a JsonString as a key or a value

This commit is contained in:
Benoit Blanchon
2019-01-29 17:00:11 +01:00
parent 6f55d1e58f
commit b184af6d00
29 changed files with 500 additions and 376 deletions

View File

@@ -0,0 +1,54 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2018
// MIT License
#pragma once
#include <string>
namespace ARDUINOJSON_NAMESPACE {
class StlStringAdapter {
public:
StlStringAdapter(const std::string& str) : _str(&str) {}
char* save(MemoryPool* pool) const {
size_t n = _str->length() + 1;
char* dup = pool->allocFrozenString(n);
if (dup) memcpy(dup, _str->c_str(), n);
return dup;
}
bool isNull() const {
return false;
}
bool equals(const char* expected) const {
if (!expected) return false;
return *_str == expected;
}
const char* data() const {
return _str->data();
}
size_t size() const {
return _str->size();
}
bool isStatic() const {
return false;
}
private:
const std::string* _str;
};
template <>
struct IsString<std::string> : true_type {};
inline StlStringAdapter adaptString(const std::string& str) {
return StlStringAdapter(str);
}
} // namespace ARDUINOJSON_NAMESPACE