Re: Perl5Util.subsitute() and ${X} symbolic references in the substitution pattern
"Daniel F. Savarese" <[email protected]> Sun, 06 Dec 2009 18:42:10 -0500
| Newsgroups | gmane.comp.jakarta.oro.user |
|---|---|
| Message-ID | <[email protected]> |
--==_Exmh_1260142846_56600 Content-Type: text/plain; charset=us-ascii In message <C73E01E3.1DDFD%[email protected]>, Brian Dantes writes: >$x =~ s/abc(def)ghi(jkl)/${1}123${2}/; > >This doesn't work with ORO. Instead I have to: > >util.substitute("s/abc(def)ghi(jkl)/$1\\123$2/"); ... >Is there a way? Try the attached patch. I made it against the trunk, so it may need a little adjustment for the last released version, but I think it will apply cleanly against 2.0.8. If you can confirm for me that the patch works for you, I'll commit the change. It's been a very long time since I've looked at any of this code and I was about to suggest you preprocess your expressions to transform them from the first form to the second form, but it turned out the feature was a very quick fix. If anyone requires a formal release with the change, we can branch off of 2.0.8 to cut a 2.0.9 release (the trunk contains incomplete experimental changes), but I'm going to have to recruit some help from another Jakarta committer to prepare an actual release as I'm extremely short on time. There's a bunch of non-coding stuff involved that has changed since the last release, centering around the build system, web page generation, and release requirement compliance that I just don't have the time for right now. daniel --==_Exmh_1260142846_56600 Content-Type: application/x-patch ; name="Perl5Substitution.patch" Content-Description: Perl5Substitution.patch Content-Disposition: attachment; filename="Perl5Substitution.patch" Index: src/java/org/apache/oro/text/regex/Perl5Substitution.java =================================================================== --- src/java/org/apache/oro/text/regex/Perl5Substitution.java (revision 389827) +++ src/java/org/apache/oro/text/regex/Perl5Substitution.java (working copy) @@ -165,7 +165,7 @@ transient String _lastInterpolation; private static final boolean __isInterpolationCharacter(char ch) { - return (Character.isDigit(ch) || ch == '&'); + return (Character.isDigit(ch) || ch == '&' || ch == '{'); } private void __addElement(int value) { @@ -220,13 +220,19 @@ saveDigits = false; continue; } - } + } else if(c == '{') { + continue; + } __addElement(posParam); posParam = 0; saveDigits = false; - } + if(c == '}') { + continue; + } + } + if ((c != '$' && c != '\\') || escapeMode) { escapeMode = false; if (offset < 0) { --==_Exmh_1260142846_56600 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] --==_Exmh_1260142846_56600--