fix encode error for multibyte charsets