The ostream passed as reference to `hexEscapeChar` is manipulated
and its original state not restored. This fixes it.
Seen via coverity in a downstream project.
There are still some holes, e.g. we leave surrogate pairs be
even though they are not a part of valid UTF-8, but this might
be for the better -- WTF-8 does support surrogate pairs inside
text.
Closes#1207