Re: Rationale for change in behavior of g_strsplit when passed empty string?



On Wed, Jul 18, 2001 at 04:33:17PM -0400, Owen Taylor wrote:
> 
> Joel Becker <jlbec evilplan org> writes:
> 
> > if ((strv == NULL) || (strv[0] == NULL))
> > 
> > 	as a method to check if the split was on an empty string.
> 
> Wait ... unless you have no idea whether you are using GLib-1.2 or
> GLib-1.3, the || makes no sense. In either case it is deterministic.

	How do you mean?  Under glib 1.2, strsplit can return NULL or 
{NULL}.  Granted, I should know that my passed string is non-null, but
it is a sanity check.  The day I assume that strsplit returned non-NULL,
it'd return NULL and segfault :-)
	Under the glib 1.3 behavior, this *is* a useless check.  It
should instead check strv[0][0] and strv[1] as mentioned below.
 
> OK, I'm lost. If I wanted to check if the string I was splitting was ":",
> I think I'd use strcmp (string, ":") == 0   ;-)

	For that particular example, I have something along the line of
':' delimited input.  It may be "foo:bar", it may be ":bar", whatever.
":" being an emtpy case, but valid, whereas "" is invalid input.
	I guess your recommendation is that my code check for ":" and ""
before calling strsplit.  I guess that would work, just have another
level of indentation.
	Anyway, I was just mentioning that the change modifies behavior
in a way that will break some folks, and I could not see a benefit.  I
suspect I'll just wait till it bites me :-)

Joel

-- 

"Reader, suppose you were and idiot.  And suppose you were a member of
 Congress.  But I repeat myself."
	- Mark Twain

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




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