Hmm, the current approach does escape all these characters, the only thing that doesn't work and doesn't need to work is preserving whitespace with this method.