commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@btopenworld.com
Subject Re: [lang] StringUtils.sliceFirstRemainder behavior
Date Wed, 23 Jul 2003 14:59:10 GMT
>  from:    Phil Steitz <phil@steitz.com>
> I assume you also agree that all slice functions should fix "", null, i.e.,
> 
> slice[Xxx](null, *) = null,
> slice[Xxx]("", *) = ""
Yes, these seem like the simple cases.

Stephen


> Phil
> 
> > 
> > 2.0 waits until we sort this....
> > 
> > Stephen
> > 
> > 
> >> from:    Phil Steitz <phil@steitz.com>
> >>s null (all slices return null)
> >>s empty (all slices return "")
> >>s nontrivial, x nontrivial, s contains x (natural definitions)
> >>s nontrivial, x nontrivial, s does not contain x (there is no first or
> >>last occurrence, so "all characters before the first occurrence" = s and 
> >>"all characters after the last occurrence" = "")
> > 
> > ("abc", "z") 
> > - slice = "abc"
> > - sliceRemainder = ""
> > - sliceFirst = "abc"
> > - sliceFirstRemainder = ""
> > 
> > 
> >>s nontrivial, x null (s does not contain x, so same as previous)
> >>
> >>s nontrivial, x empty (s occurs both at the beginning of x and at the 
> >>end of x, so "all characters before the first occurrence" = "" =
> >>"all characters after the last occurrencce")
> >>
> >>Sorry to open up this can of worms just now.  Bad timing, but good to 
> >>get it out on the table. I will provide a patch to make and document the 
> >>changes above if we want to go this route.
> >>
> >>One important disclaimer: I never bonded with Perl and I have no idea 
> >>how closely the above defs would match Perl behavior.
> >>
> >>Phil
> >>
> >>
> >>
> >>>Whether this should still hold though now, I don't know. Although I felt
> >>>that chomp getChomp should = s, I always found it made getChomp a bit
> >>>painful to use as it returned the delimiter itself. I think I was overly
> >>>impressed with the symmetry.
> >>>
> >>>Hen
> >>>
> >>>
> >>>On Wed, 23 Jul 2003, Stephen Colebourne wrote:
> >>>
> >>>
> >>>
> >>>>OK, the current behaviour seems daft to me. Can anyone explain why this
is
> >>>>as it is?
> >>>>
> >>>>StringUtils.sliceFirst("abc", "") = "abc"
> >>>>StringUtils.sliceFirst("abc", "d") = ""
> >>>>
> >>>>StringUtils.sliceFirstRemainder("abc", "") = ""
> >>>>StringUtils.sliceFirstRemainder("abc", "d") = "abc"
> >>>>
> >>>>I would expect the exact opposite:
> >>>>StringUtils.sliceFirst("abc", "") = ""
> >>>>StringUtils.sliceFirst("abc", "d") = "abc"
> >>>>
> >>>>StringUtils.sliceFirstRemainder("abc", "") = "abc"
> >>>>StringUtils.sliceFirstRemainder("abc", "d") = ""
> >>>>
> >>>>
> >>>>I would expect slice first to return the text before the first separator.
An
> >>>>empty string is found at position zero, so it should return "". Separator
> >>>>"d" is not found, so everything before it is the whole string.
> >>>>
> >>>>I'd like to change this, but why is it as it is???
> >>>>
> >>>>Stephen
> >>>>
> >>>>----- Original Message -----
> >>>>From: "Phil Steitz" <phil@steitz.com>
> >>>>To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>
> >>>>Sent: Tuesday, July 22, 2003 3:30 PM
> >>>>Subject: Re: [lang] StringUtils.sliceFirstRemainder behavior
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>>Stephen Colebourne wrote:
> >>>>>
> >>>>>
> >>>>>>I think I would expect:
> >>>>>>
> >>>>>>StringUtils.slice("foo", "b") = "foo"
> >>>>>>"get everything before the last 'b'"
> >>>>>>
> >>>>>>StringUtils.sliceRemainder("foo", "b") = ""
> >>>>>>"get everything after the last 'b'"
> >>>>>>
> >>>>>>StringUtils.sliceFirst("foo", "b") = ""
> >>>>>>"get everything before the first 'b'"
> >>>>>>
> >>>>>>StringUtils.sliceFirstRemainder("foo", "b") = "foo"
> >>>>>>"get everything after the first 'b'"
> >>>>>>
> >>>>>>slice and sliceRemainder are opposite.
> >>>>>>The results would be the same for a blank separator.
> >>>>>>
> >>>>>>But then I don't use Perl which is where I think these came from.
> >>>>>>So wait to see if you get any more answers!
> >>>>>>
> >>>>>>Stephen
> >>>>>>
> >>>>>
> >>>>>I just submitted a patch here
> >>>>>
> >>>>>http://issues.apache.org/bugzilla/show_bug.cgi?id=21797
> >>>>>
> >>>>>that documents current behavior with examples and test cases.
> >>>>>
> >>>>>Phil
> >>>>>
> >>>>>
> >>>>>
> >>>>>>----- Original Message -----
> >>>>>>From: "Phil Steitz" <phil@steitz.com>
> >>>>>>To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>
> >>>>>>Sent: Tuesday, July 22, 2003 5:50 AM
> >>>>>>Subject: [lang] StringUtils.sliceFirstRemainder behavior
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>>Currently,
> >>>>>>>
> >>>>>>>StringUtils.sliceRemainder("foo", "b") = ""
> >>>>>>>= StringUtils.sliceFirst("foo", "b"),
> >>>>>>>
> >>>>>>>but StringUtils.sliceRemainder("foo", "b") = "foo".
> >>>>>>>
> >>>>>>>Is this the intended behavior?
> >>>>>>>
> >>>>>>>Phil
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>---------------------------------------------------------------------
> >>>>>>>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> >>>>>>>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >>>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>---------------------------------------------------------------------
> >>>>>>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> >>>>>>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >>>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>---------------------------------------------------------------------
> >>>>>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> >>>>>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >>>>>
> >>>>
> >>>>
> >>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> >>>>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >>>>
> >>>
> >>>
> >>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> >>>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >>>
> >>
> >>
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >>
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> > 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message