Web lists-archives.com

Re: G_UTF8String: Boxed Type Proposal




Just to add my two cents worth as a user of glibmm.

Glib::usting uses g_utf8_pointer_to_offset() to obtain the length of
the string in characters in the method Glib::ustring::length. The
method Glib::ustring::bytes returns the length in bytes;

At no point does it store the number of UTF-8 characters as this would
be inefficient.

For simple string manipulation like inserting a string or character or
concatenating would require extra work to be done. The string needs to
be checked that it is still valid UTF-8 before the length is updated.
The next issue is what to do when the string becomes invalid UTF-8.
Doing this for every string operation will have a performance
implication. Imagine doing this in a loop inserting a byte from a
stream!

Checking at the end of all the operations or handing it over to GTK to
deal with the problems will be more efficient and less of a headache.

On Fri, 2016-03-18 at 10:19 -0400, Randall Sawyer wrote:
> On 03/18/2016 10:10 AM, Florian Müllner wrote:
> > On Fri, Mar 18, 2016 at 2:57 PM Randall Sawyer <srandallsawyer@hush
> > mail.me> wrote:
> > > how about the following modifications?
> > > Change "gstring.h":
> > > ...
> > > struct _GString
> > > {
> > >    gchar  *str;
> > >    gsize len;
> > >    gsize allocated_len;
> > >    gsize utf8_len;
> > > };
> > > ...
> > > 
> >  Changing the size of a public struct is an ABI break, so this is
> > not an option for glib-2.x.
>  
> So, does that answer question 4?
> 
> Also - I just discovered that glibmm has a class Glib::ustring (https
> ://developer.gnome.org/glibmm/stable/classGlib_1_1ustring.html). I am
> going to take a look through its source to see what they have there.
> 
> _______________________________________________
> gtk-devel-list mailing list
> gtk-devel-list@xxxxxxxxx
> https://mail.gnome.org/mailman/listinfo/gtk-devel-list
_______________________________________________
gtk-devel-list mailing list
gtk-devel-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-devel-list