Re: std::cout << Glib::ustring(utf8_literal) throws exception



Indeed. The magic for setlocale on Windows escapes me (btw, it was supposed to be setlocale(LC_ALL,""), not setlocale(LC_ALL,0)). According to MSDN the *only* things you can't set through setlocale are UTF-8 and UTF-7. Wonderful...

Milosz Derezynski wrote:
Then i guess you would somehow need to set an UTF-8 locale (setting LC_ALL to 0 you set the C or (i think) ANSI X3.4-1986 locale).

2008/7/13 Sohail Somani <sohail taggedtype net <mailto:sohail taggedtype net>>:

    Yes, you are right. Copying the ustring to a std::string gets rid of
    the error but still doesn't work right because it is interpreted as
    ASCII in the console.

    Milosz Derezynski wrote:

        It should be noted here that Glib::ustring::operator<< performs
        a conversion from UTF-8 to the currenty set locale (yeah it's
        weird and unexpected) and thus works intransparent and produces
        sideeffects; i don't know the implication of this on Windows but
        i'm willing to be that that's the reason for your problem here.
        You could try copying the ustring to an std::string before using
        << and then feed the std::string to cout.

        2008/7/13 Sohail Somani <sohail taggedtype net
        <mailto:sohail taggedtype net> <mailto:sohail taggedtype net
        <mailto:sohail taggedtype net>>>:


           Hi,

           The following code works fine on Linux but dies on Windows
        when run
           in the console:

           #include <gtkmm.h>

           int main()
           {
            setlocale(LC_ALL,0);
            // Should output aleph
            std::cout << Glib::ustring("\xd7\x90") << std::endl
           }

           The error is: "Invalid byte sequence in conversion input"

           Has anyone tried UTF-8 with Glib on Windows? What else do I
        need to do?

           Thanks,

           Sohail


--
Sohail Somani
http://uint32t.blogspot.com


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