You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Verneri Åberg <ve...@gmail.com> on 2011/08/24 08:02:23 UTC

[lang]Question about StringUtils chomp and removeEnd

Hi all,

I was just browsing through StringUtils Api (versions 2.5, 2.6 and
3.0.1) and found two very similar looking methods

chomp(String,String)
and
removeEnd(String, String)

So I started to wonder what is the difference here and looked at the
source code.

To my astonishment the only difference is that chomp returns the source
string immediately if the removed string is null and remove end
additionally checks for empty strings too.

So wouldn't it be better to substitute the duplication by simply
replacing the chomp method with following version?

public String chomp(String source, String separator) {
	return removeEnd(source,separator);
}

Or is there some hidden idea for two different implementations of the
same string chompping function? if there is maybe it should be added to
both methods javadocs?

 Verneri


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


Re: [lang]Question about StringUtils chomp and removeEnd

Posted by Henri Yandell <fl...@gmail.com>.
This is committed (r1161997 + LANG-748).

Thanks again Verneri.

Hen

On Thu, Aug 25, 2011 at 8:30 AM, Henri Yandell <fl...@gmail.com> wrote:
> Agreed :) Nice catch.
>
> I'll also deprecate the chomp(String,String) version for removal in 4.0.
>
> Hen
>
> On Tue, Aug 23, 2011 at 11:02 PM, Verneri Åberg <ve...@gmail.com> wrote:
>> Hi all,
>>
>> I was just browsing through StringUtils Api (versions 2.5, 2.6 and
>> 3.0.1) and found two very similar looking methods
>>
>> chomp(String,String)
>> and
>> removeEnd(String, String)
>>
>> So I started to wonder what is the difference here and looked at the
>> source code.
>>
>> To my astonishment the only difference is that chomp returns the source
>> string immediately if the removed string is null and remove end
>> additionally checks for empty strings too.
>>
>> So wouldn't it be better to substitute the duplication by simply
>> replacing the chomp method with following version?
>>
>> public String chomp(String source, String separator) {
>>        return removeEnd(source,separator);
>> }
>>
>> Or is there some hidden idea for two different implementations of the
>> same string chompping function? if there is maybe it should be added to
>> both methods javadocs?
>>
>>  Verneri
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>

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


Re: [lang]Question about StringUtils chomp and removeEnd

Posted by Henri Yandell <fl...@gmail.com>.
Agreed :) Nice catch.

I'll also deprecate the chomp(String,String) version for removal in 4.0.

Hen

On Tue, Aug 23, 2011 at 11:02 PM, Verneri Åberg <ve...@gmail.com> wrote:
> Hi all,
>
> I was just browsing through StringUtils Api (versions 2.5, 2.6 and
> 3.0.1) and found two very similar looking methods
>
> chomp(String,String)
> and
> removeEnd(String, String)
>
> So I started to wonder what is the difference here and looked at the
> source code.
>
> To my astonishment the only difference is that chomp returns the source
> string immediately if the removed string is null and remove end
> additionally checks for empty strings too.
>
> So wouldn't it be better to substitute the duplication by simply
> replacing the chomp method with following version?
>
> public String chomp(String source, String separator) {
>        return removeEnd(source,separator);
> }
>
> Or is there some hidden idea for two different implementations of the
> same string chompping function? if there is maybe it should be added to
> both methods javadocs?
>
>  Verneri
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

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