This is a bit shorter and a lot safer. Substrings of unescaped characters are added by a single call to reduce overhead. Extend test 1465 to handle more kind of escapes. Closes #9653