Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Benoît Blanchon
ArduinoJson
Commits
5790f3c8
Commit
5790f3c8
authored
3 years ago
by
Benoit Blanchon
Browse files
Options
Download
Email Patches
Plain Diff
Refactored string adapters: only one `IsString<T>` and `adaptString()`
parent
4073b52c
6.x
6.20.x
v6.21.0
v6.20.1
v6.20.0
v6.19.4
v6.19.3
v6.19.2
v6.19.1
v6.19.0
v6.18.5
v6.18.4
v6.18.3
No related merge requests found
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
.devcontainer/devcontainer.json
+2
-1
.devcontainer/devcontainer.json
extras/tests/Misc/StringAdapters.cpp
+16
-17
extras/tests/Misc/StringAdapters.cpp
src/ArduinoJson/Collection/CollectionImpl.hpp
+2
-2
src/ArduinoJson/Collection/CollectionImpl.hpp
src/ArduinoJson/Polyfills/type_traits.hpp
+1
-0
src/ArduinoJson/Polyfills/type_traits.hpp
src/ArduinoJson/Polyfills/type_traits/make_void.hpp
+14
-0
src/ArduinoJson/Polyfills/type_traits/make_void.hpp
src/ArduinoJson/Strings/Adapters/ArduinoStringAdapter.hpp
+9
-11
src/ArduinoJson/Strings/Adapters/ArduinoStringAdapter.hpp
src/ArduinoJson/Strings/Adapters/ConstRamStringAdapter.hpp
+8
-11
src/ArduinoJson/Strings/Adapters/ConstRamStringAdapter.hpp
src/ArduinoJson/Strings/Adapters/FlashStringAdapter.hpp
+4
-9
src/ArduinoJson/Strings/Adapters/FlashStringAdapter.hpp
src/ArduinoJson/Strings/Adapters/JsonStringAdapter.hpp
+27
-0
src/ArduinoJson/Strings/Adapters/JsonStringAdapter.hpp
src/ArduinoJson/Strings/Adapters/RamStringAdapter.hpp
+29
-0
src/ArduinoJson/Strings/Adapters/RamStringAdapter.hpp
src/ArduinoJson/Strings/Adapters/SizedFlashStringAdapter.hpp
+4
-7
src/ArduinoJson/Strings/Adapters/SizedFlashStringAdapter.hpp
src/ArduinoJson/Strings/Adapters/SizedRamStringAdapter.hpp
+4
-8
src/ArduinoJson/Strings/Adapters/SizedRamStringAdapter.hpp
src/ArduinoJson/Strings/Adapters/StdStringAdapter.hpp
+7
-16
src/ArduinoJson/Strings/Adapters/StdStringAdapter.hpp
src/ArduinoJson/Strings/Adapters/StringViewAdapter.hpp
+4
-10
src/ArduinoJson/Strings/Adapters/StringViewAdapter.hpp
src/ArduinoJson/Strings/String.hpp
+0
-25
src/ArduinoJson/Strings/String.hpp
src/ArduinoJson/Strings/StringAdapter.hpp
+32
-0
src/ArduinoJson/Strings/StringAdapter.hpp
src/ArduinoJson/Strings/StringAdapters.hpp
+9
-8
src/ArduinoJson/Strings/StringAdapters.hpp
src/ArduinoJson/Variant/VariantCompare.hpp
+1
-1
src/ArduinoJson/Variant/VariantCompare.hpp
src/ArduinoJson/Variant/VariantData.hpp
+3
-2
src/ArduinoJson/Variant/VariantData.hpp
with
176 additions
and
128 deletions
+176
-128
.devcontainer/devcontainer.json
+
2
-
1
View file @
5790f3c8
...
...
@@ -12,7 +12,8 @@
//
Add
the
IDs
of
extensions
you
want
installed
when
the
container
is
created.
"extensions"
:
[
"ms-vscode.cmake-tools"
,
"ms-vscode.cpptools"
"ms-vscode.cpptools"
,
"xaver.clang-format"
],
//
Use
'forwardPorts'
to
make
a
list
of
ports
inside
the
container
available
locally.
...
...
This diff is collapsed.
Click to expand it.
extras/tests/Misc/StringAdapters.cpp
+
16
-
17
View file @
5790f3c8
...
...
@@ -2,23 +2,22 @@
// Copyright Benoit Blanchon 2014-2021
// MIT License
#define ARDUINOJSON_ENABLE_PROGMEM 1
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
#include
"custom_string.hpp"
#include
"progmem_emulation.hpp"
#include
"weird_strcmp.hpp"
#include
<ArduinoJson/Strings/ArduinoStringAdapter.hpp>
#include
<ArduinoJson/Strings/ConstRamStringAdapter.hpp>
#include
<ArduinoJson/Strings/FlashStringAdapter.hpp>
#include
<ArduinoJson/Strings/SizedRamStringAdapter.hpp>
#include
<ArduinoJson/Strings/StdStringAdapter.hpp>
#include
<ArduinoJson/Strings/StringAdapters.hpp>
#include
<catch.hpp>
using
namespace
ARDUINOJSON_NAMESPACE
;
TEST_CASE
(
"
C
onst
RamStringAdapter
"
)
{
TEST_CASE
(
"
c
onst
char*
"
)
{
SECTION
(
"null"
)
{
ConstRam
StringAdapter
adapter
(
NULL
);
StringAdapter
<
const
char
*>
adapter
(
NULL
);
CHECK
(
adapter
.
compare
(
"bravo"
)
<
0
);
CHECK
(
adapter
.
compare
(
NULL
)
==
0
);
...
...
@@ -30,7 +29,7 @@ TEST_CASE("ConstRamStringAdapter") {
}
SECTION
(
"non-null"
)
{
ConstRam
StringAdapter
adapter
(
"bravo"
);
StringAdapter
<
const
char
*>
adapter
(
"bravo"
);
CHECK
(
adapter
.
compare
(
NULL
)
>
0
);
CHECK
(
adapter
.
compare
(
"alpha"
)
>
0
);
...
...
@@ -44,9 +43,9 @@ TEST_CASE("ConstRamStringAdapter") {
}
}
TEST_CASE
(
"
SizedRamStringAdapter
"
)
{
TEST_CASE
(
"
const char* + size
"
)
{
SECTION
(
"null"
)
{
SizedRam
StringAdapter
adapter
(
NULL
,
10
);
StringAdapter
<
const
char
*
,
true
>
adapter
(
NULL
,
10
);
CHECK
(
adapter
.
compare
(
"bravo"
)
<
0
);
CHECK
(
adapter
.
compare
(
NULL
)
==
0
);
...
...
@@ -58,7 +57,7 @@ TEST_CASE("SizedRamStringAdapter") {
}
SECTION
(
"non-null"
)
{
SizedRam
StringAdapter
adapter
(
"bravo"
,
5
);
StringAdapter
<
const
char
*
,
true
>
adapter
(
"bravo"
,
5
);
CHECK
(
adapter
.
compare
(
NULL
)
>
0
);
CHECK
(
adapter
.
compare
(
"alpha"
)
>
0
);
...
...
@@ -72,9 +71,9 @@ TEST_CASE("SizedRamStringAdapter") {
}
}
TEST_CASE
(
"FlashString
Adapt
er"
)
{
TEST_CASE
(
"
const __
FlashString
Help
er
*
"
)
{
SECTION
(
"null"
)
{
FlashString
Adapter
adapter
(
NULL
);
StringAdapter
<
const
__
FlashString
Helper
*>
adapter
(
NULL
);
CHECK
(
adapter
.
compare
(
"bravo"
)
<
0
);
CHECK
(
adapter
.
compare
(
NULL
)
==
0
);
...
...
@@ -86,7 +85,7 @@ TEST_CASE("FlashStringAdapter") {
}
SECTION
(
"non-null"
)
{
FlashString
Adapter
adapter
=
adaptString
(
F
(
"bravo"
));
StringAdapter
<
const
__
FlashString
Helper
*>
adapter
=
adaptString
(
F
(
"bravo"
));
CHECK
(
adapter
.
compare
(
NULL
)
>
0
);
CHECK
(
adapter
.
compare
(
"alpha"
)
>
0
);
...
...
@@ -102,7 +101,7 @@ TEST_CASE("FlashStringAdapter") {
TEST_CASE
(
"std::string"
)
{
std
::
string
str
(
"bravo"
);
Std
StringAdapter
<
std
::
string
>
adapter
=
adaptString
(
str
);
StringAdapter
<
std
::
string
>
adapter
(
str
);
CHECK
(
adapter
.
compare
(
NULL
)
>
0
);
CHECK
(
adapter
.
compare
(
"alpha"
)
>
0
);
...
...
@@ -117,7 +116,7 @@ TEST_CASE("std::string") {
TEST_CASE
(
"Arduino String"
)
{
::
String
str
(
"bravo"
);
Arduino
StringAdapter
adapter
=
adaptString
(
str
);
StringAdapter
<
::
String
>
adapter
(
str
);
CHECK
(
adapter
.
compare
(
NULL
)
>
0
);
CHECK
(
adapter
.
compare
(
"alpha"
)
>
0
);
...
...
@@ -132,7 +131,7 @@ TEST_CASE("Arduino String") {
TEST_CASE
(
"custom_string"
)
{
custom_string
str
(
"bravo"
);
Std
StringAdapter
<
custom_string
>
adapter
=
adaptString
(
str
);
StringAdapter
<
custom_string
>
adapter
(
str
);
CHECK
(
adapter
.
compare
(
NULL
)
>
0
);
CHECK
(
adapter
.
compare
(
"alpha"
)
>
0
);
...
...
This diff is collapsed.
Click to expand it.
src/ArduinoJson/Collection/CollectionImpl.hpp
+
2
-
2
View file @
5790f3c8
...
...
@@ -62,9 +62,9 @@ inline bool CollectionData::copyFrom(const CollectionData& src,
VariantData
*
var
;
if
(
s
->
key
()
!=
0
)
{
if
(
s
->
ownsKey
())
var
=
addMember
(
Ram
String
Adapter
(
s
->
key
()),
pool
);
var
=
addMember
(
adapt
String
(
const_cast
<
char
*>
(
s
->
key
())
)
,
pool
);
else
var
=
addMember
(
ConstRamStringAdapter
(
s
->
key
()),
pool
);
var
=
addMember
(
adaptString
(
s
->
key
()),
pool
);
}
else
{
var
=
addElement
(
pool
);
}
...
...
This diff is collapsed.
Click to expand it.
src/ArduinoJson/Polyfills/type_traits.hpp
+
1
-
0
View file @
5790f3c8
...
...
@@ -20,5 +20,6 @@
#include
"type_traits/is_signed.hpp"
#include
"type_traits/is_unsigned.hpp"
#include
"type_traits/make_unsigned.hpp"
#include
"type_traits/make_void.hpp"
#include
"type_traits/remove_const.hpp"
#include
"type_traits/remove_reference.hpp"
This diff is collapsed.
Click to expand it.
src/ArduinoJson/
Strings/IsString
.hpp
→
src/ArduinoJson/
Polyfills/type_traits/make_void
.hpp
+
14
-
0
View file @
5790f3c8
...
...
@@ -4,15 +4,11 @@
#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
<
class
=
void
>
struct
make_void
{
typedef
void
type
;
};
template
<
typename
T
>
struct
IsString
<
T
&>
:
IsString
<
T
>
{};
}
// namespace ARDUINOJSON_NAMESPACE
This diff is collapsed.
Click to expand it.
src/ArduinoJson/Strings/ArduinoStringAdapter.hpp
→
src/ArduinoJson/Strings/
Adapters/
ArduinoStringAdapter.hpp
+
9
-
11
View file @
5790f3c8
...
...
@@ -7,14 +7,15 @@
#include
<Arduino.h>
#include
<ArduinoJson/Polyfills/safe_strcmp.hpp>
#include
<ArduinoJson/Strings/IsString.hpp>
#include
<ArduinoJson/Strings/StoragePolicy.hpp>
#include
<ArduinoJson/Strings/StringAdapter.hpp>
namespace
ARDUINOJSON_NAMESPACE
{
class
ArduinoStringAdapter
{
template
<
>
class
StringAdapter
<
::
String
>
{
public:
Arduino
StringAdapter
(
const
::
String
&
str
)
:
_str
(
&
str
)
{}
StringAdapter
(
const
::
String
&
str
)
:
_str
(
&
str
)
{}
void
copyTo
(
char
*
p
,
size_t
n
)
const
{
memcpy
(
p
,
_str
->
c_str
(),
n
);
...
...
@@ -46,13 +47,10 @@ class ArduinoStringAdapter {
};
template
<
>
struct
IsString
<
::
String
>
:
true_type
{};
template
<
>
struct
IsString
<
::
StringSumHelper
>
:
true_type
{};
inline
ArduinoStringAdapter
adaptString
(
const
::
String
&
str
)
{
return
ArduinoStringAdapter
(
str
);
}
class
StringAdapter
<
::
StringSumHelper
>
:
public
StringAdapter
<
::
String
>
{
public:
StringAdapter
<
::
StringSumHelper
>
(
const
::
String
&
s
)
:
StringAdapter
<
::
String
>
(
s
)
{}
};
}
// namespace ARDUINOJSON_NAMESPACE
This diff is collapsed.
Click to expand it.
src/ArduinoJson/Strings/ConstRamStringAdapter.hpp
→
src/ArduinoJson/Strings/
Adapters/
ConstRamStringAdapter.hpp
+
8
-
11
View file @
5790f3c8
...
...
@@ -8,14 +8,15 @@
#include
<string.h>
// strcmp
#include
<ArduinoJson/Polyfills/safe_strcmp.hpp>
#include
<ArduinoJson/Strings/IsString.hpp>
#include
<ArduinoJson/Strings/StoragePolicy.hpp>
#include
<ArduinoJson/Strings/StringAdapter.hpp>
namespace
ARDUINOJSON_NAMESPACE
{
class
ConstRamStringAdapter
{
template
<
>
class
StringAdapter
<
const
char
*>
{
public:
ConstRam
StringAdapter
(
const
char
*
str
=
0
)
:
_str
(
str
)
{}
StringAdapter
(
const
char
*
str
=
0
)
:
_str
(
str
)
{}
int
compare
(
const
char
*
other
)
const
{
return
safe_strcmp
(
_str
,
other
);
...
...
@@ -45,14 +46,10 @@ class ConstRamStringAdapter {
const
char
*
_str
;
};
template
<
>
struct
IsString
<
const
char
*>
:
true_type
{};
template
<
int
N
>
struct
IsString
<
const
char
[
N
]
>
:
true_type
{};
inline
ConstRamStringAdapter
adaptString
(
const
char
*
str
)
{
return
ConstRamStringAdapter
(
str
);
}
class
StringAdapter
<
const
char
[
N
]
>
:
public
StringAdapter
<
const
char
*>
{
public:
StringAdapter
<
const
char
[
N
]
>
(
const
char
*
s
)
:
StringAdapter
<
const
char
*>
(
s
)
{}
};
}
// namespace ARDUINOJSON_NAMESPACE
This diff is collapsed.
Click to expand it.
src/ArduinoJson/Strings/FlashStringAdapter.hpp
→
src/ArduinoJson/Strings/
Adapters/
FlashStringAdapter.hpp
+
4
-
9
View file @
5790f3c8
...
...
@@ -5,14 +5,15 @@
#pragma once
#include
<ArduinoJson/Polyfills/pgmspace.hpp>
#include
<ArduinoJson/Strings/IsString.hpp>
#include
<ArduinoJson/Strings/StoragePolicy.hpp>
#include
<ArduinoJson/Strings/StringAdapter.hpp>
namespace
ARDUINOJSON_NAMESPACE
{
class
FlashStringAdapter
{
template
<
>
class
StringAdapter
<
const
__FlashStringHelper
*>
{
public:
Flash
StringAdapter
(
const
__FlashStringHelper
*
str
)
:
_str
(
str
)
{}
StringAdapter
(
const
__FlashStringHelper
*
str
)
:
_str
(
str
)
{}
int
compare
(
const
char
*
other
)
const
{
if
(
!
other
&&
!
_str
)
...
...
@@ -48,10 +49,4 @@ class FlashStringAdapter {
const
__FlashStringHelper
*
_str
;
};
inline
FlashStringAdapter
adaptString
(
const
__FlashStringHelper
*
str
)
{
return
FlashStringAdapter
(
str
);
}
template
<
>
struct
IsString
<
const
__FlashStringHelper
*>
:
true_type
{};
}
// namespace ARDUINOJSON_NAMESPACE
This diff is collapsed.
Click to expand it.
src/ArduinoJson/Strings/Adapters/JsonStringAdapter.hpp
0 → 100644
+
27
-
0
View file @
5790f3c8
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include
<ArduinoJson/Strings/Adapters/RamStringAdapter.hpp>
#include
<ArduinoJson/Strings/String.hpp>
namespace
ARDUINOJSON_NAMESPACE
{
template
<
>
class
StringAdapter
<
String
>
:
public
StringAdapter
<
char
*>
{
public:
StringAdapter
(
const
String
&
str
)
:
StringAdapter
<
char
*>
(
str
.
c_str
()),
_isStatic
(
str
.
isStatic
())
{}
bool
isStatic
()
const
{
return
_isStatic
;
}
typedef
storage_policies
::
decide_at_runtime
storage_policy
;
private:
bool
_isStatic
;
};
}
// namespace ARDUINOJSON_NAMESPACE
This diff is collapsed.
Click to expand it.
src/ArduinoJson/Strings/RamStringAdapter.hpp
→
src/ArduinoJson/Strings/
Adapters/
RamStringAdapter.hpp
+
29
-
0
View file @
5790f3c8
...
...
@@ -4,15 +4,20 @@
#pragma once
#include
<ArduinoJson/Strings/ConstRamStringAdapter.hpp>
#include
<ArduinoJson/Strings/IsString.hpp>
#include
<ArduinoJson/Polyfills/type_traits.hpp>
#include
<ArduinoJson/Strings/StoragePolicy.hpp>
#include
<ArduinoJson/Strings/StringAdapter.hpp>
namespace
ARDUINOJSON_NAMESPACE
{
class
RamStringAdapter
:
public
ConstRamStringAdapter
{
template
<
typename
TChar
>
class
StringAdapter
<
TChar
*
,
false
,
typename
enable_if
<
sizeof
(
TChar
)
==
1
&&
!
is_same
<
TChar
,
void
>::
value
>::
type
>
:
public
StringAdapter
<
const
char
*>
{
public:
RamStringAdapter
(
const
char
*
str
)
:
ConstRamStringAdapter
(
str
)
{}
StringAdapter
(
const
TChar
*
str
)
:
StringAdapter
<
const
char
*>
(
reinterpret_cast
<
const
char
*>
(
str
))
{}
void
copyTo
(
char
*
p
,
size_t
n
)
const
{
memcpy
(
p
,
_str
,
n
);
...
...
@@ -21,23 +26,4 @@ class RamStringAdapter : public ConstRamStringAdapter {
typedef
ARDUINOJSON_NAMESPACE
::
storage_policies
::
store_by_copy
storage_policy
;
};
template
<
typename
TChar
>
inline
RamStringAdapter
adaptString
(
const
TChar
*
str
)
{
return
RamStringAdapter
(
reinterpret_cast
<
const
char
*>
(
str
));
}
inline
RamStringAdapter
adaptString
(
char
*
str
)
{
return
RamStringAdapter
(
str
);
}
template
<
typename
TChar
>
struct
IsString
<
TChar
*>
{
static
const
bool
value
=
sizeof
(
TChar
)
==
1
;
};
template
<
>
struct
IsString
<
void
*>
{
static
const
bool
value
=
false
;
};
}
// namespace ARDUINOJSON_NAMESPACE
This diff is collapsed.
Click to expand it.
src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp
→
src/ArduinoJson/Strings/
Adapters/
SizedFlashStringAdapter.hpp
+
4
-
7
View file @
5790f3c8
...
...
@@ -5,14 +5,15 @@
#pragma once
#include
<ArduinoJson/Namespace.hpp>
#include
<ArduinoJson/Strings/IsString.hpp>
#include
<ArduinoJson/Strings/StoragePolicy.hpp>
#include
<ArduinoJson/Strings/StringAdapter.hpp>
namespace
ARDUINOJSON_NAMESPACE
{
class
SizedFlashStringAdapter
{
template
<
>
class
StringAdapter
<
const
__FlashStringHelper
*
,
true
>
{
public:
SizedFlash
StringAdapter
(
const
__FlashStringHelper
*
str
,
size_t
sz
)
StringAdapter
(
const
__FlashStringHelper
*
str
,
size_t
sz
)
:
_str
(
str
),
_size
(
sz
)
{}
int
compare
(
const
char
*
other
)
const
{
...
...
@@ -48,8 +49,4 @@ class SizedFlashStringAdapter {
size_t
_size
;
};
inline
SizedFlashStringAdapter
adaptString
(
const
__FlashStringHelper
*
str
,
size_t
sz
)
{
return
SizedFlashStringAdapter
(
str
,
sz
);
}
}
// namespace ARDUINOJSON_NAMESPACE
This diff is collapsed.
Click to expand it.
src/ArduinoJson/Strings/SizedRamStringAdapter.hpp
→
src/ArduinoJson/Strings/
Adapters/
SizedRamStringAdapter.hpp
+
4
-
8
View file @
5790f3c8
...
...
@@ -5,16 +5,17 @@
#pragma once
#include
<ArduinoJson/Namespace.hpp>
#include
<ArduinoJson/Strings/IsString.hpp>
#include
<ArduinoJson/Strings/StoragePolicy.hpp>
#include
<ArduinoJson/Strings/StringAdapter.hpp>
#include
<string.h>
// strcmp
namespace
ARDUINOJSON_NAMESPACE
{
class
SizedRamStringAdapter
{
template
<
typename
TChar
>
class
StringAdapter
<
TChar
*
,
true
>
{
public:
SizedRam
StringAdapter
(
const
char
*
str
,
size_t
n
)
:
_str
(
str
),
_size
(
n
)
{}
StringAdapter
(
const
char
*
str
,
size_t
n
)
:
_str
(
str
),
_size
(
n
)
{}
int
compare
(
const
char
*
other
)
const
{
return
safe_strncmp
(
_str
,
other
,
_size
);
...
...
@@ -43,9 +44,4 @@ class SizedRamStringAdapter {
size_t
_size
;
};
template
<
typename
TChar
>
inline
SizedRamStringAdapter
adaptString
(
const
TChar
*
str
,
size_t
size
)
{
return
SizedRamStringAdapter
(
reinterpret_cast
<
const
char
*>
(
str
),
size
);
}
}
// namespace ARDUINOJSON_NAMESPACE
This diff is collapsed.
Click to expand it.
src/ArduinoJson/Strings/StdStringAdapter.hpp
→
src/ArduinoJson/Strings/
Adapters/
StdStringAdapter.hpp
+
7
-
16
View file @
5790f3c8
...
...
@@ -5,17 +5,19 @@
#pragma once
#include
<ArduinoJson/Namespace.hpp>
#include
<ArduinoJson/Strings/IsString.hpp>
#include
<ArduinoJson/Strings/StoragePolicy.hpp>
#include
<ArduinoJson/Strings/StringAdapter.hpp>
#include
<string>
namespace
ARDUINOJSON_NAMESPACE
{
template
<
typename
T
String
>
class
Std
StringAdapter
{
template
<
typename
T
CharTraits
,
typename
TAllocator
>
class
StringAdapter
<
std
::
basic_string
<
char
,
TCharTraits
,
TAllocator
>
>
{
public:
StdStringAdapter
(
const
TString
&
str
)
:
_str
(
&
str
)
{}
typedef
std
::
basic_string
<
char
,
TCharTraits
,
TAllocator
>
string_type
;
StringAdapter
(
const
string_type
&
str
)
:
_str
(
&
str
)
{}
void
copyTo
(
char
*
p
,
size_t
n
)
const
{
memcpy
(
p
,
_str
->
c_str
(),
n
);
...
...
@@ -44,18 +46,7 @@ class StdStringAdapter {
typedef
storage_policies
::
store_by_copy
storage_policy
;
private:
const
TS
tring
*
_str
;
const
s
tring
_type
*
_str
;
};
template
<
typename
TCharTraits
,
typename
TAllocator
>
struct
IsString
<
std
::
basic_string
<
char
,
TCharTraits
,
TAllocator
>
>
:
true_type
{
};
template
<
typename
TCharTraits
,
typename
TAllocator
>
inline
StdStringAdapter
<
std
::
basic_string
<
char
,
TCharTraits
,
TAllocator
>
>
adaptString
(
const
std
::
basic_string
<
char
,
TCharTraits
,
TAllocator
>&
str
)
{
return
StdStringAdapter
<
std
::
basic_string
<
char
,
TCharTraits
,
TAllocator
>
>
(
str
);
}
}
// namespace ARDUINOJSON_NAMESPACE
This diff is collapsed.
Click to expand it.
src/ArduinoJson/Strings/StringViewAdapter.hpp
→
src/ArduinoJson/Strings/
Adapters/
StringViewAdapter.hpp
+
4
-
10
View file @
5790f3c8
...
...
@@ -5,16 +5,17 @@
#pragma once
#include
<ArduinoJson/Namespace.hpp>
#include
<ArduinoJson/Strings/IsString.hpp>
#include
<ArduinoJson/Strings/StoragePolicy.hpp>
#include
<ArduinoJson/Strings/StringAdapter.hpp>
#include
<string_view>
namespace
ARDUINOJSON_NAMESPACE
{
class
StringViewAdapter
{
template
<
>
class
StringAdapter
<
std
::
string_view
>
{
public:
String
View
Adapter
(
std
::
string_view
str
)
:
_str
(
str
)
{}
StringAdapter
(
std
::
string_view
str
)
:
_str
(
str
)
{}
void
copyTo
(
char
*
p
,
size_t
n
)
const
{
memcpy
(
p
,
_str
.
data
(),
n
);
...
...
@@ -46,11 +47,4 @@ class StringViewAdapter {
std
::
string_view
_str
;
};
template
<
>
struct
IsString
<
std
::
string_view
>
:
true_type
{};
inline
StringViewAdapter
adaptString
(
const
std
::
string_view
&
str
)
{
return
StringViewAdapter
(
str
);
}
}
// namespace ARDUINOJSON_NAMESPACE
This diff is collapsed.
Click to expand it.
src/ArduinoJson/Strings/String.hpp
+
0
-
25
View file @
5790f3c8
...
...
@@ -4,10 +4,6 @@
#pragma once
#include
<ArduinoJson/Strings/ConstRamStringAdapter.hpp>
#include
<ArduinoJson/Strings/IsString.hpp>
#include
<ArduinoJson/Strings/StoragePolicy.hpp>
namespace
ARDUINOJSON_NAMESPACE
{
class
String
{
...
...
@@ -53,25 +49,4 @@ class String {
bool
_isStatic
;
};
class
StringAdapter
:
public
RamStringAdapter
{
public:
StringAdapter
(
const
String
&
str
)
:
RamStringAdapter
(
str
.
c_str
()),
_isStatic
(
str
.
isStatic
())
{}
bool
isStatic
()
const
{
return
_isStatic
;
}
typedef
storage_policies
::
decide_at_runtime
storage_policy
;
private:
bool
_isStatic
;
};
template
<
>
struct
IsString
<
String
>
:
true_type
{};
inline
StringAdapter
adaptString
(
const
String
&
str
)
{
return
StringAdapter
(
str
);
}
}
// namespace ARDUINOJSON_NAMESPACE
This diff is collapsed.
Click to expand it.
src/ArduinoJson/Strings/StringAdapter.hpp
0 → 100644
+
32
-
0
View file @
5790f3c8
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include
<ArduinoJson/Polyfills/type_traits.hpp>
namespace
ARDUINOJSON_NAMESPACE
{
template
<
typename
T
,
bool
bounded
=
false
,
typename
Enable
=
void
>
class
StringAdapter
;
template
<
typename
T
>
inline
StringAdapter
<
T
,
false
>
adaptString
(
const
T
&
str
)
{
return
StringAdapter
<
T
,
false
>
(
str
);
}
template
<
typename
T
>
inline
StringAdapter
<
T
,
true
>
adaptString
(
const
T
&
str
,
size_t
sz
)
{
return
StringAdapter
<
T
,
true
>
(
str
,
sz
);
}
template
<
typename
T
,
typename
Enable
=
void
>
struct
IsString
:
false_type
{};
template
<
typename
T
>
struct
IsString
<
T
,
typename
make_void
<
typename
StringAdapter
<
T
>::
storage_policy
>::
type
>
:
true_type
{};
}
// namespace ARDUINOJSON_NAMESPACE
This diff is collapsed.
Click to expand it.
src/ArduinoJson/Strings/StringAdapters.hpp
+
9
-
8
View file @
5790f3c8
...
...
@@ -4,23 +4,24 @@
#pragma once
#include
<ArduinoJson/Strings/ConstRamStringAdapter.hpp>
#include
<ArduinoJson/Strings/RamStringAdapter.hpp>
#include
<ArduinoJson/Strings/SizedRamStringAdapter.hpp>
#include
<ArduinoJson/Strings/Adapters/ConstRamStringAdapter.hpp>
#include
<ArduinoJson/Strings/Adapters/JsonStringAdapter.hpp>
#include
<ArduinoJson/Strings/Adapters/RamStringAdapter.hpp>
#include
<ArduinoJson/Strings/Adapters/SizedRamStringAdapter.hpp>
#if ARDUINOJSON_ENABLE_STD_STRING
# include <ArduinoJson/Strings/StdStringAdapter.hpp>
# include <ArduinoJson/Strings/
Adapters/
StdStringAdapter.hpp>
#endif
#if ARDUINOJSON_ENABLE_STRING_VIEW
# include <ArduinoJson/Strings/StringViewAdapter.hpp>
# include <ArduinoJson/Strings/
Adapters/
StringViewAdapter.hpp>
#endif
#if ARDUINOJSON_ENABLE_ARDUINO_STRING
# include <ArduinoJson/Strings/ArduinoStringAdapter.hpp>
# include <ArduinoJson/Strings/
Adapters/
ArduinoStringAdapter.hpp>
#endif
#if ARDUINOJSON_ENABLE_PROGMEM
# include <ArduinoJson/Strings/FlashStringAdapter.hpp>
# include <ArduinoJson/Strings/SizedFlashStringAdapter.hpp>
# include <ArduinoJson/Strings/
Adapters/
FlashStringAdapter.hpp>
# include <ArduinoJson/Strings/
Adapters/
SizedFlashStringAdapter.hpp>
#endif
This diff is collapsed.
Click to expand it.
src/ArduinoJson/Variant/VariantCompare.hpp
+
1
-
1
View file @
5790f3c8
...
...
@@ -8,7 +8,7 @@
#include
<ArduinoJson/Misc/Visitable.hpp>
#include
<ArduinoJson/Numbers/arithmeticCompare.hpp>
#include
<ArduinoJson/Polyfills/type_traits.hpp>
#include
<ArduinoJson/Strings/
Is
String.hpp>
#include
<ArduinoJson/Strings/String
Adapter
.hpp>
#include
<ArduinoJson/Variant/Visitor.hpp>
namespace
ARDUINOJSON_NAMESPACE
{
...
...
This diff is collapsed.
Click to expand it.
src/ArduinoJson/Variant/VariantData.hpp
+
3
-
2
View file @
5790f3c8
...
...
@@ -7,7 +7,7 @@
#include
<ArduinoJson/Memory/MemoryPool.hpp>
#include
<ArduinoJson/Misc/SerializedValue.hpp>
#include
<ArduinoJson/Numbers/convertNumber.hpp>
#include
<ArduinoJson/Strings/
Ram
StringAdapter.hpp>
#include
<ArduinoJson/Strings/StringAdapter
s
.hpp>
#include
<ArduinoJson/Variant/VariantContent.hpp>
// VariantData can't have a constructor (to be a POD), so we have no way to fix
...
...
@@ -103,7 +103,8 @@ class VariantData {
case
VALUE_IS_OBJECT
:
return
toObject
().
copyFrom
(
src
.
_content
.
asCollection
,
pool
);
case
VALUE_IS_OWNED_STRING
:
return
setString
(
RamStringAdapter
(
src
.
_content
.
asString
),
pool
);
return
setString
(
adaptString
(
const_cast
<
char
*>
(
src
.
_content
.
asString
)),
pool
);
case
VALUE_IS_OWNED_RAW
:
return
setOwnedRaw
(
serialized
(
src
.
_content
.
asRaw
.
data
,
src
.
_content
.
asRaw
.
size
),
pool
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets