Fwd: wide char string literals to Glib ustring
- From: "Onur Tugcu" <onur tugcu gmail com>
- To: gtkmm-list gnome org
- Subject: Fwd: wide char string literals to Glib ustring
- Date: Sat, 8 Dec 2007 12:24:41 -0500
---------- Forwarded message ----------
From: Onur Tugcu <onur tugcu gmail com>
Date: Dec 8, 2007 12:22 PM
Subject: Re: wide char string literals to Glib ustring
To: Armin Burgmeier <armin arbur net>
On Dec 8, 2007 7:43 AM, Armin Burgmeier <armin arbur net> wrote:
>
> On Sat, 2007-12-08 at 07:03 -0500, Onur Tugcu wrote:
> > Hi,
> > I'm writing my strings hardcoded into the program, so I want to make
> > use of string literals in C++.
>
> I think the easiest thing to do is not to use wchar_t at all but
> directly encode the string literals in UTF-8.
>
To me, easiest would be to be able to write unicode directly
into code and to not worry about the codes. Also, I imagine
multi-byte glyphs will suffer from endianness.
>
> > When I use gtkmm with vc++ 2005, sizeof(wchar_t) is 2.
> > So I assumed utf-16 encoding and wrote:
> >
> > Glib::ustring w2ustring(std::wstring const &w)
> > {
> > gunichar2 const* utf16= reinterpret_cast<gunichar2 const*>(w.c_str());
> > gchar* utf8= g_utf16_to_utf8(utf16, -1, 0, 0, 0);
> > Glib::ustring u(utf8); g_free(utf8);
> > return u;
> > }
> >
> > Which seems to work great like
> > Glib::ustring u(w2ustring(L"üö"));
> >
> > But on linux with a unicode terminal,
> >
> > I can just set
> > std::locale::global(std::locale("en_US.UTF-8"));
> > Glib::ustring u(Glib::locale_to_utf8("üö"));
> >
> > And the code up there doesn't work (wchar_t is actually 4 bytes)
> > And even the ucs4 output warnings and the resulting ustring is garbage
> > or I get a segfault.
> > So no utf16 to utf8 or ucs4 to utf8 conversions.
> >
> > Shall I use two separate codes for these platforms?
> > Is there a unified solution?
>
> Armin
>
>
Another vaguely related issue: on vc++ 2005 express
#include <iostream>
#include <ostream>
#include <gtkmm.h>
int main()
{
std::cout<< "test"<< std::endl;
}
// crashes!
I set up a vanilla project and used the MSVC/gtkmm-2.4d.vsprops
in Debug mode. Removing #include <gtkmm.h> will of course make it not crash.
I don't know what in gtkmm.h results in the crash, including headers
individually
hasn't caused me this problem before.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]