summaryrefslogtreecommitdiff
path: root/include/lib/ArduinoJson/Json/EscapeSequence.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/lib/ArduinoJson/Json/EscapeSequence.hpp')
-rw-r--r--include/lib/ArduinoJson/Json/EscapeSequence.hpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/include/lib/ArduinoJson/Json/EscapeSequence.hpp b/include/lib/ArduinoJson/Json/EscapeSequence.hpp
new file mode 100644
index 0000000..811e825
--- /dev/null
+++ b/include/lib/ArduinoJson/Json/EscapeSequence.hpp
@@ -0,0 +1,39 @@
+// ArduinoJson - https://arduinojson.org
+// Copyright Benoit Blanchon 2014-2021
+// MIT License
+
+#pragma once
+
+#include <ArduinoJson/Namespace.hpp>
+
+namespace ARDUINOJSON_NAMESPACE {
+
+class EscapeSequence {
+ public:
+ // Optimized for code size on a 8-bit AVR
+ static char escapeChar(char c) {
+ const char *p = escapeTable(true);
+ while (p[0] && p[1] != c) {
+ p += 2;
+ }
+ return p[0];
+ }
+
+ // Optimized for code size on a 8-bit AVR
+ static char unescapeChar(char c) {
+ const char *p = escapeTable(false);
+ for (;;) {
+ if (p[0] == '\0')
+ return 0;
+ if (p[0] == c)
+ return p[1];
+ p += 2;
+ }
+ }
+
+ private:
+ static const char *escapeTable(bool excludeSolidus) {
+ return &"//\"\"\\\\b\bf\fn\nr\rt\t"[excludeSolidus ? 2 : 0];
+ }
+};
+} // namespace ARDUINOJSON_NAMESPACE