The index operator doesn't use the `char` boundaries, but rather
byte boundaries. So I switched back to a simpler, but slightly
less efficient loop that simply adds individual characters to the
output.
It also doesn't escape Unicode anymore, as this shouldn't be an issue
in UTF-8 encoded output files.