UTF-16 in gtkmm?

View: New views
4 Messages — Rating Filter:   Alert me  

UTF-16 in gtkmm?

by Andreas Volz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I like to read Unicode strings into my gtkmm application that are
written in UTF-16. There's only the glib::ustring class to handle
UTF-8. Is there a UTF-16 string class or a way to convert the UTF-16
string to UTF-8?

Then I need to write back my Unicode strings in UTF-16. I found the
docs about "Character Set Conversion"[1], but I don't see how they'll
help me.

[1]http://gtkmm.org/docs/glibmm-2.4/docs/reference/html/group__CharsetConv.html

regards
Andreas
_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: UTF-16 in gtkmm?

by Chris Vine :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, 2008-05-17 at 11:43 +0200, Andreas Volz wrote:

> Hello,
>
> I like to read Unicode strings into my gtkmm application that are
> written in UTF-16. There's only the glib::ustring class to handle
> UTF-8. Is there a UTF-16 string class or a way to convert the UTF-16
> string to UTF-8?
>
> Then I need to write back my Unicode strings in UTF-16. I found the
> docs about "Character Set Conversion"[1], but I don't see how they'll
> help me.

You can convert from UTF-16 to UTF-8 using g_utf16_to_utf8() (for which
purpose you will need to include glib/gunicode.h).  You will need to
call g_free() on the return value after putting it in a Glib::ustring
object.

You can go the other way with g_utf8_to_utf16().  It returns an array of
type gunichar2, which is typedef'ed to guint16, also requiring to be
g_free'd when you have finished with it.

Chris


_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: UTF-16 in gtkmm?

by Andreas Volz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Am Sat, 17 May 2008 12:40:30 +0100 schrieb Chris Vine:

> On Sat, 2008-05-17 at 11:43 +0200, Andreas Volz wrote:
> > Hello,
> >
> > I like to read Unicode strings into my gtkmm application that are
> > written in UTF-16. There's only the glib::ustring class to handle
> > UTF-8. Is there a UTF-16 string class or a way to convert the UTF-16
> > string to UTF-8?
> >
> > Then I need to write back my Unicode strings in UTF-16. I found the
> > docs about "Character Set Conversion"[1], but I don't see how
> > they'll help me.
>
> You can convert from UTF-16 to UTF-8 using g_utf16_to_utf8() (for
> which purpose you will need to include glib/gunicode.h).  You will
> need to call g_free() on the return value after putting it in a
> Glib::ustring object.
>
> You can go the other way with g_utf8_to_utf16().  It returns an array
> of type gunichar2, which is typedef'ed to guint16, also requiring to
> be g_free'd when you have finished with it.

Thanks, I'll try it. Any ideas why there's no glibmm wrapper for that?

regards
Andreas
_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: UTF-16 in gtkmm?

by Chris Vine :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, 2008-05-17 at 22:58 +0200, Andreas Volz wrote:

> Thanks, I'll try it. Any ideas why there's no glibmm wrapper for that?

I think it probably arises from the fact that the size of the character
used by std::wstring is not guaranteed by the standard, so a std::string
to std::wstring conversion would be system dependent.  In addition, it's
only really relevant to windows programmers, as UTF-8 interfaces are
becoming pretty well ubiquitous for unix-like systems.

Certainly, any sane new use of unicode these days would either employ
UTF-8 (multi-element representation with an element size of 1) or
UCS-4/UTF-32 (fixed size of 4).  UTF-16 is in the "worst of all possible
worlds" category.

Chris


_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list