Re: patch to change behavior of g_strsplit on empty string back to 1.2 behavior



On Wed, Jul 18, 2001 at 05:33:03PM -0400, Owen Taylor wrote:
> > On Wednesday, July 18, 2001, at 02:12  PM, Owen Taylor wrote:
> > 
> > > The code in GLib stable didn't do that either, however, what it
> > > produced was
> > >
> > >   "w,x,y,z", ",", 2 => "w" "x" "y,z"
> > 
> > After re-reading it, I think this matches what the docs say.

	AFAICT, stable behaved like perl.  If it doesn't, I'm amazed I
haven't seen bugs.  I've been using it like perl for the longest time.

> I actually know of no decent reason to use max_tokens, and would
> guess that the vast majority of all cases use 0 or -1, so it may
> be fairly academic.

	I use max_tokens all the time.  On common usage is to parse the
shell expression "FOO=bar=baz".  Properly, you g_strsplit("FOO=bar=baz",
"=", 2); and get {"FOO", "bar=baz"}.  This is the same for any
expression where the defined syntax is
<non-delimiter><delimiter><any_text_including_delimiter_to_eol>.  Sure,
I could write a simple function myself, but the point of glib is to not
do that, and "gchar **var = g_strsplit(line, delim, 2);" is very nice.
	Do you consider that a bad reason?  The other solution I can
think of is to use strchr and strdup, which is more code and would
likely become a helper function.  And once you get more than 2 elements
(foo:bar:to the end of line), it becomes a helper function that emulates
perl's split.

Joel

-- 

Life's Little Instruction Book #511

	"Call your mother."

			http://www.jlbec.org/
			jlbec evilplan org




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]