Added support for basic_string<char, traits, allocator> (closes #1045)

This commit is contained in:
Benoit Blanchon
2019-08-12 14:21:45 +02:00
parent b9c4a0c5f6
commit 1e9cc285bb
6 changed files with 89 additions and 15 deletions

View File

@@ -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