In message <[EMAIL PROTECTED]>, "Sann, St
ephan" writes:
>Been there - took a look at that. Let's say the code is a litle bit of
>counterintuitive - especially when it comes to the nitty-gritty (where
...
>Could you give a short clue where the backreferences are pasted back
>in so I can apply the leverage there?

I said subclass, not modify :)  You can subclass Perl5Substitution,
override append, and wrap the MatchResult with your own
MatchResultAdapter (maybe a dummy convenience adapter should be
added to the API) before passing it to super.appendSubstitution().
For example:
public void appendSubstitution(StringBuffer appendBuffer, MatchResult match,
                               int substitutionCount,
                               PatternMatcherInput originalInput, 
                               PatternMatcher matcher, Pattern pattern)
{
    super.appendSubstitution(appendBuffer, new MyMatchResult(match),
                             substitutionCount, originalInput, matcher, 
pattern);
}

MyMatchResult would override the delegate's method return values,
applying whatever modifications you wanted to the real result, which
would be used transparently by Perl5Substitution.

>Maybe if I'm able to cope with this thing I could commit the results to
>the project!??

If you can implement a MatchResult adapter that adjusts the groups
and offsets automatically, that would definitely be something to
commit.  Basically, what you're doing is substituting one or more
matched groups with a new value and adjusting the offsets.
Unfortunately, in a non-scripting language you have to go through
the rigmarole of using a class framework instead of embedding
inline interpreted code into the substitution expressio.  However,
another route one could go is to actually implement support for
interpreting function calls or basic Java syntax  a la "(?{ code } )"
(using one of the various embeddable scripting frameworks) in the
substitution expression using reflection.  I'm not sure there's a lot
of demand for that though (it may have been suggested in the past; check
the archives), but if Perl5Substition were enhanced to do that, it
would probably be a good idea to require the feature to be turned on
explicitly so that legacy code doesn't suddenly have this security hole
in it (e.g., servlets that accept expressions via a Web form without
scrubbing).

daniel



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

Reply via email to