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

bblanchon / ArduinoJson / 6770901880

06 Nov 2023 12:24PM CUT coverage: 99.545%. Remained the same
6770901880

push

github

bblanchon
CI: always use libc++ with clang

3497 of 3513 relevant lines covered (99.54%)

10637.15 hits per line

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

93.94
/src/ArduinoJson/Strings/Adapters/FlashString.hpp
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2023, Benoit BLANCHON
3
// MIT License
4

5
#pragma once
6

7
#include <ArduinoJson/Polyfills/pgmspace.hpp>
8
#include <ArduinoJson/Strings/StringAdapter.hpp>
9

10
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
11

12
class FlashString {
13
 public:
14
  static const size_t typeSortKey = 1;
15

16
  FlashString(const __FlashStringHelper* str, size_t sz)
32✔
17
      : str_(reinterpret_cast<const char*>(str)), size_(sz) {}
32✔
18

19
  bool isNull() const {
21✔
20
    return !str_;
21✔
21
  }
22

23
  char operator[](size_t i) const {
46✔
24
    ARDUINOJSON_ASSERT(str_ != 0);
25
    ARDUINOJSON_ASSERT(i <= size_);
26
    return static_cast<char>(pgm_read_byte(str_ + i));
46✔
27
  }
28

29
  const char* data() const {
×
30
    return nullptr;
×
31
  }
32

33
  size_t size() const {
42✔
34
    return size_;
42✔
35
  }
36

37
  friend bool stringEquals(FlashString a, SizedRamString b) {
6✔
38
    ARDUINOJSON_ASSERT(a.typeSortKey < b.typeSortKey);
39
    ARDUINOJSON_ASSERT(!a.isNull());
40
    ARDUINOJSON_ASSERT(!b.isNull());
41
    if (a.size() != b.size())
6✔
42
      return false;
2✔
43
    return ::memcmp_P(b.data(), a.str_, a.size_) == 0;
4✔
44
  }
45

46
  friend int stringCompare(FlashString a, SizedRamString b) {
6✔
47
    ARDUINOJSON_ASSERT(a.typeSortKey < b.typeSortKey);
48
    ARDUINOJSON_ASSERT(!a.isNull());
49
    ARDUINOJSON_ASSERT(!b.isNull());
50
    size_t minsize = a.size() < b.size() ? a.size() : b.size();
6✔
51
    int res = ::memcmp_P(b.data(), a.str_, minsize);
6✔
52
    if (res)
6✔
53
      return -res;
2✔
54
    if (a.size() < b.size())
4✔
55
      return -1;
1✔
56
    if (a.size() > b.size())
3✔
57
      return 1;
1✔
58
    return 0;
2✔
59
  }
60

61
  friend void stringGetChars(FlashString s, char* p, size_t n) {
6✔
62
    ARDUINOJSON_ASSERT(s.size() <= n);
63
    ::memcpy_P(p, s.str_, n);
6✔
64
  }
6✔
65

66
  bool isLinked() const {
8✔
67
    return false;
8✔
68
  }
69

70
 private:
71
  const char* str_;
72
  size_t size_;
73
};
74

75
template <>
76
struct StringAdapter<const __FlashStringHelper*, void> {
77
  typedef FlashString AdaptedString;
78

79
  static AdaptedString adapt(const __FlashStringHelper* s) {
27✔
80
    return AdaptedString(s, s ? strlen_P(reinterpret_cast<const char*>(s)) : 0);
27✔
81
  }
82
};
83

84
template <>
85
struct SizedStringAdapter<const __FlashStringHelper*, void> {
86
  typedef FlashString AdaptedString;
87

88
  static AdaptedString adapt(const __FlashStringHelper* s, size_t n) {
5✔
89
    return AdaptedString(s, n);
5✔
90
  }
91
};
92

93
ARDUINOJSON_END_PRIVATE_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