commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject Re: Possible addition to StringUtils
Date Tue, 11 Dec 2001 13:22:59 GMT

On Tue, 11 Dec 2001, Chad Johnson wrote:

> > Respectfully disagree.  If someone calls the escape method on a string,
> > and wants, say, single quotes escaped, then all single quotes in the
> > string, period, should be escaped.  But then I tend to think

>   After running an example through my head of getting input that is
> quoted, I'd have to agree.  If I got the string "bob''s" as input I'd want
> to get it escaped to "bob''''s" so I could get it properly unescaped back
> to its original form.  That line of thinking takes me to my next question
> for the list...  Should an unescape method also be added?  As far as I can
> tell this method won't run into the same problem as the current escape()
> method does (with regards to unescaping), as long as we deal with single
> chars for the charsToEscape and escapingChar variables.

I'm definitely in favour of an unescape method. And after consideration
I'm swayed to having methods that do what they say and escape everything

So now we have:

escape(String target, Map replacements)
escape(String target, char value, char escapeWith)
escape(String target, String value, String escapeWith)  (??)

and unescape methods with the same arguments. Does this have good

foo = escape(foo, 'n', '\\');
foo = unescape(foo, 'n', '\\');

Another question, what's the real difference between an escape method and
a replace method? Is this just a replace method which takes a Map argument
and replaces multiple things in one sweep? In which case, are the escape
semantics necessary ( I think so), and is a replace(String, Map) method
also therefore desired.


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

View raw message