Coverage Report

Created: 2026-03-13 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/arduinojson/src/ArduinoJson/Json/Utf16.hpp
Line
Count
Source
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2025, Benoit BLANCHON
3
// MIT License
4
5
#pragma once
6
7
#include <ArduinoJson/Namespace.hpp>
8
9
#include <stdint.h>  // uint16_t, uint32_t
10
11
// The high surrogate may be uninitialized if the pair is invalid,
12
// we choose to ignore the problem to reduce the size of the code
13
// Garbage in => Garbage out
14
#if defined(__GNUC__)
15
#  if __GNUC__ >= 7
16
#    pragma GCC diagnostic push
17
#    pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
18
#  endif
19
#endif
20
21
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
22
23
namespace Utf16 {
24
641
inline bool isHighSurrogate(uint16_t codeunit) {
25
641
  return codeunit >= 0xD800 && codeunit < 0xDC00;
26
641
}
27
28
557
inline bool isLowSurrogate(uint16_t codeunit) {
29
557
  return codeunit >= 0xDC00 && codeunit < 0xE000;
30
557
}
31
32
class Codepoint {
33
 public:
34
1.40k
  Codepoint() : highSurrogate_(0), codepoint_(0) {}
35
36
641
  bool append(uint16_t codeunit) {
37
641
    if (isHighSurrogate(codeunit)) {
38
84
      highSurrogate_ = codeunit & 0x3FF;
39
84
      return false;
40
84
    }
41
42
557
    if (isLowSurrogate(codeunit)) {
43
165
      codepoint_ =
44
165
          uint32_t(0x10000 + ((highSurrogate_ << 10) | (codeunit & 0x3FF)));
45
165
      return true;
46
165
    }
47
48
392
    codepoint_ = codeunit;
49
392
    return true;
50
557
  }
51
52
557
  uint32_t value() const {
53
557
    return codepoint_;
54
557
  }
55
56
 private:
57
  uint16_t highSurrogate_;
58
  uint32_t codepoint_;
59
};
60
}  // namespace Utf16
61
ARDUINOJSON_END_PRIVATE_NAMESPACE
62
63
#if defined(__GNUC__)
64
#  if __GNUC__ >= 8
65
#    pragma GCC diagnostic pop
66
#  endif
67
#endif