Re: Proper handling of unicode strings



On Mon, 7 Jul 2008 12:01:36 +0200
"Milosz Derezynski" <internalerror gmail com> wrote:

> It's "safe" in the aforementioned sense, but if you want to properly
> count characters in the UTF-8 string, you should use g_utf8_strlen()
> instead.
> 
> 2008/7/7 LCID Fire <lcid-fire gmx net>:
> 
> > That's great - simplifies a lot of things. But since one character
> > might need more space than a gchar is it save to call strlen on
> > that string?

It is not just "safe" in the sense described above, but required if you
need to know the byte length (say to allocate storage on the heap).

If you need to know the byte length use strlen().  If you need to know
the number of characters (which will be rare, unless you are thinking of
converting say to UCS-4), then use g_utf8_strlen().  If you want to
iterate over the string then g_utf8_next_char() is handy.

Chris



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