Re: Save files with correct character set



On Thu, 22 Mar 2012 20:11:31 +0100
Spazzatura.Live <kharhonte hotmail com> wrote:
> You're right, the content is UTF-8, so my problem is that i don't need
> one like that.
> 
> I thought the casting from Glib::ustring to std::string also made a
> conversion of the content (from unicode char) so the file has wrong
> extended character so that was the issue...
> 
> Probably, instead, is the tool i use after which doesn't support
> Unicode file (i mean files with Unicode character encoding).
> 
> So the new question is that: How can i convert the Glib::ustring from
> Unicode to ASCII (ISO-8859-1) and save to file?

ISO-8859-1 (Latin-1) is not ASCII.  It uses the 8th bit for non-ASCII
characters.  Latin-1 and UTF-8 are ASCII compatible if you stick to the
ASCII character set.

If you are saving data to file, it is much better to save it in unicode
format as UTF-8, and if you need to convert it, convert it when reading.
However, if you really think you need to convert to Latin-1, use
Glib::convert().

But what drew you to Latin-1?  If that is your locale encoding, it won't
necessarily be other people's locale encoding, and for that reason
saving data to file in the locale encoding is generally a bad idea, as
it is non-portable. However, if that is not an issue, you could use
Glib::locale_from_utf8().

Chris


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