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

bblanchon / ArduinoJson / 5313785987

pending completion
5313785987

push

github

bblanchon
Extract `arrayEquals()` and `objectEquals()`

28 of 28 new or added lines in 4 files covered. (100.0%)

3362 of 3383 relevant lines covered (99.38%)

6246.1 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-2023, Benoit BLANCHON
3
// MIT License
4

5
#pragma once
6

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

10
ARDUINOJSON_BEGIN_PUBLIC_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 detail::enable_if<!detail::is_array<T>::value, bool>::type
16
copyArray(const T& src, JsonVariant dst) {
42✔
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 detail::enable_if<
24
    !detail::is_base_of<JsonDocument, TDestination>::value, 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 detail::enable_if<
33
    !detail::is_base_of<JsonDocument, TDestination>::value, 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 detail::enable_if<!detail::is_array<T>::value, size_t>::type
67
copyArray(JsonVariantConst src, T& dst) {
29✔
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 detail::enable_if<
107
    detail::is_array<T>::value &&
108
        detail::is_base_of<JsonDocument, TSource>::value,
109
    size_t>::type
110
copyArray(const TSource& src, T& dst) {
2✔
111
  return copyArray(src.template as<JsonArrayConst>(), dst);
2✔
112
}
113

114
ARDUINOJSON_END_PUBLIC_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