Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.0-RC-2
-
None
-
Groovy RC2 on jre 1.6.0 rc1 on WinXP prof edn SP2
Description
(1) each(Matcher,Closure) in DGM doesn't work for patterns with groups
m= 'a name is just a game' =~ /a name is (.*)/ m.each{ println it } //Caught: groovy.lang.MissingMethodException: //No signature of method Regex.doCall() is applicable for argument types: (java.lang.String, java.lang.String) //values: {"a name is just a game", "just a game"}
To fix, replace line:
closure.call((Object[]) groups.toArray())
with these from nearby "eachMatch" method:
if( groups.size()==1 || closure.getMaximumNumberOfParameters()<groups.size() ){ // not enough parameters there to give each group part its own parameter, // so try a closure with one parameter and give it all groups as a array closure.call( (Object)groups.toArray() ) }else{ closure.call( (Object[])groups.toArray() ) }
(2) each(Matcher,Closure) in DGM requires reset()
m= 'coffee' =~ /ee/ m.each{ println it } //prints: ee m.each{ println it } //prints nothing m.reset(); m.each{ println it } //prints: ee
reset() is called in these DGM regex methods: getCount, size, replaceAll, setIndex, & getAt
Why not in each() ?
To fix, before the m.find() call, put:
m.reset()
(3) MatcherIterator in DGM also requires reset():
m= 'reek coffee' =~ /ee/ println m.collect{ it }.join(',') //ee,ee println m.collect{ it }.join(',') //prints blank m.reset(); println m.collect{ it }.join(',') //ee,ee
To fix (I think), in MatcherIterator constructor:
MatcherIterator( Matcher m ){ m.reset(); matcher= m }
Attachments
Issue Links
- is related to
-
GROOVY-1132 match vs match[] handling inconsistent for eachMatch vs. =~
- Closed