You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oro-dev@jakarta.apache.org by df...@apache.org on 2001/01/16 01:14:48 UTC
cvs commit: jakarta-oro/src/java/org/apache/oro/text/perl Perl5Util.java
dfs 01/01/15 16:14:48
Modified: src/java/org/apache/oro/text/perl Perl5Util.java
Log:
Updated new split() methods to use the more general Collection argument
to collect results rather than a List. Also reimplemented deprecated
split() method (the one that returns a Vector) to use the new split()
method rather than leave in extra duplicated code.
Revision Changes Path
1.5 +11 -41 jakarta-oro/src/java/org/apache/oro/text/perl/Perl5Util.java
Index: Perl5Util.java
===================================================================
RCS file: /home/cvs/jakarta-oro/src/java/org/apache/oro/text/perl/Perl5Util.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Perl5Util.java 2000/12/24 03:34:24 1.4
+++ Perl5Util.java 2001/01/16 00:14:48 1.5
@@ -148,7 +148,7 @@
* (or even a split, but this isn't particularly useful).
@author <a href="mailto:dfs@savarese.org">Daniel F. Savarese</a>
- @version $Id: Perl5Util.java,v 1.4 2000/12/24 03:34:24 dfs Exp $
+ @version $Id: Perl5Util.java,v 1.5 2001/01/16 00:14:48 dfs Exp $
* @see MalformedPerl5PatternException
* @see org.apache.oro.text.PatternCache
@@ -747,8 +747,8 @@
* the expression. You are not forced to catch this exception
* because it is derived from RuntimeException.
*/
- public synchronized void split(List results, String pattern,
- String input, int limit)
+ public synchronized void split(Collection results, String pattern,
+ String input, int limit)
throws MalformedPerl5PatternException
{
int beginOffset, groups, index;
@@ -790,7 +790,8 @@
* split(results, pattern, input, SPLIT_ALL);
* </pre></blockquote>
*/
- public synchronized void split(List results, String pattern, String input)
+ public synchronized void split(Collection results, String pattern,
+ String input)
throws MalformedPerl5PatternException
{
split(results, pattern, input, SPLIT_ALL);
@@ -837,8 +838,8 @@
* be usable with Pattern instances other than Perl5Pattern.
* <p>
* @deprecated Use
- * {@link split(List results, String pattern, String input, int limit)}
- * instead.
+ * {@link split(Collection results, String pattern, String input, int limit)}
+ * instead.
* @param pattern The regular expression to use as a split delimiter.
* @param input The String to split.
* @param limit The limit on the size of the returned <code>Vector</code>.
@@ -861,40 +862,9 @@
public synchronized Vector split(String pattern, String input, int limit)
throws MalformedPerl5PatternException
{
- int beginOffset, groups, index;
- String group;
Vector results = new Vector(20);
- MatchResult currentResult = null;
- PatternMatcherInput pinput;
- Pattern compiledPattern;
-
- compiledPattern = __parseMatchExpression(pattern);
-
- pinput = new PatternMatcherInput(input);
- beginOffset = 0;
-
- while(--limit != 0 && __matcher.contains(pinput, compiledPattern)) {
- currentResult = __matcher.getMatch();
-
- results.addElement(input.substring(beginOffset,
- currentResult.beginOffset(0)));
- if((groups = currentResult.groups()) > 1) {
- for(index = 1; index < groups; ++index) {
- group = currentResult.group(index);
- if(group != null && group.length() > 0)
- results.addElement(group);
- }
- }
-
- beginOffset = currentResult.endOffset(0);
- }
-
- results.addElement(input.substring(beginOffset, input.length()));
-
- // Just for the sake of completeness
- __lastMatch = currentResult;
-
- return results;
+ split(results, pattern, input, limit);
+ return results;
}
/**
@@ -902,8 +872,8 @@
* <blockquote><pre>
* split(pattern, input, SPLIT_ALL);
* </pre></blockquote>
- * @deprecated Use {@link split(List results, String pattern, String input)}
- * instead.
+ * @deprecated Use
+ * {@link split(Collection results, String pattern, String input)} instead.
*/
public synchronized Vector split(String pattern, String input)
throws MalformedPerl5PatternException