Hi,
Here is a trivial patch to add...
public synchronized int substitute( StringBuffer result,
String expression,
PatternMatcherInput input )
...to Perl5Util.
Files also available from http://coderage.org/oro/
--
Michael
--- Perl5Util.java.1.10 Sat Dec 8 03:15:25 2001
+++ Perl5Util.java.translate.patch Wed Feb 6 00:01:22 2002
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * Copyright (c) 2000, 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -58,7 +58,7 @@
*/
/*
- * $Id: Perl5Util.java,v 1.10 2001/12/08 03:15:25 dfs Exp $
+ * $Id: Perl5Util.java,v 1.10+MD 2002/02/06 00:01:22 michaed Exp $
*/
import java.util.*;
import org.apache.oro.text.regex.*;
@@ -537,23 +537,26 @@
* <blockquote><pre>
* result = util.substitute("s#/#\\#g", input);
* </pre></blockquote>
- * <p>
- * @param expression The substitution expression.
- * @param input The input.
- * @return The input after substitutions have been performed.
- * @exception MalformedPerl5PatternException If there is an error in
+ * @param appendResult the <code>StringBuffer</code> in which to store the
+ * result of the substitutions. The buffer is only appended to.
+ * @param expression the Perl 5 substitution regular expression
+ * @param input the input on which to perform substitutions
+ * @return <code>int</code> - the number of substitutions made
+ * @exception MalformedPerl5PatternException if there is an error in
* the expression. You are not forced to catch this exception
- * because it is derived from RuntimeException.
+ * as it is derived from <code>RuntimeException</code>.
+ * @since 2.0.6 (file version 1.11)
*/
// Expression parsing will have to be moved into a separate method if
// there are going to be variations of this method.
- public synchronized String substitute(String expression, String input)
+ public synchronized int substitute( StringBuffer appendResult,
+ String expression,
+ PatternMatcherInput input )
throws MalformedPerl5PatternException
{
boolean backslash, finalDelimiter;
int index, compileOptions, numSubstitutions, numInterpolations;
- int firstOffset, secondOffset, thirdOffset;
- String result;
+ int firstOffset, secondOffset, thirdOffset, countSubstitutions;
StringBuffer replacement;
Pattern compiledPattern;
char exp[], delimiter;
@@ -575,12 +578,13 @@
break __nullTest;
}
- result = Util.substitute(__matcher, entry._pattern, entry._substitution,
- input, entry._numSubstitutions);
+ countSubstitutions = Util.substitute(appendResult, __matcher,
+entry._pattern,
+ entry._substitution, input,
+ entry._numSubstitutions);
__lastMatch = __matcher.getMatch();
- return result;
+ return countSubstitutions;
}
exp = expression.toCharArray();
@@ -680,14 +684,49 @@
numSubstitutions);
__expressionCache.addElement(expression, entry);
- result = Util.substitute(__matcher, compiledPattern, substitution,
- input, numSubstitutions);
+ countSubstitutions = Util.substitute(appendResult, __matcher,
+compiledPattern,
+ substitution, input, numSubstitutions);
__lastMatch = __matcher.getMatch();
- return result;
+ return countSubstitutions;
}
+
+ /**
+ * <p>
+ * Substitutes a pattern in a given input with a replacement string.
+ * The substitution expression is specified in Perl5 native format.
+ * </p>
+ * <DD><DL>
+ * <DT><B>Equivalent-to:</B>
+ * <DD><code>
+ * StringBuffer result = new StringBuffer();<br>
+ * PatternMatcherInput pInput = new PatternMatcherInput( input );<br>
+ * perl.substitute( result, expression, input );
+ * </code></DD>
+ * </DL></DD>
+ * @param expression the Perl 5 substitution regular expression
+ * @param input the input on which to perform substitutions
+ * @return the input <code>String</code> after substitutions have
+ * been performed
+ * @exception MalformedPerl5PatternException if there is an error in
+ * the expression. You are not forced to catch this exception
+ * as it is derived from <code>RuntimeException</code>.
+ * @since 1.0
+ * @see #substitute
+ */
+ // Expression parsing will have to be moved into a separate method if
+ // there are going to be variations of this method.
+ public synchronized String substitute( String expression,
+ String input)
+ throws MalformedPerl5PatternException {
+ StringBuffer result = new StringBuffer();
+ PatternMatcherInput cInput = new PatternMatcherInput( input );
+ this.substitute( result, expression, cInput );
+ return result.toString();
+ }
+
/**
* Splits a String into strings that are appended to a List, but no more
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>