Re: ustring bug?



Hello,

Maybe you can try this approach:

~=~
//compile this with:
//gcc -g `pkg-config --cflags --libs glibmm-2.4` -o test test.cc
//assuming the filename is test.cc .

#include <locale.h>
#include <iostream>
#include <glibmm.h>

using namespace std ;

int
main (int argc, char **argv)
{
   //initialize the conversion functions correctly
   setlocale (LC_ALL, "") ;

   try {
       //convert a fixed char size string (where each char is 1 byte
long) into an utf8 string
       //(where each char can be between 1 and 4 bytes long)
       //using the conversion functions
       Glib::ustring utf8_str = Glib::locale_to_utf8 ("éçà") ;
   } catch (Glib::ConvertError &e) {
       cerr << "got converter error: " << e.what () << "\n";
       return -1 ;
   } catch (...) {
       cerr << "got an unknown error\n" ;
       return -1 ;
   }
   cout << "whoo, it works\n" ;
   return 0 ;
}
~=~

My locale is fr_FR euro  Maybe this works for you.

Do not forget to call setlocale (LC_ALL, "") to initialize the charset
conversion subsytem.

Also, I think ustring("foo") cannot work properly if "foo" is not a
valid utf8 sequence.
In your case, "foo" is not. So if "foo" is a string for which each
character can fit in one byte, you should rather put "foo" in a
std::string and convert it to a valid utf8 string using
Glib::locale_to_utf8() .

I hope this helps.

Cheers,

Dodji.

On 8/1/06, Maik Beckmann <maikbeckmann gmx de> wrote:
Hello!

This code

<code>
        #include <glibmm.h>
        #include <iostream>


        int main(int argc, char **argv) {

            Glib::ustring ustr ( "hää?" );

            try {

               Glib::locale_from_utf8(ustr);

            } catch (Glib::ConvertError& e) {
                std::cout << e.what() << std::endl;
            }

            return 0;
        }
</code>

produces
<output>
        Invalid byte sequence in conversion input
</output>

Is this the normal behavior of glibmm? If not, can some of you compile
it and give me response, please.


Thanks in advance, Maik


PS:
I'm using
        glib-2.12.1
        glibmm-2.11.3
on a gentoo-linux x86 maschine with this

        maik localhost ~ $ locale
        LANG=de_DE.utf8
        LC_CTYPE="de_DE.utf8"
        LC_NUMERIC="de_DE.utf8"
        LC_TIME="de_DE.utf8"
        LC_COLLATE="de_DE.utf8"
        LC_MONETARY="de_DE.utf8"
        LC_MESSAGES="de_DE.utf8"
        LC_PAPER="de_DE.utf8"
        LC_NAME="de_DE.utf8"
        LC_ADDRESS="de_DE.utf8"
        LC_TELEPHONE="de_DE.utf8"
        LC_MEASUREMENT="de_DE.utf8"
        LC_IDENTIFICATION="de_DE.utf8"
        LC_ALL=de_DE.utf8

locales.


_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list




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