• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bblanchon / ArduinoJson / 4143639874

pending completion
4143639874

push

github

Benoit Blanchon
Remove `ARDUINOJSON_HAS_NULLPTR`

3390 of 3406 relevant lines covered (99.53%)

5984.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/ArduinoJson/Array/Utilities.hpp
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2022, Benoit BLANCHON
3
// MIT License
4

5
#pragma once
6

7
#include <ArduinoJson/Array/JsonArray.hpp>
8
#include <ArduinoJson/Document/JsonDocument.hpp>
9

10
namespace ARDUINOJSON_NAMESPACE {
11

12
// Copies a value to a JsonVariant.
13
// This is a degenerated form of copyArray() to stop the recursion.
14
template <typename T>
15
inline typename enable_if<!is_array<T>::value, bool>::type copyArray(
42✔
16
    const T& src, JsonVariant dst) {
17
  return dst.set(src);
45✔
18
}
19

20
// Copies values from an array to a JsonArray or a JsonVariant.
21
// https://arduinojson.org/v6/api/misc/copyarray/
22
template <typename T, size_t N, typename TDestination>
23
inline typename enable_if<!is_base_of<JsonDocument, TDestination>::value,
24
                          bool>::type
25
copyArray(T (&src)[N], const TDestination& dst) {
30✔
26
  return copyArray(src, N, dst);
30✔
27
}
28

29
// Copies values from an array to a JsonArray or a JsonVariant.
30
// https://arduinojson.org/v6/api/misc/copyarray/
31
template <typename T, typename TDestination>
32
inline typename enable_if<!is_base_of<JsonDocument, TDestination>::value,
33
                          bool>::type
34
copyArray(const T* src, size_t len, const TDestination& dst) {
21✔
35
  bool ok = true;
21✔
36
  for (size_t i = 0; i < len; i++) {
80✔
37
    ok &= copyArray(src[i], dst.add());
59✔
38
  }
39
  return ok;
21✔
40
}
41

42
// Copies a string to a JsonVariant.
43
// This is a degenerated form of copyArray() to handle strings.
44
template <typename TDestination>
45
inline bool copyArray(const char* src, size_t, const TDestination& dst) {
9✔
46
  return dst.set(src);
9✔
47
}
48

49
// Copies values from an array to a JsonDocument.
50
// https://arduinojson.org/v6/api/misc/copyarray/
51
template <typename T>
52
inline bool copyArray(const T& src, JsonDocument& dst) {
3✔
53
  return copyArray(src, dst.to<JsonArray>());
3✔
54
}
55

56
// Copies an array to a JsonDocument.
57
// https://arduinojson.org/v6/api/misc/copyarray/
58
template <typename T>
59
inline bool copyArray(const T* src, size_t len, JsonDocument& dst) {
60
  return copyArray(src, len, dst.to<JsonArray>());
61
}
62

63
// Copies a value from a JsonVariant.
64
// This is a degenerated form of copyArray() to stop the recursion.
65
template <typename T>
66
inline typename enable_if<!is_array<T>::value, size_t>::type copyArray(
29✔
67
    JsonVariantConst src, T& dst) {
68
  dst = src.as<T>();
29✔
69
  return 1;
29✔
70
}
71

72
// Copies values from a JsonArray or JsonVariant to an array.
73
// https://arduinojson.org/v6/api/misc/copyarray/
74
template <typename T, size_t N>
75
inline size_t copyArray(JsonArrayConst src, T (&dst)[N]) {
19✔
76
  return copyArray(src, dst, N);
19✔
77
}
78

79
// Copies values from a JsonArray or JsonVariant to an array.
80
// https://arduinojson.org/v6/api/misc/copyarray/
81
template <typename T>
82
inline size_t copyArray(JsonArrayConst src, T* dst, size_t len) {
19✔
83
  size_t i = 0;
19✔
84
  for (JsonArrayConst::iterator it = src.begin(); it != src.end() && i < len;
120✔
85
       ++it)
41✔
86
    copyArray(*it, dst[i++]);
50✔
87
  return i;
19✔
88
}
89

90
// Copies a string from a JsonVariant.
91
// This is a degenerated form of copyArray() to handle strings.
92
template <size_t N>
93
inline size_t copyArray(JsonVariantConst src, char (&dst)[N]) {
3✔
94
  JsonString s = src;
95
  size_t len = N - 1;
3✔
96
  if (len > s.size())
3✔
97
    len = s.size();
1✔
98
  memcpy(dst, s.c_str(), len);
3✔
99
  dst[len] = 0;
3✔
100
  return 1;
3✔
101
}
102

103
// Copies values from a JsonDocument to an array.
104
// https://arduinojson.org/v6/api/misc/copyarray/
105
template <typename TSource, typename T>
106
inline typename enable_if<is_array<T>::value &&
107
                              is_base_of<JsonDocument, TSource>::value,
108
                          size_t>::type
109
copyArray(const TSource& src, T& dst) {
2✔
110
  return copyArray(src.template as<JsonArrayConst>(), dst);
2✔
111
}
112

113
}  // namespace ARDUINOJSON_NAMESPACE
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc