Re: Glib::ustring, error while reading an utf-8 encoded file



On Tue, 2009-01-20 at 14:56 +0100, Bastien Dalla Piazza wrote:

1: as-is: "First line: plain text."
1: through Glib::ustring: "First line: plain text."
2: as-is: "deuxiÃme ligne: des accents ici et lÃ..."

You are lucky that that worked. It's unlikely to work with multi-byte
UTF-8 characters such as Asian characters.

2: through Glib::ustring: "
Glib::ConvertError: Invalid byte sequence in conversion input

my locale is using utf-8 (fr_CH).

The question is: How to import the file content in an Glib::ustring
when
already knowing its encoding (not necessarily utf-8 though)?

The exception is actually coming from your use of << with the standard C
++ stream. The standard C++ streams can't do UTF-8 so there is an
automatic conversion. See "streams input/output" here:
http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1ustring.html#_details

The answer, I think, is Just don't use std::cout and friends to show
UTF-8.

-- 
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]