Minh Nguyen / ArduinoJson
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EscapeSequence.hpp Source File

EscapeSequence.hpp

00001 // ArduinoJson - arduinojson.org
00002 // Copyright Benoit Blanchon 2014-2021
00003 // MIT License
00004 
00005 #pragma once
00006 
00007 #include <ArduinoJson/Namespace.hpp>
00008 
00009 namespace ARDUINOJSON_NAMESPACE {
00010 
00011 class EscapeSequence {
00012  public:
00013   // Optimized for code size on a 8-bit AVR
00014   static char escapeChar(char c) {
00015     const char *p = escapeTable(true);
00016     while (p[0] && p[1] != c) {
00017       p += 2;
00018     }
00019     return p[0];
00020   }
00021 
00022   // Optimized for code size on a 8-bit AVR
00023   static char unescapeChar(char c) {
00024     const char *p = escapeTable(false);
00025     for (;;) {
00026       if (p[0] == '\0')
00027         return 0;
00028       if (p[0] == c)
00029         return p[1];
00030       p += 2;
00031     }
00032   }
00033 
00034  private:
00035   static const char *escapeTable(bool excludeSolidus) {
00036     return &"//\"\"\\\\b\bf\fn\nr\rt\t"[excludeSolidus ? 2 : 0];
00037   }
00038 };
00039 }  // namespace ARDUINOJSON_NAMESPACE