Prioritizes escaping predefined Escape Sequences over Unescaping UTF-8 Sequences

This commit is contained in:
Dev Bali 2019-07-23 11:08:54 -07:00
parent d6bcdfce52
commit 3efbea0b84

View file

@ -261,7 +261,7 @@ size_t check_utf8 (const char* bytes, size_t n, size_t i)
{ {
// Check if this is infact a multibyte UTF-8 sequence, // Check if this is infact a multibyte UTF-8 sequence,
// which requires a 1 to be the first bit of the first byte // which requires a 1 to be the first bit of the first byte
if (!(bytes[i] >> 7 & 1)) if (!(bytes[i] >> 7 & 1))
return 0; return 0;
// Checks two to four bytes from starting position i // Checks two to four bytes from starting position i
@ -291,7 +291,12 @@ pair<const char*, size_t> ODesc::FirstEscapeLoc(const char* bytes, size_t n)
if (bytes[i] == '\\' ) if (bytes[i] == '\\' )
return escape_pos(bytes + i, 1); return escape_pos(bytes + i, 1);
else if (!isprint(bytes[i])) size_t len = StartsWithEscapeSequence(bytes + i, bytes + n);
if ( len )
return escape_pos(bytes + i, len);
if (!isprint(bytes[i]))
{ {
if (utf8) if (utf8)
{ {
@ -305,10 +310,6 @@ pair<const char*, size_t> ODesc::FirstEscapeLoc(const char* bytes, size_t n)
return escape_pos(bytes + i, 1); return escape_pos(bytes + i, 1);
} }
size_t len = StartsWithEscapeSequence(bytes + i, bytes + n);
if ( len )
return escape_pos(bytes + i, len);
} }
return escape_pos(0, 0); return escape_pos(0, 0);