forked from bblanchon/ArduinoJson
Reduced the size of EscapedString::printTo() by 4 more bytes
This commit is contained in:
1 parent
af7dd55d34
commit
a48fbac7d7
1 file changed
+14
-11
@@ -21,6 +21,19 @@ static inline char getSpecialChar(char c)
|
|||||||
return p[1];
|
return p[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline size_t printCharTo(char c, Print& p)
|
||||||
|
{
|
||||||
|
char specialChar = getSpecialChar(c);
|
||||||
|
if (specialChar)
|
||||||
|
{
|
||||||
|
return p.write('\\') + p.write(specialChar);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return p.write(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t EscapedString::printTo(Print& p) const
|
size_t EscapedString::printTo(Print& p) const
|
||||||
{
|
{
|
||||||
const char* s = rawString;
|
const char* s = rawString;
|
||||||
@@ -36,17 +49,7 @@ size_t EscapedString::printTo(Print& p) const
|
|||||||
|
|
||||||
while (*s)
|
while (*s)
|
||||||
{
|
{
|
||||||
char specialChar = getSpecialChar(*s);
|
n += printCharTo(*s, p);
|
||||||
|
|
||||||
if (specialChar)
|
|
||||||
{
|
|
||||||
n += p.write('\\');
|
|
||||||
n += p.write(specialChar);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
n += p.write(*s);
|
|
||||||
}
|
|
||||||
|
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user