groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jochen Kemnade (JIRA)" <>
Subject [jira] [Commented] (GROOVY-7540) Add StringGroovyMethods.collectReplacements(String, Map)
Date Thu, 06 Aug 2015 06:39:04 GMT


Jochen Kemnade commented on GROOVY-7540:

There are questions to answer though, like should the method be regex aware 
I'm not sure. I don't need it to be regex aware, but I can see how that would be a nice feature.
I'd like to avoid the overhead of compiling a Pattern for simple strings though. Also, if
we allow regexes, people will want to pass in a pattern. We cannot provide two methods ({{Map<String,
String>}} and {{Map<Pattern, String>}}) because of type erasure, but we could allow
{{Map<Object, String>}} and check the keys's types. Allowing regexes will definitely
make things more complicated.
and as per your earlier comment, are the transformations sequential in nature (the 'bar' and
'baz') alternatives
I'd say no.
"foo".collectReplacements(["foo":"bar", "bar":"baz"])                        // should become
"bar", if I want "baz", I can call
"foo".collectReplacements(["foo":"bar"]).collectReplacements(["bar":"baz"])  // but if the
replacements are done sequentially, 
                                                                             // there's no
way to do the "faabor" -> "foobor" example.
But I've got another one: What happens here?
"foo".collectReplacements(["f":"g", "foo":"bar"])    // goo? bar? Exception?
I'd go for exception, but those cases can be hard to detect, if not impossible, especially
if we do allow regexes. StringUtils does this:

> Add StringGroovyMethods.collectReplacements(String, Map)
> --------------------------------------------------------
>                 Key: GROOVY-7540
>                 URL:
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Jochen Kemnade
>            Priority: Minor
> It should be possible to use a map with {{collectReplacements}}, like in
> {code}
> "f006ar".collectReplacements(["0":"o", "6":"b"])
> {code}

This message was sent by Atlassian JIRA

View raw message