Coverage Report

Created: 2023-06-07 06:03

/src/arduinojson/src/ArduinoJson/Json/EscapeSequence.hpp
Line
Count
Source
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2023, Benoit BLANCHON
3
// MIT License
4
5
#pragma once
6
7
#include <ArduinoJson/Namespace.hpp>
8
9
ARDUINOJSON_BEGIN_PRIVATE_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
9.63k
    while (p[0] && p[1] != c) {
17
8.23k
      p += 2;
18
8.23k
    }
19
1.40k
    return p[0];
20
1.40k
  }
21
22
  // Optimized for code size on a 8-bit AVR
23
107
  static char unescapeChar(char c) {
24
107
    const char* p = escapeTable(false);
25
531
    for (;;) {
26
531
      if (p[0] == '\0')
27
11
        return 0;
28
520
      if (p[0] == c)
29
96
        return p[1];
30
424
      p += 2;
31
424
    }
32
107
  }
33
34
 private:
35
1.51k
  static const char* escapeTable(bool excludeSolidus) {
36
1.51k
    return &"//\"\"\\\\b\bf\fn\nr\rt\t"[excludeSolidus ? 2 : 0];
37
1.51k
  }
38
};
39
40
ARDUINOJSON_END_PRIVATE_NAMESPACE