Mst::escapeDiffOffTbl(): Handle '\n', '\f' and '\\'.

Similar to the regular escaped() function.

'\\' is especially needed, since otherwise the escapes wouldn't
work correctly.
This commit is contained in:
David Korth 2019-05-27 19:52:43 -04:00
parent f570aff7a0
commit f7ce4f14e7

View File

@ -1143,9 +1143,23 @@ string Mst::escapeDiffOffTbl(const uint8_t *diffTbl, size_t len)
for (; len > 0; diffTbl++, len--) {
if (*diffTbl < 0x20 || *diffTbl >= 0x7F) {
// Escape the character.
switch (*diffTbl) {
case '\\':
ret += "\\";
break;
case '\n':
ret += "\\n";
break;
case '\f':
ret += "\\r";
break;
default: {
char buf[8];
snprintf(buf, sizeof(buf), "\\x%02X", *diffTbl);
ret += buf;
break;
}
}
} else {
// Use the character as-is.
ret += *diffTbl;