2017-01-06 21:07:34 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2017
|
2015-07-10 22:11:26 +02:00
|
|
|
// MIT License
|
|
|
|
//
|
|
|
|
// Arduino JSON library
|
2017-03-25 22:05:06 +01:00
|
|
|
// https://bblanchon.github.io/ArduinoJson/
|
2016-01-07 22:35:12 +01:00
|
|
|
// If you like this project, please add a star!
|
2015-07-10 22:11:26 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2016-05-06 08:44:31 +02:00
|
|
|
#include "../Print.hpp"
|
2015-07-10 22:11:26 +02:00
|
|
|
|
|
|
|
namespace ArduinoJson {
|
|
|
|
namespace Internals {
|
|
|
|
|
|
|
|
class Encoding {
|
|
|
|
public:
|
|
|
|
// Optimized for code size on a 8-bit AVR
|
|
|
|
static char escapeChar(char c) {
|
2016-06-22 21:41:19 +02:00
|
|
|
const char *p = escapeTable(false);
|
2015-07-10 22:11:26 +02:00
|
|
|
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) {
|
2016-06-22 21:41:19 +02:00
|
|
|
const char *p = escapeTable(true);
|
2015-07-10 22:11:26 +02:00
|
|
|
for (;;) {
|
|
|
|
if (p[0] == '\0') return c;
|
|
|
|
if (p[0] == c) return p[1];
|
|
|
|
p += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-07 22:35:12 +01:00
|
|
|
private:
|
2016-06-22 21:41:19 +02:00
|
|
|
static const char *escapeTable(bool excludeIdenticals) {
|
|
|
|
return &"\"\"\\\\b\bf\fn\nr\rt\t"[excludeIdenticals ? 4 : 0];
|
|
|
|
}
|
2015-07-10 22:11:26 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|