Add a backport of surrogateescape, written by haypo.

Closes #9.