Re: Proposed patch: Modify glib to permit embedded NULs in GString.
- From: Owen Taylor <otaylor redhat com>
 
- To: gtk-devel-list redhat com
 
- Subject: Re: Proposed patch: Modify glib to permit embedded NULs in GString.
 
- Date: 29 Jun 2000 16:13:35 -0400
 
I agree that since it isn't very hard to do, GString should
support embedded NULS. 
There is a question of how far to 
go with this - almost any string function could conceivably
have a variant that handles embedded \0. My opinion on this
is that we should stop here - most of the time when you have
a string with embedded \0 it is basically a data chunk.
But having this basic capability will be useful.
I've applied your patch with only a few changes:
> +  while (i) {
> +    if (*p != *q)
> +      return FALSE;
> +    p++;
> +    q++;
> +    i--;
> +  }
Indentation here needed to be fixed.
> --- glib.orig/testglib.c	Wed Mar  1 04:44:09 2000
> +++ glib/testglib.c	Tue Jun 27 12:30:31 2000
> @@ -795,7 +795,37 @@
>    g_string_insert_len (string1, 5, "last", -1);
>    g_assert (strcmp (string1->str, "firstlast") == 0);
>    g_string_free (string1, TRUE);
I've applied this change, but since the canonical location
for 
I've also added g_string_hash() to go along with g_string_equal(),
since these two functions are universally paired in GLib.
guint
g_string_hash (const GString *str)
{
  const gchar *p = str->str;
  gint n = str->len;
  guint h = 0;
  while (n--)
    {
      h = (h << 5) - h + *p;
      p++;
    }
  return h;
}
Regards,
                                        Owen
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]