PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
ArduinoJson
src
ArduinoJson
Strings
ArduinoStringAdapter.hpp
1
// ArduinoJson - arduinojson.org
2
// Copyright Benoit Blanchon 2014-2020
3
// MIT License
4
5
#pragma once
6
7
#include <Arduino.h>
8
9
#include <ArduinoJson/Polyfills/safe_strcmp.hpp>
10
#include <ArduinoJson/Strings/IsString.hpp>
11
#include <ArduinoJson/Strings/StoragePolicy.hpp>
12
13
namespace
ARDUINOJSON_NAMESPACE {
14
15
class
ArduinoStringAdapter
{
16
public
:
17
ArduinoStringAdapter
(const ::String& str) : _str(&str) {}
18
19
void
copyTo(
char
* p,
size_t
n)
const
{
20
memcpy(p, _str->c_str(), n);
21
}
22
23
bool
isNull()
const
{
24
// Arduino's String::c_str() can return NULL
25
return
!_str->c_str();
26
}
27
28
int
compare(
const
char
* other)
const
{
29
// Arduino's String::c_str() can return NULL
30
const
char
* me = _str->c_str();
31
return
safe_strcmp(me, other);
32
}
33
34
bool
equals(
const
char
* expected)
const
{
35
return
compare(expected) == 0;
36
}
37
38
size_t
size()
const
{
39
return
_str->length();
40
}
41
42
const
char
* begin()
const
{
43
return
_str->c_str();
44
}
45
46
typedef
storage_policies::store_by_copy
storage_policy
;
47
48
private
:
49
const ::String* _str;
50
};
51
52
template
<>
53
struct
IsString
< ::
String
> :
true_type
{};
54
55
template
<>
56
struct
IsString
< ::StringSumHelper> :
true_type
{};
57
58
inline
ArduinoStringAdapter
adaptString(const ::String& str) {
59
return
ArduinoStringAdapter
(str);
60
}
61
62
}
// namespace ARDUINOJSON_NAMESPACE
ARDUINOJSON_NAMESPACE::String
Definition:
String.hpp:13
ARDUINOJSON_NAMESPACE::IsString
Definition:
IsString.hpp:11
ARDUINOJSON_NAMESPACE::integral_constant
Definition:
integral_constant.hpp:12
ARDUINOJSON_NAMESPACE::ArduinoStringAdapter
Definition:
ArduinoStringAdapter.hpp:15
ARDUINOJSON_NAMESPACE::storage_policies::store_by_copy
Definition:
StoragePolicy.hpp:11
Generated on Fri May 20 2022 16:48:01 for PropWare by
1.8.17