I have committed this change to CVS as follows:

- original translate function in CharSetUtils is unchanged, but DEPRECATED

- NEW method 'replaceChars' added to StringUtils. (translate didn't use set
notation, so was completely out of place on CharSetUtils. replaceChars
follows our style of using Java-like method names)

- replaceChars performs as per below:
replaceChars(*str, null, *)  = *str
replaceChars(*str, "", *)  = *str
replaceChars(*, "abc", null)  = delete chars 'abc' from string
replaceChars(*, "abc", "")  = delete chars 'abc' from string
replaceChars(*, "abc", "z")  = replace chars 'a' with 'z', DELETE 'b','c'
replaceChars(*, "abc", "zyxwv")  = replace chars 'a' with 'z', 'b' with 'y',
'c' with 'x', IGNORE 'w','v'
Note the change to delete if replaceChars is shorter, as Eric suggested. It
makes much more sense that way.

Stephen

From: "Eric Galluzzo" <[EMAIL PROTECTED]>
> Stephen Colebourne wrote:
> > I propose the clearest is:
> >
> >translate(*str, null, *)  = *str
> >translate(*str, "", *)  = *str
> >translate(*, "abc", null)  = delete chars 'abc' from string
> >translate(*, "abc", "")  = delete chars 'abc' from string
> >translate(*, "abc", "z")  = replace chars 'abc' with 'z'
> >translate(*, "abc", "zyxwv")  = replace chars 'a' with 'z', 'b' with 'y',
> >'c' with 'x', ignore 'wv'
> >
> >--> no errors
> >
> >
> Would it make sense for the translate() function to mimic the XPath
> translate() function's behavior?  (See
> http://www.w3.org/TR/xpath#function-translate.)  That seems to be what
> StringUtils.translate() is modeled upon -- either that or the old Unix
> 'tr' utility.  Following XPath's translate() function definition, all
> your examples above would remain intact except that:
>
> translate(*, "abc", "z")
>
> would cause 'a' to be replaced with 'z', and would delete all
> occurrences of 'b' and 'c'.
>
> If I have no idea what I'm talking about, feel free to brush these
> comments aside with a Dogbert-style "Bah." :)
>
>     - Eric
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to