for (ptrdiff_t i = 0; i < nbytes; i++)
{
unsigned char c = SREF (str, i);
- escapes += (c == '\0' || c == '\n' || c == '\r' || c == '\t' || c == '"');
+ escapes += (c == '\0' || c == '\n' || c == '\r' || c == '\t'
+ || c == '"' || c == '\\');
}
ptrdiff_t nchars = SCHARS (str);
ptrdiff_t extra = escapes + 2; /* backslashes + double quotes */
case '\n': *d++ = '\\'; *d++ = 'n'; break;
case '\r': *d++ = '\\'; *d++ = 'r'; break;
case '\t': *d++ = '\\'; *d++ = 't'; break;
- case '"': *d++ = '\\'; *d++ = '"'; break;
+ case '"':
+ case '\\': *d++ = '\\'; *d++ = c; break;
default: *d++ = c; break;
}
}
;; Test string conversion in `treesit-pattern-expand'.
(should (equal
- (treesit-pattern-expand "a\nb\rc\td\0e\"f\1g")
- "\"a\\nb\\rc\\td\\0e\\\"f\1g\"")))))
+ (treesit-pattern-expand "a\nb\rc\td\0e\"f\1g\\h\fi")
+ "\"a\\nb\\rc\\td\\0e\\\"f\1g\\\\h\fi\"")))))
;;; Narrow