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. > 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 _______________________________________________ gtkmm-list mailing list gtkmm-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtkmm-list