Re: glib strings (fwd)
- From: Tim Janik <timj gtk org>
- To: Gtk+ Developers <gtk-devel-list gnome org>
- Cc: Dan Libby <danda epinions-inc com>
- Subject: Re: glib strings (fwd)
- Date: Mon, 14 Aug 2000 22:24:19 +0200 (CEST)
forwarded to gtk-devel-list since i didn't see dan's original
message come through and would like to encourage comments.
assuming dan is not on the list, it's probably a good idea
to Cc: him on replies.
---
ciaoTJ
---------- Forwarded message ----------
Date: Sun, 13 Aug 2000 19:19:12 -0700
From: Dan Libby <danda@epinions-inc.com>
To: gtk-devel-list@gnome.org
Cc: Tim Janik <timj@gtk.org>
Subject: Re: glib strings
Patches for GString attached (from 1.2.8). Apologies in advance for any
spacing weirdness. I don't normally use tabs.
Note, tests/string-test works with these patches, however I did not add
any tests for the new functions. Someone may want to do that.
If possible, please let me know if/when these have been merged in.
-dan
Tim Janik wrote:
> On Sun, 13 Aug 2000, Dan Libby wrote:
>
> > Hi Tim. I'm sending you this note because I saw your name in the
> > changelog most often associated with GString.
>
> thanks for your comments, you pointed out something that could really
> be optimized.
> please send the patches (Glib coding style, unified diff i.e. diff -u)
> to gtk-devel-list@gnome.org, so we can review your changes and maybe
> point out deficiencies, renames etc. or simply accept and apply it ;)
>
> > Let me know... thx.
> >
> > -dan
> >
>
> ---
> ciaoTJ
diff -u -r 1.2.8.orig/glib-1.2.8/glib.h glib-1.2.8/glib.h
--- 1.2.8.orig/glib-1.2.8/glib.h Thu Mar 23 18:34:01 2000
+++ glib-1.2.8/glib.h Sun Aug 13 19:01:56 2000
@@ -1612,6 +1612,11 @@
void g_string_chunk_free (GStringChunk *chunk);
gchar* g_string_chunk_insert (GStringChunk *chunk,
const gchar *string);
+gchar* g_string_chunk_insert_n (GStringChunk *chunk,
+ const gchar *string,
+ gint len);
+gchar* g_string_chunk_insert_g (GStringChunk *chunk,
+ const GString *string);
gchar* g_string_chunk_insert_const (GStringChunk *chunk,
const gchar *string);
@@ -1619,24 +1624,49 @@
/* Strings
*/
GString* g_string_new (const gchar *init);
+GString* g_string_new_n (const gchar *init,
+ gint len);
+GString* g_string_new_g (const GString *init);
GString* g_string_sized_new (guint dfl_size);
void g_string_free (GString *string,
gint free_segment);
GString* g_string_assign (GString *lval,
const gchar *rval);
+GString* g_string_assign_n (GString *lval,
+ const gchar *rval,
+ gint len);
+GString* g_string_assign_g (GString *lval,
+ const GString *rval);
GString* g_string_truncate (GString *string,
gint len);
GString* g_string_append (GString *string,
const gchar *val);
+GString* g_string_append_n (GString *string,
+ const gchar *val,
+ gint len);
+GString* g_string_append_g (GString *string,
+ const GString *val);
GString* g_string_append_c (GString *string,
gchar c);
GString* g_string_prepend (GString *string,
const gchar *val);
+GString* g_string_prepend_n (GString *string,
+ const gchar *val,
+ gint len);
+GString* g_string_prepend_g (GString *string,
+ const GString *val);
GString* g_string_prepend_c (GString *string,
gchar c);
GString* g_string_insert (GString *string,
gint pos,
const gchar *val);
+GString* g_string_insert_n (GString *string,
+ gint pos,
+ const gchar *val,
+ gint len);
+GString* g_string_insert_g (GString *string,
+ gint pos,
+ const GString *val);
GString* g_string_insert_c (GString *string,
gint pos,
gchar c);
Only in 1.2.8.orig/glib-1.2.8: glib.spec
Only in glib-1.2.8: glibconfig-sysdefs.h
Only in glib-1.2.8: glibconfig.h
diff -u -r 1.2.8.orig/glib-1.2.8/gstring.c glib-1.2.8/gstring.c
--- 1.2.8.orig/glib-1.2.8/gstring.c Fri May 19 02:41:07 2000
+++ glib-1.2.8/gstring.c Sun Aug 13 19:01:33 2000
@@ -125,11 +125,11 @@
}
gchar*
-g_string_chunk_insert (GStringChunk *fchunk,
- const gchar *string)
+g_string_chunk_insert_n (GStringChunk *fchunk,
+ const gchar *string,
+ gint len)
{
GRealStringChunk *chunk = (GRealStringChunk*) fchunk;
- gint len = strlen (string);
char* pos;
g_return_val_if_fail (chunk != NULL, NULL);
@@ -158,6 +158,25 @@
}
gchar*
+g_string_chunk_insert (GStringChunk *fchunk,
+ const gchar *string)
+{
+ gint len;
+
+ len = strlen(string);
+
+ return g_string_chunk_insert_n(fchunk, string, len);
+}
+
+gchar*
+g_string_chunk_insert_g (GStringChunk *fchunk,
+ const GString *string)
+{
+ return g_string_chunk_insert_n(fchunk, string->str, string->len);
+}
+
+
+gchar*
g_string_chunk_insert_const (GStringChunk *fchunk,
const gchar *string)
{
@@ -228,18 +247,35 @@
}
GString*
-g_string_new (const gchar *init)
+g_string_new_n (const gchar *init,
+ gint len)
{
GString *string;
string = g_string_sized_new (2);
if (init)
- g_string_append (string, init);
+ g_string_append_n (string, init, len);
return string;
}
+GString*
+g_string_new (const gchar *init)
+{
+ gint len;
+
+ len = strlen(init);
+
+ return g_string_new_n (init, len);
+}
+
+GString*
+g_string_new_g (const GString *init)
+{
+ return g_string_new_n (init->str, init->len);
+}
+
void
g_string_free (GString *string,
gint free_segment)
@@ -255,19 +291,40 @@
}
GString*
-g_string_assign (GString *lval,
- const gchar *rval)
+g_string_assign_n (GString *lval,
+ const gchar *rval,
+ gint len)
{
g_return_val_if_fail (lval != NULL, NULL);
g_return_val_if_fail (rval != NULL, NULL);
g_string_truncate (lval, 0);
- g_string_append (lval, rval);
+ g_string_append_n (lval, rval, len);
return lval;
}
GString*
+g_string_assign (GString *lval,
+ const gchar *rval)
+{
+ gint len;
+
+ len = strlen (rval);
+
+ return g_string_assign_n (lval, rval, len);
+}
+
+GString*
+g_string_assign_g (GString *lval,
+ const GString *rval)
+{
+ return g_string_assign_n (lval, rval->str, rval->len);
+}
+
+
+
+GString*
g_string_truncate (GString* fstring,
gint len)
{
@@ -284,16 +341,15 @@
}
GString*
-g_string_append (GString *fstring,
- const gchar *val)
+g_string_append_n (GString *fstring,
+ const gchar *val,
+ gint len)
{
GRealString *string = (GRealString*)fstring;
- int len;
g_return_val_if_fail (string != NULL, NULL);
g_return_val_if_fail (val != NULL, fstring);
- len = strlen (val);
g_string_maybe_expand (string, len);
strcpy (string->str + string->len, val);
@@ -304,6 +360,24 @@
}
GString*
+g_string_append (GString *fstring,
+ const gchar *val)
+{
+ gint len;
+
+ len = strlen (val);
+
+ return g_string_append_n(fstring, val, len);
+}
+
+GString*
+g_string_append_g (GString *fstring,
+ const GString *val)
+{
+ return g_string_append_n(fstring, val->str, val->len);
+}
+
+GString*
g_string_append_c (GString *fstring,
gchar c)
{
@@ -319,16 +393,15 @@
}
GString*
-g_string_prepend (GString *fstring,
- const gchar *val)
+g_string_prepend_n (GString *fstring,
+ const gchar *val,
+ gint len)
{
GRealString *string = (GRealString*)fstring;
- gint len;
g_return_val_if_fail (string != NULL, NULL);
g_return_val_if_fail (val != NULL, fstring);
- len = strlen (val);
g_string_maybe_expand (string, len);
g_memmove (string->str + len, string->str, string->len);
@@ -343,6 +416,24 @@
}
GString*
+g_string_prepend (GString *fstring,
+ const gchar *val)
+{
+ gint len;
+
+ len = strlen(val);
+
+ return g_string_prepend_n(fstring, val, len);
+}
+
+GString*
+g_string_prepend_g (GString *fstring,
+ const GString *val)
+{
+ return g_string_prepend_n(fstring, val->str, val->len);
+}
+
+GString*
g_string_prepend_c (GString *fstring,
gchar c)
{
@@ -363,19 +454,18 @@
}
GString*
-g_string_insert (GString *fstring,
- gint pos,
- const gchar *val)
+g_string_insert_n (GString *fstring,
+ gint pos,
+ const gchar *val,
+ gint len)
{
GRealString *string = (GRealString*)fstring;
- gint len;
g_return_val_if_fail (string != NULL, NULL);
g_return_val_if_fail (val != NULL, fstring);
g_return_val_if_fail (pos >= 0, fstring);
g_return_val_if_fail (pos <= string->len, fstring);
- len = strlen (val);
g_string_maybe_expand (string, len);
g_memmove (string->str + pos + len, string->str + pos, string->len - pos);
@@ -387,6 +477,26 @@
string->str[string->len] = 0;
return fstring;
+}
+
+GString*
+g_string_insert (GString *fstring,
+ gint pos,
+ const gchar *val)
+{
+ gint len;
+
+ len = strlen(val);
+
+ return g_string_insert_n(fstring, pos, val, len);
+}
+
+GString*
+g_string_insert_g (GString *fstring,
+ gint pos,
+ const GString *val)
+{
+ return g_string_insert_n(fstring, pos, val->str, val->len);
}
GString *
Only in glib-1.2.8: stamp-gc-h
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]