forked from bblanchon/ArduinoJson
Added tests for FlashStringAdapter
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
#include <ArduinoJson/Polyfills/assert.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
// Wraps a const char* so that the our functions are picked only if the
|
||||
@ -18,6 +19,7 @@ struct pgm_p {
|
||||
#ifndef strlen_P
|
||||
inline size_t strlen_P(ARDUINOJSON_NAMESPACE::pgm_p s) {
|
||||
const char* p = s.address;
|
||||
ARDUINOJSON_ASSERT(p != NULL);
|
||||
while (pgm_read_byte(p)) p++;
|
||||
return size_t(p - s.address);
|
||||
}
|
||||
@ -27,6 +29,8 @@ inline size_t strlen_P(ARDUINOJSON_NAMESPACE::pgm_p s) {
|
||||
inline int strncmp_P(const char* a, ARDUINOJSON_NAMESPACE::pgm_p b, size_t n) {
|
||||
const char* s1 = a;
|
||||
const char* s2 = b.address;
|
||||
ARDUINOJSON_ASSERT(s1 != NULL);
|
||||
ARDUINOJSON_ASSERT(s2 != NULL);
|
||||
while (n-- > 0) {
|
||||
char c1 = *s1++;
|
||||
char c2 = static_cast<char>(pgm_read_byte(s2++));
|
||||
@ -45,6 +49,8 @@ inline int strncmp_P(const char* a, ARDUINOJSON_NAMESPACE::pgm_p b, size_t n) {
|
||||
inline int strcmp_P(const char* a, ARDUINOJSON_NAMESPACE::pgm_p b) {
|
||||
const char* s1 = a;
|
||||
const char* s2 = b.address;
|
||||
ARDUINOJSON_ASSERT(s1 != NULL);
|
||||
ARDUINOJSON_ASSERT(s2 != NULL);
|
||||
for (;;) {
|
||||
char c1 = *s1++;
|
||||
char c2 = static_cast<char>(pgm_read_byte(s2++));
|
||||
@ -62,6 +68,8 @@ inline int strcmp_P(const char* a, ARDUINOJSON_NAMESPACE::pgm_p b) {
|
||||
inline void* memcpy_P(void* dst, ARDUINOJSON_NAMESPACE::pgm_p src, size_t n) {
|
||||
uint8_t* d = reinterpret_cast<uint8_t*>(dst);
|
||||
const char* s = src.address;
|
||||
ARDUINOJSON_ASSERT(d != NULL);
|
||||
ARDUINOJSON_ASSERT(s != NULL);
|
||||
while (n-- > 0) {
|
||||
*d++ = pgm_read_byte(s++);
|
||||
}
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
|
||||
#include <stdint.h> // int8_t
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
inline int8_t safe_strcmp(const char* a, const char* b) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <WString.h>
|
||||
|
||||
#include <ArduinoJson/Polyfills/safe_strcmp.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <string.h> // strcmp
|
||||
|
||||
#include <ArduinoJson/Polyfills/safe_strcmp.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
@ -4,7 +4,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Memory/MemoryPool.hpp>
|
||||
#include <ArduinoJson/Polyfills/pgmspace.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
18
src/ArduinoJson/Strings/IsString.hpp
Normal file
18
src/ArduinoJson/Strings/IsString.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Polyfills/type_traits.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
template <typename>
|
||||
struct IsString : false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct IsString<const T> : IsString<T> {};
|
||||
|
||||
template <typename T>
|
||||
struct IsString<T&> : IsString<T> {};
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -4,7 +4,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Memory/MemoryPool.hpp>
|
||||
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
|
||||
#include <string.h> // strcmp
|
||||
|
@ -4,7 +4,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Memory/MemoryPool.hpp>
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
|
||||
#include <string>
|
||||
|
@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
@ -4,20 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Memory/MemoryPool.hpp>
|
||||
#include <ArduinoJson/Polyfills/type_traits.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
template <typename>
|
||||
struct IsString : false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct IsString<const T> : IsString<T> {};
|
||||
|
||||
template <typename T>
|
||||
struct IsString<T&> : IsString<T> {};
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
||||
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/RamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/SizedRamStringAdapter.hpp>
|
||||
|
Reference in New Issue
Block a user