forked from bblanchon/ArduinoJson
Fix detection of char types
This commit is contained in:
@ -86,6 +86,8 @@ TEST_CASE("custom_string") {
|
||||
CHECK(s.size() == 5);
|
||||
}
|
||||
|
||||
struct EmptyStruct {};
|
||||
|
||||
TEST_CASE("IsString<T>") {
|
||||
CHECK(IsString<std::string>::value == true);
|
||||
CHECK(IsString<std::basic_string<wchar_t> >::value == false);
|
||||
@ -95,6 +97,7 @@ TEST_CASE("IsString<T>") {
|
||||
CHECK(IsString<const char[8]>::value == true);
|
||||
CHECK(IsString< ::String>::value == true);
|
||||
CHECK(IsString< ::StringSumHelper>::value == true);
|
||||
CHECK(IsString<const EmptyStruct*>::value == false);
|
||||
}
|
||||
|
||||
TEST_CASE("stringCompare") {
|
||||
|
@ -40,12 +40,8 @@ serialize(JsonVariantConst source, void* buffer, size_t bufferSize) {
|
||||
}
|
||||
|
||||
template <template <typename> class TSerializer, typename TChar, size_t N>
|
||||
#if defined _MSC_VER && _MSC_VER < 1900
|
||||
typename enable_if<sizeof(remove_reference<TChar>::type) == 1, size_t>::type
|
||||
#else
|
||||
typename enable_if<sizeof(TChar) == 1, size_t>::type
|
||||
#endif
|
||||
serialize(JsonVariantConst source, TChar (&buffer)[N]) {
|
||||
typename enable_if<IsChar<TChar>::value, size_t>::type serialize(
|
||||
JsonVariantConst source, TChar (&buffer)[N]) {
|
||||
return serialize<TSerializer>(source, buffer, N);
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,10 @@
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <typename T>
|
||||
struct IsChar
|
||||
: integral_constant<bool, is_integral<T>::value && sizeof(T) == 1> {};
|
||||
|
||||
class ZeroTerminatedRamString {
|
||||
public:
|
||||
static const size_t typeSortKey = 3;
|
||||
@ -58,7 +62,7 @@ class ZeroTerminatedRamString {
|
||||
};
|
||||
|
||||
template <typename TChar>
|
||||
struct StringAdapter<TChar*, typename enable_if<sizeof(TChar) == 1>::type> {
|
||||
struct StringAdapter<TChar*, typename enable_if<IsChar<TChar>::value>::type> {
|
||||
typedef ZeroTerminatedRamString AdaptedString;
|
||||
|
||||
static AdaptedString adapt(const TChar* p) {
|
||||
@ -67,7 +71,7 @@ struct StringAdapter<TChar*, typename enable_if<sizeof(TChar) == 1>::type> {
|
||||
};
|
||||
|
||||
template <typename TChar, size_t N>
|
||||
struct StringAdapter<TChar[N], typename enable_if<sizeof(TChar) == 1>::type> {
|
||||
struct StringAdapter<TChar[N], typename enable_if<IsChar<TChar>::value>::type> {
|
||||
typedef ZeroTerminatedRamString AdaptedString;
|
||||
|
||||
static AdaptedString adapt(const TChar* p) {
|
||||
@ -128,7 +132,7 @@ class SizedRamString {
|
||||
|
||||
template <typename TChar>
|
||||
struct SizedStringAdapter<TChar*,
|
||||
typename enable_if<sizeof(TChar) == 1>::type> {
|
||||
typename enable_if<IsChar<TChar>::value>::type> {
|
||||
typedef SizedRamString AdaptedString;
|
||||
|
||||
static AdaptedString adapt(const TChar* p, size_t n) {
|
||||
|
Reference in New Issue
Block a user