Re: Using Glib::ustring with std::wstring



On Monday 20 February 2006 18:41, Loïc Joly wrote:
> Hello everybody,
>
> I'm starting to use LibXml++ for a new project, and in this context, I'd
> like to convert from std::wstring  to Glib::ustring and the other way
> around.
>
> I can see some convertion functions with std::string, but not with
> std::wstring. Am I missing something ?

std::wstring (and wchar_t) are types, not codesets.  (As you refer to 
Glib::ustring, the narrow character codeset that you have in mind is 
presumably UTF-8).

If sizeof wchar_t is 4 and you are interested in UCS-4/UTF-32, glib has 
g_utf8_to_ucs4() and g_utf8_to_ucs4_fast() which will do what you want.  
(Note however that you will need to free the return values of these after 
loading them into your std::wstring object.)  If you are using windows you 
will probably want to use g_utf8_to_utf16().

For the reverse there is g_ucs4_to_utf8() (and g_unichar_to_utf8()) and 
g_utf16_to_utf8().

Chris




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