commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Graham" <>
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.


>From: Alex Chaffee / Purple Technology <>
>To: Jakarta Commons Developers List <>
>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?
>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                     
>Purple Technology - Code and Consulting
>jGuru - Java News and FAQs       
>Gamelan - the Original Java site 
>Stinky - Art and Angst           
>To unsubscribe, e-mail:
>For additional commands, e-mail:

Tired of spam? Get advanced junk mail protection with MSN 8.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message