Re: [[gtkmm] Problem with std::string -> Glib::ustring conversion]



> 
> 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]