Re: glib utf8 api

On Tue, 2008-03-04 at 16:24 -0800, Gregory Sharp wrote:
> Thanks so much Owen and Bedhad for your response.
> > > 1) There seems to be no good way to strncpy a utf8 string 
> > > into a fixed buffer.  g_strncpy doesn't work, because the 
> > > last character can get truncated causing an invalid string. 
> > 
> > > g_utf8_strncpy doesn't work either, because I don't know 
> > > how many characters fit in the buffer.
> > 
> > Doesn't strike me as a useful operation. Easy enough to write
> > yourself with
> > g_utf8_get_char()/next_char()/g_unichar_to_utf8().
> May I try to convince you that it is useful?  For good or 
> evil, it is still common to copy strings into fixed length
> buffers.  That is why functions like strncpy exist in 
> the standard C library.  It is not expected that everyone 
> write his own strncpy, even though it is easy, because we 
> all benefit from using the copy in the library.

Behdad certainly has a lot more influence than I do about what goes into
GLib these days ... he actually commits things! So, convincing me isn't
really necessary.

We generally have discouraged people from using fixed sized buffers..
GString,g_strdup_printf(), g_strconcat(), 
g_markup_printf_escaped(), etc. are generally a much more robust, more
convenient and safer ways to build strings. 

Other than that, I can only offer that I've never felt that I needed a
"truncate Unicode string 'cleanly' at N bytes' operation. (Noting that
even if you preserve character boundaries you might strip accents, break
 up clusters, etc.) And I've never seen it in anybody else's GLib code
either. So, it clearly isn't an essential operation. But could it be
occasionally useful? Sure. As could hundreds of other functions.

- Owen

Attachment: signature.asc
Description: This is a digitally signed message part

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