Change character encoding error correction method

The previous method sometimes didn't catch all the encoding errors.

Signed-off-by: Lucas Dutra Nunes <ldnunes@ossystems.com.br>