You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Phil Steitz <ph...@steitz.com> on 2003/12/13 21:34:18 UTC
Re: [lang][PROPOSAL] How to best address Bug 25454
Gary Gregory wrote:
> Hello [lang],
>
> Reference: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25454
>
> Here is the pickle:
>
> CharSetUtils.translate(String,String,String) is deprecated in favor of
> StringUtils.replaceChars(String,String,String) but their behaviors are
> different.
>
> The choices as I see them are (compatibility issues noted are with lang
> /2.0/):
>
> (1) Make StringUtils.replaceChars exactly like CharSetUtils.translate.
> Pro: Backwards compatible with the Javadoc in CharSetUtils.translate.
> Con: Not Backwards compatible with the current StringUtils.replaceChars.
>
> (2) Do (1) and add a new function ("replaceChars2" for the sake of this
> description) in StringUtils to do what replaceChars does now.
> Pro: Backwards compatible with the Javadoc in CharSetUtils.translate.
> Pro: Backwards compatible with the current StringUtils.replaceChars, it has
> not changed.
> Con: StringUtils now has 2 functions, replaceChars and "replaceChars2", do
> we need both?
>
> (3) Point the Javadoc for the deprecated CharSetUtils.translate to a new
> StringUtils function replaceChars2.
> Pro: Backwards compatible with the current StringUtils.replaceChars, it has
> not changed.
> Con: Well... in theory, calls sites that have followed the deprecated
> instructions now will now be "incorrect" and will have to be changed again.
>
> (4) "un-deprecate" CharSetUtils.translate(String,String,String) and say that
> both methods do different jobs.
>
> Opinions please?
>
> Thanks,
> Gary
>
The rationale for deprecating CharSetUtils.translate() and the intended
behavior of StringUtils.replaceChars() can be found here:
http://nagoya.apache.org/eyebrowse/ReadMsg?listName=commons-dev@jakarta.apache.org&msgId=785148
The example in the bug report looks like a bug to me, which should be
fixed. I doubt seriously that anyone is relying on the following kind of
bugged behavior:
StringUtils.replaceChars("abc", "abc", "cba") = "aba"
This results from the string being modified and re-searched in a loop over
the search characters (so multiple "translations" may be applied,
depending on the order of characters in the search string).
As long as the search and replace character strings have the same length,
StringUtils.replaceChars() *should* produce the same results as
CharSetUtils.translate().
I suggest, therefore
(5) Fix the bug in StringUtils.replaceChars() and improve the javadoc for
this method.
Phil
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [lang][PROPOSAL] How to best address Bug 25454
Posted by Phil Steitz <ph...@steitz.com>.
Stephen Colebourne wrote:
> From: "Phil Steitz" <ph...@steitz.com>
>
>>>+1, replaceChars should be like calling replaceChars(String, char, char)
>>>multiple times.
>>
>>hmm. I think that was what I was referring to as "bugged." The problem is
>>that, as Gary points out above, the old CharSetUtils.translate() really
>>works like a simple translation map, passing the string just one time and
>>performing the indicated character replacements. The behavior now in
>>replaceChars() is as you describe -- so if the replacement map takes c_1
>>to c_2 and c_2 to c_3 (and c_1 preceeds c_2 in the searchString) the net
>>effect will be c_1 |-> c_3. Is this really how we want it to work?
>
> Er no,
> replaceChars("abc", "ab", "bc") = "bcc"
> (multiple times based on the original string...)
> Stephen
>
OK we agree then that the current code is incorrect, since it returns
"ccc" for the case above.
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
Re: [lang][PROPOSAL] How to best address Bug 25454
Posted by Stephen Colebourne <sc...@btopenworld.com>.
From: "Phil Steitz" <ph...@steitz.com>
> > +1, replaceChars should be like calling replaceChars(String, char, char)
> > multiple times.
>
> hmm. I think that was what I was referring to as "bugged." The problem is
> that, as Gary points out above, the old CharSetUtils.translate() really
> works like a simple translation map, passing the string just one time and
> performing the indicated character replacements. The behavior now in
> replaceChars() is as you describe -- so if the replacement map takes c_1
> to c_2 and c_2 to c_3 (and c_1 preceeds c_2 in the searchString) the net
> effect will be c_1 |-> c_3. Is this really how we want it to work?
Er no,
replaceChars("abc", "ab", "bc") = "bcc"
(multiple times based on the original string...)
Stephen
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [lang][PROPOSAL] How to best address Bug 25454
Posted by Phil Steitz <ph...@steitz.com>.
Stephen Colebourne wrote:
> From: "Phil Steitz" <ph...@steitz.com>
>
>>The example in the bug report looks like a bug to me, which should be
>>fixed. I doubt seriously that anyone is relying on the following kind of
>>bugged behavior:
>>
>>StringUtils.replaceChars("abc", "abc", "cba") = "aba"
>>
>>This results from the string being modified and re-searched in a loop over
>>the search characters (so multiple "translations" may be applied,
>>depending on the order of characters in the search string).
>>
>>As long as the search and replace character strings have the same length,
>>StringUtils.replaceChars() *should* produce the same results as
>>CharSetUtils.translate().
>>
>>I suggest, therefore
>>
>>(5) Fix the bug in StringUtils.replaceChars() and improve the javadoc for
>>this method.
>
> +1, replaceChars should be like calling replaceChars(String, char, char)
> multiple times.
hmm. I think that was what I was referring to as "bugged." The problem is
that, as Gary points out above, the old CharSetUtils.translate() really
works like a simple translation map, passing the string just one time and
performing the indicated character replacements. The behavior now in
replaceChars() is as you describe -- so if the replacement map takes c_1
to c_2 and c_2 to c_3 (and c_1 preceeds c_2 in the searchString) the net
effect will be c_1 |-> c_3. Is this really how we want it to work?
Phil
> Stephen
>
>
> ---------------------------------------------------------------------
> 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
Re: [lang][PROPOSAL] How to best address Bug 25454
Posted by Stephen Colebourne <sc...@btopenworld.com>.
From: "Phil Steitz" <ph...@steitz.com>
> The example in the bug report looks like a bug to me, which should be
> fixed. I doubt seriously that anyone is relying on the following kind of
> bugged behavior:
>
> StringUtils.replaceChars("abc", "abc", "cba") = "aba"
>
> This results from the string being modified and re-searched in a loop over
> the search characters (so multiple "translations" may be applied,
> depending on the order of characters in the search string).
>
> As long as the search and replace character strings have the same length,
> StringUtils.replaceChars() *should* produce the same results as
> CharSetUtils.translate().
>
> I suggest, therefore
>
> (5) Fix the bug in StringUtils.replaceChars() and improve the javadoc for
> this method.
+1, replaceChars should be like calling replaceChars(String, char, char)
multiple times.
Stephen
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org