Re: wstring to ustring conversion
- From: Chris Vine <chris cvine freeserve co uk>
- To: gtkmm-list gnome org
- Cc:
- Subject: Re: wstring to ustring conversion
- Date: Fri, 22 Apr 2005 00:45:10 +0100
On Thursday 21 April 2005 23:13, Emre Turkay wrote:
> Greetings,
>
> I need to convert std::wstring into glib::ustring. It seems that
> conversion from/to std::string is included in the ustring and the way
> is pretty straight forward, however I couldn't figure out the *correct
> way* to make the conversion from wstring.
>
> I've been looking into the ustring source code, but it is really
> overwhelming for a guy who doesn't know anything about the
> internationalization and character code stuff ;)
>
> I think, for now I'll go and just write a one by one copy function and
> use it, however I would like to work on a better solution in the long
> term. Can you guys give me a pointer for information about it, well
> ustring compared to wstring would be the best.
That depends on the encoding in your std::wstring, and the character size.
(I do not use Windows but I think that that used to use 16 bit wide
characters, which were neither utf16 nor ucs4 but comprised that part of the
ucs4 character set reproducible as a single 16-bit character, but that may
now have changed.) Glib has various conversion functions you could use, not
all of which are in glibmm, including g_utf8_to_utf16(),
g_utf8_to_ucs4(), and vice versa. See
http://developer.gnome.org/doc/API/2.0/glib/glib-Unicode-Manipulation.html
You can use these to make a conversion functor for std::transform and then
iterate through the source and target strings, but you would need to handle
conversion errors.
If you wanted to be clever you could also implement std::codecvt stream code
conversion facets using the Glib functions.
You will not get anywhere with this without learning something about
internationalisation and character codes.
Chris.
--
Summer is y-cumen in, lhude sing, cuccu!
Groweth sed and bloweth med, springeth the wude nu.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]