Re: [[gtkmm] Problem with std::string -> Glib::ustring conversion]
- From: joey yandle <joey divisionbyzero com>
- To: Brian Gartner <cadrach-gtkmm wcug wwu edu>
- Cc: gtkmm list <gtkmm-list gnome org>
- Subject: Re: [[gtkmm] Problem with std::string -> Glib::ustring conversion]
- Date: Sun, 14 Sep 2003 16:07:07 -0400 (EDT)
>
> 1) Is it possible to simply specify that a string must be converted from
> e.g. ISO 8859-1, including the characters with values > 127, into UTF-8? I
> thought that this was what locale_to_utf8 would do, but if so I'm doing
> something wrong, as my program crashed when I called it on strings
> containing characters with values > 127.
>
Yes... here's a code snippet:
std::string charset = "ISO-8859-1";
std::string data = read_from_file();
Glib::ustring ret;
try {
ret = Glib::convert(data, "UTF-8", charset);
} catch(Glib::Exception& e) {
ret = data;
Glib::ustring::iterator i;
while(!ret.validate(i)) {
ret.replace(i++, i, "*");
}
}
cheers,
--
joey yandle ___====-_ _-====___
www.divisionbyzero.com _--~~~#####// \\#####~~~--_
/jwy/pubkey.asc _-~##########// ( ) \\##########~-_
-############// :\^^/: \\############-
_~############// (@::@) \\############~_
~#############(( \\// ))#############~
-###############\\ (^^) //###############-
-#################\\ / "" \ //#################-
-###################\\/ \//###################-
_#/:##########/\######( /\ )######/\##########:\#_
:/ :#/\#/\#/\/ \#/\##\ : : /##/\#/ \/\#/\#/\#: \:
" :/ V V " V \#\: : : :/#/ V " V V \: "
" " " " \ : : : : / " " " "
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]