Implement IsString from StringAdapter

This commit is contained in:
Benoit Blanchon
2022-10-26 17:20:33 +02:00
parent ecb72f9a9d
commit c3d5e9382d
9 changed files with 9 additions and 41 deletions

View File

@ -8,6 +8,7 @@
#include "custom_string.hpp"
#include "weird_strcmp.hpp"
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StringAdapters.hpp>
#include <catch.hpp>

View File

@ -6,7 +6,7 @@
#include <ArduinoJson/Polyfills/attributes.hpp>
#include <ArduinoJson/Polyfills/type_traits.hpp>
#include <ArduinoJson/Strings/StringAdapters.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <typename TSource>

View File

@ -7,7 +7,6 @@
#include <Arduino.h>
#include <ArduinoJson/Strings/Adapters/RamString.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
namespace ARDUINOJSON_NAMESPACE {
@ -23,10 +22,4 @@ struct StringAdapter<
}
};
template <>
struct IsString< ::String> : true_type {};
template <>
struct IsString< ::StringSumHelper> : true_type {};
} // namespace ARDUINOJSON_NAMESPACE

View File

@ -7,7 +7,7 @@
#include <Arduino.h>
#include <ArduinoJson/Polyfills/pgmspace.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
namespace ARDUINOJSON_NAMESPACE {
@ -88,7 +88,4 @@ struct SizedStringAdapter<const __FlashStringHelper*, void> {
}
};
template <>
struct IsString<const __FlashStringHelper*> : true_type {};
} // namespace ARDUINOJSON_NAMESPACE

View File

@ -5,8 +5,8 @@
#pragma once
#include <ArduinoJson/Strings/Adapters/RamString.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/String.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
namespace ARDUINOJSON_NAMESPACE {
@ -33,7 +33,4 @@ struct StringAdapter<String> {
}
};
template <>
struct IsString<String> : true_type {};
} // namespace ARDUINOJSON_NAMESPACE

View File

@ -8,7 +8,6 @@
#include <string.h> // strcmp
#include <ArduinoJson/Polyfills/assert.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
@ -58,12 +57,6 @@ class ZeroTerminatedRamString {
const char* _str;
};
template <>
struct IsString<char*> : true_type {};
template <>
struct IsString<unsigned char*> : true_type {};
template <typename TChar>
struct StringAdapter<TChar*, typename enable_if<sizeof(TChar) == 1>::type> {
typedef ZeroTerminatedRamString AdaptedString;
@ -73,15 +66,6 @@ struct StringAdapter<TChar*, typename enable_if<sizeof(TChar) == 1>::type> {
}
};
template <>
struct IsString<signed char*> : true_type {};
template <size_t N>
struct IsString<char[N]> : true_type {};
template <size_t N>
struct IsString<const char[N]> : true_type {};
template <typename TChar, size_t N>
struct StringAdapter<TChar[N], typename enable_if<sizeof(TChar) == 1>::type> {
typedef ZeroTerminatedRamString AdaptedString;

View File

@ -20,8 +20,4 @@ struct StringAdapter<std::basic_string<char, TCharTraits, TAllocator>, void> {
}
};
template <typename TCharTraits, typename TAllocator>
struct IsString<std::basic_string<char, TCharTraits, TAllocator> > : true_type {
};
} // namespace ARDUINOJSON_NAMESPACE

View File

@ -19,7 +19,4 @@ struct StringAdapter<std::string_view, void> {
}
};
template <>
struct IsString<std::string_view> : true_type {};
} // namespace ARDUINOJSON_NAMESPACE

View File

@ -5,13 +5,16 @@
#pragma once
#include <ArduinoJson/Polyfills/type_traits.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <typename T, typename Enable = void>
struct IsString : false_type {};
template <typename TChar>
struct IsString<const TChar*> : IsString<TChar*> {};
template <typename T>
struct IsString<
T, typename make_void<typename StringAdapter<T>::AdaptedString>::type>
: true_type {};
} // namespace ARDUINOJSON_NAMESPACE