commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Graham" <dgraham1...@hotmail.com>
Subject Re: [lang] chop and chomp
Date Wed, 05 Mar 2003 20:54:57 GMT
I agree that chomp and chop should behave exactly as Perl's functions do.  
It's confusing to name methods after Perl functions and then not mirror 
their functionality exactly.

David



>From: Alex Chaffee / Purple Technology <guru@stinky.com>
>Reply-To: alex@jguru.com
>To: Jakarta Commons Developers List <commons-dev@jakarta.apache.org>
>CC: alex@jguru.com
>Subject: [lang] chop and chomp
>Date: Wed, 5 Mar 2003 12:36:35 -0800
>
>On Wed, Mar 05, 2003 at 02:02:17PM -0500, Henri Yandell wrote:
> >
> > > * chomp() and chop() have slightly (but significantly!) different
> > >   semantics than in Perl.  It would be great if StringUtils behaved in
> > >   line with expectations.
> >
> > Yeah, they evolved after I copied them from the php description [having
> > liked them previously in perl].
> >
> > I'm a bit too close to the StringUtils versions now though, care to
> > highlight the differences?
>
>Perl:
>
>chop removes the final character, no matter what it is
>
>chomp removes the final character if and only if it's a newline
>(or, technically, the $INPUT_RECORD_SEPARATOR).
>
>
>Current StringUtils:
>
>chop removes the final character, no matter what it is, and glomming
>\r\n as if it were a single character
>
>chopNewline removes the final character if and only if it's a newline
>(glomming \r\n) -- behaving like Perl chomp
>
>chomp removes the last newline *and all succeeding characters*
>(i.e. the last unterminated line)
>
>chompLast removes the last character if and only if it's a newline
>(glomming \r\n) -- This is redundant with chopNewline, and matches
>Perl chomp
>
>getChomp - since Henri's chomp might delete more than just the
>separator, this returns the portion that got deleted
>
>
>My advice is that Henri's chomp is dangerous, since in Perl chomp is
>quite safe, and just prepares a string by removing potential spurious
>newlines without changing the content at all.
>
>I'd suggest that you consider removing or renaming chomp, chompLast,
>and getChomp, and renaming chopNewline to chomp for Perl
>compatibility.  Maybe we can do a poll and find out if anyone's
>actually using them?
>
>
>--
>Alex Chaffee                               mailto:alex@jguru.com
>Purple Technology - Code and Consulting    http://www.purpletech.com/
>jGuru - Java News and FAQs                 http://www.jguru.com/alex/
>Gamelan - the Original Java site           http://www.gamelan.com/
>Stinky - Art and Angst                     http://www.stinky.com/
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-dev-help@jakarta.apache.org


_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail


---------------------------------------------------------------------
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