|
9 | 9 |
|
10 | 10 | #include <ArduinoJson/Polyfills/assert.hpp> |
11 | 11 | #include <ArduinoJson/Polyfills/attributes.hpp> |
12 | | -#include <ArduinoJson/Strings/StringAdapter.hpp> |
13 | 12 |
|
14 | 13 | ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE |
15 | 14 |
|
16 | 15 | template <typename T> |
17 | 16 | struct IsChar |
18 | | - : integral_constant<bool, is_integral<T>::value && sizeof(T) == 1> {}; |
| 17 | + : integral_constant<bool, |
| 18 | + is_same<remove_cv_t<T>, char>::value || |
| 19 | + is_same<remove_cv_t<T>, signed char>::value || |
| 20 | + is_same<remove_cv_t<T>, unsigned char>::value> {}; |
19 | 21 |
|
20 | 22 | class RamString { |
21 | 23 | public: |
@@ -52,42 +54,27 @@ class RamString { |
52 | 54 | bool linked_; // TODO: merge with size_ |
53 | 55 | }; |
54 | 56 |
|
55 | | -template <typename TChar> |
56 | | -struct StringAdapter<TChar*, enable_if_t<IsChar<TChar>::value>> { |
57 | | - using AdaptedString = RamString; |
58 | | - |
59 | | - static AdaptedString adapt(const TChar* p) { |
60 | | - auto str = reinterpret_cast<const char*>(p); |
61 | | - return AdaptedString(str, str ? ::strlen(str) : 0); |
62 | | - } |
63 | | -}; |
| 57 | +template <typename TChar, typename = enable_if_t<IsChar<TChar>::value>> |
| 58 | +inline RamString adaptString(TChar* p) { |
| 59 | + auto str = reinterpret_cast<const char*>(p); |
| 60 | + return RamString(str, str ? ::strlen(str) : 0); |
| 61 | +} |
64 | 62 |
|
65 | | -template <typename TChar, size_t N> |
66 | | -struct StringAdapter<TChar[N], enable_if_t<IsChar<TChar>::value>> { |
67 | | - using AdaptedString = RamString; |
68 | | - |
69 | | - static AdaptedString adapt(const TChar* p) { |
70 | | - auto str = reinterpret_cast<const char*>(p); |
71 | | - return AdaptedString(str, str ? ::strlen(str) : 0); |
72 | | - } |
73 | | -}; |
| 63 | +template < |
| 64 | + typename TChar, size_t N, |
| 65 | + typename = enable_if_t<IsChar<TChar>::value && !is_const<TChar>::value>> |
| 66 | +inline RamString adaptString(TChar p[N]) { |
| 67 | + auto str = reinterpret_cast<const char*>(p); |
| 68 | + return RamString(str, str ? ::strlen(str) : 0); |
| 69 | +} |
74 | 70 |
|
75 | | -template <> |
76 | | -struct StringAdapter<const char*, void> { |
77 | | - using AdaptedString = RamString; |
78 | | - |
79 | | - static AdaptedString adapt(const char* p) { |
80 | | - return AdaptedString(p, p ? ::strlen(p) : 0, true); |
81 | | - } |
82 | | -}; |
| 71 | +inline RamString adaptString(const char* p) { |
| 72 | + return RamString(p, p ? ::strlen(p) : 0, true); |
| 73 | +} |
83 | 74 |
|
84 | 75 | template <typename TChar> |
85 | | -struct SizedStringAdapter<TChar*, enable_if_t<IsChar<TChar>::value>> { |
86 | | - using AdaptedString = RamString; |
87 | | - |
88 | | - static AdaptedString adapt(const TChar* p, size_t n) { |
89 | | - return AdaptedString(reinterpret_cast<const char*>(p), n); |
90 | | - } |
91 | | -}; |
| 76 | +inline RamString adaptString(const TChar* p, size_t n) { |
| 77 | + return RamString(reinterpret_cast<const char*>(p), n); |
| 78 | +} |
92 | 79 |
|
93 | 80 | ARDUINOJSON_END_PRIVATE_NAMESPACE |
0 commit comments