Re: Behaviour of g_utf8_to_utf16



On Tue, Jun 19, 2012 at 10:28:56PM +0100, Weeble wrote:
> As far as I can tell by experimentation, g_utf8_to_utf16 always stops
> at the first nul in a string, even when a positive value is passed for
> the len argument. If I have a UTF8 string with embedded nuls (of known
> length, of course), is there a good way to convert it to UTF16 with
> GLib?

I would just write a wrapper around g_utf8_to_utf16() that would use it
in a cycle until the full length is reached and handle the nul characters.

> I thought at first that passing a positive len would have this
> effect because I read "If len < 0, then the string is nul-terminated"

The string is terminated by a nul character or explicit length,
whichever comes *first* – this is the standard behaviour of all libc and
glib string functions.  Passing len < 0 simply means that the second
condition never realises.

Yeti



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