Re: Some new GString functions - constructors

2005-12-21 Thread Paul LeoNerd Evans
On Tue, Dec 20, 2005 at 07:09:35PM -0500, Owen Taylor wrote: 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. Yes; that's

Some new GString functions - constructors

2005-12-20 Thread Paul LeoNerd Evans
As promised earlier, here's a patch with some new functions for GString. I'll split them up with related changes, so this is just the first of a sequence. There's 3 functions added here, g_string_clone, g_string_new_lenz, and g_string_slice. Each is a constructor, to return a new GString object.

Re: Some new GString functions - constructors

2005-12-20 Thread Emmanuele Bassi
Hi, On Tue, 2005-12-20 at 22:36 +, Paul LeoNerd Evans wrote: As promised earlier, here's a patch with some new functions for GString. I'll split them up with related changes, so this is just the first of a sequence. Can you please open a bug inside http://bugzilla.gnome.org and attach the

Re: Some new GString functions - constructors

2005-12-20 Thread Paul LeoNerd Evans
On Tue, Dec 20, 2005 at 02:43:43PM -0800, Alan M. Evans wrote: GStrings are already guaranteed to have a nul terminating byte, aren't they? Ah; yes, in fact, they are. I had thought they weren't, in the case of calling g_string_new_len(), because I tried it one time and found a bug. I'd just

Re: Some new GString functions - constructors

2005-12-20 Thread Paul LeoNerd Evans
On Wed, Dec 21, 2005 at 12:00:52AM +0100, Emmanuele Bassi wrote: Can you please open a bug inside http://bugzilla.gnome.org and attach the patch there? Tracking patches on Bugzilla makes things easier than on a mailing list. Shall do. Apart from g_string_new_lenz() which I don't understand,

Re: Some new GString functions - constructors

2005-12-20 Thread Alan M. Evans
On Tue, 2005-12-20 at 14:36, Paul LeoNerd Evans wrote: typedef GList GStringList; Not entirely certain I like this. See below. GStringList* g_string_split(GString *str, gchar c); Seems to me this should return a gchar** a-la g_strsplit(). Whether or not this is more useful may depend on

Re: Some new GString functions - constructors

2005-12-20 Thread Alan M. Evans
On Tue, 2005-12-20 at 15:18, Alan M. Evans wrote: On Tue, 2005-12-20 at 14:36, Paul LeoNerd Evans wrote: typedef GList GStringList; Not entirely certain I like this. See below. GStringList* g_string_split(GString *str, gchar c); Seems to me this should return a gchar** a-la

Re: Some new GString functions - constructors

2005-12-20 Thread Owen Taylor
At a high-level, I think there is a question of what GString is - should there be GString versions of everything you want to do with a char *? My opinion is no ... a GString is the equivalent of a Java StringBuffer .. it is a useful way to build and work with strings, but it isn't *a string*.

Re: Some new GString functions - constructors

2005-12-20 Thread Paul LeoNerd Evans
On Tue, Dec 20, 2005 at 03:26:45PM -0800, Alan M. Evans wrote: Not entirely certain I like this. See below. GStringList* g_string_split(GString *str, gchar c); Seems to me this should return a gchar** a-la g_strsplit(). I take that back. I can always use g_strsplit() on the

Re: Some new GString functions - constructors

2005-12-20 Thread Paul LeoNerd Evans
On Wed, Dec 21, 2005 at 12:33:23AM +0100, Emmanuele Bassi wrote: EIther way, you would have another type out: GStringList would be a G(S)List of GString; you would have to use: GSList *iter; /* or GList *iter; */ for (iter = stringlist; iter != NULL; iter = iter-next) do_something

Re: Some new GString functions - constructors

2005-12-20 Thread Paul LeoNerd Evans
On Tue, Dec 20, 2005 at 06:31:01PM -0500, Owen Taylor wrote: At a high-level, I think there is a question of what GString is - should there be GString versions of everything you want to do with a char *? My opinion is no ... a GString is the equivalent of a Java StringBuffer .. it is a

Naked GString operations [was: Re: Some new GString functions - constructors]

2005-12-20 Thread Paul LeoNerd Evans
(Appologies for the pun in the subject; I couldn't help myself.. :) ) On Tue, Dec 20, 2005 at 03:52:28PM -0800, Alan M. Evans wrote: void g_string_init(GString *str); void g_string_fini(GString *str); Which would do most of the work of g_string_new() and g_string_free()

Re: Some new GString functions - constructors

2005-12-20 Thread Owen Taylor
On Tue, 2005-12-20 at 23:48 +, 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

Re: Some new GString functions - constructors

2005-12-20 Thread Paul LeoNerd Evans
On Wed, Dec 21, 2005 at 01:19:59AM +0100, Øyvind Kolås wrote: At least in my sources, and where they draw inspiration from there is a larger precedence for the suffix _dup, rather than _clone. g_string_dup() also works, yes.. I'm not overly attached to the name. Thoughts anyone? -- Paul

Re: Naked GString operations [was: Re: Some new GString functions - constructors]

2005-12-20 Thread Paul LeoNerd Evans
On Wed, Dec 21, 2005 at 12:07:14AM +, Paul LeoNerd Evans wrote: void g_string_init(GString *str); void g_string_fini(GString *str); Actually, it occurs to me. If we wanted to give certain future guarantees about GString, we could do something like the following: #define