forked from bblanchon/ArduinoJson
Added support for basic_string<char, traits, allocator>
(closes #1045)
This commit is contained in:
@ -54,13 +54,16 @@ class DynamicStringWriter<String> {
|
||||
#endif
|
||||
|
||||
#if ARDUINOJSON_ENABLE_STD_STRING
|
||||
template <>
|
||||
struct IsWriteableString<std::string> : true_type {};
|
||||
template <typename TCharTraits, typename TAllocator>
|
||||
struct IsWriteableString<std::basic_string<char, TCharTraits, TAllocator> >
|
||||
: true_type {};
|
||||
|
||||
template <typename TCharTraits, typename TAllocator>
|
||||
class DynamicStringWriter<std::basic_string<char, TCharTraits, TAllocator> > {
|
||||
typedef std::basic_string<char, TCharTraits, TAllocator> string_type;
|
||||
|
||||
template <>
|
||||
class DynamicStringWriter<std::string> {
|
||||
public:
|
||||
DynamicStringWriter(std::string &str) : _str(&str) {}
|
||||
DynamicStringWriter(string_type &str) : _str(&str) {}
|
||||
|
||||
size_t write(uint8_t c) {
|
||||
_str->operator+=(static_cast<char>(c));
|
||||
@ -73,7 +76,7 @@ class DynamicStringWriter<std::string> {
|
||||
}
|
||||
|
||||
private:
|
||||
std::string *_str;
|
||||
string_type *_str;
|
||||
};
|
||||
#endif
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
@ -8,9 +8,10 @@
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <typename TString>
|
||||
class StlStringAdapter {
|
||||
public:
|
||||
StlStringAdapter(const std::string& str) : _str(&str) {}
|
||||
StlStringAdapter(const TString& str) : _str(&str) {}
|
||||
|
||||
char* save(MemoryPool* pool) const {
|
||||
size_t n = _str->length() + 1;
|
||||
@ -46,14 +47,18 @@ class StlStringAdapter {
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string* _str;
|
||||
const TString* _str;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct IsString<std::string> : true_type {};
|
||||
template <typename TCharTraits, typename TAllocator>
|
||||
struct IsString<std::basic_string<char, TCharTraits, TAllocator> > : true_type {
|
||||
};
|
||||
|
||||
inline StlStringAdapter adaptString(const std::string& str) {
|
||||
return StlStringAdapter(str);
|
||||
template <typename TCharTraits, typename TAllocator>
|
||||
inline StlStringAdapter<std::basic_string<char, TCharTraits, TAllocator> >
|
||||
adaptString(const std::basic_string<char, TCharTraits, TAllocator>& str) {
|
||||
return StlStringAdapter<std::basic_string<char, TCharTraits, TAllocator> >(
|
||||
str);
|
||||
}
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
Reference in New Issue
Block a user