Coverage Report

Created: 2022-11-24 06:23

/src/arduinojson/src/ArduinoJson/Json/EscapeSequence.hpp
Line
Count
Source
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2022, Benoit BLANCHON
3
// MIT License
4
5
#pragma once
6
7
#include <ArduinoJson/Namespace.hpp>
8
9
namespace ARDUINOJSON_NAMESPACE {
10
11
class EscapeSequence {
12
 public:
13
  // Optimized for code size on a 8-bit AVR
14
1.40k
  static char escapeChar(char c) {
15
1.40k
    const char* p = escapeTable(true);
16
10.5k
    while (p[0] && p[1] != c) {
17
9.10k
      p += 2;
18
9.10k
    }
19
1.40k
    return p[0];
20
1.40k
  }
21
22
  // Optimized for code size on a 8-bit AVR
23
117
  static char unescapeChar(char c) {
24
117
    const char* p = escapeTable(false);
25
581
    for (;;) {
26
581
      if (p[0] == '\0')
27
16
        return 0;
28
565
      if (p[0] == c)
29
101
        return p[1];
30
464
      p += 2;
31
464
    }
32
117
  }
33
34
 private:
35
1.52k
  static const char* escapeTable(bool excludeSolidus) {
36
1.52k
    return &"//\"\"\\\\b\bf\fn\nr\rt\t"[excludeSolidus ? 2 : 0];
37
1.52k
  }
38
};
39
}  // namespace ARDUINOJSON_NAMESPACE