Re: Some new GString functions - constructors
- From: Owen Taylor <otaylor redhat com>
- To: Paul LeoNerd Evans <leonerd leonerd org uk>
- Cc: gtk-devel-list gnome org
- Subject: Re: Some new GString functions - constructors
- Date: Tue, 20 Dec 2005 19:09:35 -0500
On Tue, 2005-12-20 at 23:48 +0000, Paul LeoNerd Evans wrote:
> That said, I don't see why we need a new split function, on reflection.
> Maybe a:
>
> GString** g_string_new_strv(gchar** a);
>
> would be useful; it would return a NULL-terminated array of new
> GString*s, each one wrapping a string from the original array. Thus, to
> form a GString** one could
>
> gchar** sv = g_strsplit(original_string->str, delim);
> GString** gsv = g_string_new_strv(sv);
> g_strfreev(sv);
>
> So easily providing what I intended for g_string_split(), but being less
> added code, and more useful.
What I don't understand is why you want to end up with a list or array
of GString.
gchar **names = g_strsplit(namelist, ",");
gchar **p;
for (p = names; *p; p++) {
GString *praise = g_string_new(*p);
g_string_append(praise, " is a great person);
g_printf("%s", praise->str);
g_string_free(praise);
}
g_strfreev(names);
Or whatever. If I *really* want a GList of GString, then:
gchar **names = g_strsplit(namelist, ",");
gchar **p;
GList *l = NULL;
for (p = names; *p; p++)
g_list_prepend(l, g_string_new(*p));
g_strfreev(names);
return g_list_reverse(l);
Isn't a lot of code; if it was a common operation, then sure
I'd get annoyed writing it over and over again. But unless you are
using GString as your string type (which I think is wrong), it
strikes me as quite rare.
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]