summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2008-05-09 23:05:04 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2008-05-09 23:05:04 +0000
commit16e862d18eaf06a8bb7b112ed0fabf1da0c19738 (patch)
tree8a0f3ad4b8bd626d58bd5f054dfcf798cd95a3ad
parent12e81a8ae1a7b68d5616a781f2c4f8915c3b3469 (diff)
downloadclasspath-16e862d18eaf06a8bb7b112ed0fabf1da0c19738.tar.gz
2008-05-10 Andrew John Hughes <gnu_andrew@member.fsf.org>
* gnu/java/util/regex/RE.java: Switch to use generic ArrayLists. * gnu/java/util/regex/REMatchEnumeration.java: Make the enumeration implementation generic. * gnu/java/util/regex/RETokenLookBehind.java: Remove unused variables.
-rw-r--r--ChangeLog9
-rw-r--r--gnu/java/util/regex/RE.java57
-rw-r--r--gnu/java/util/regex/REMatchEnumeration.java29
-rw-r--r--gnu/java/util/regex/RETokenLookBehind.java2
4 files changed, 49 insertions, 48 deletions
diff --git a/ChangeLog b/ChangeLog
index d14a23a44..f92a8301c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-05-10 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+ * gnu/java/util/regex/RE.java:
+ Switch to use generic ArrayLists.
+ * gnu/java/util/regex/REMatchEnumeration.java:
+ Make the enumeration implementation generic.
+ * gnu/java/util/regex/RETokenLookBehind.java:
+ Remove unused variables.
+
2008-05-07 Andrew John Hughes <gnu_andrew@member.fsf.org>
Add generics to these classes.
diff --git a/gnu/java/util/regex/RE.java b/gnu/java/util/regex/RE.java
index 2b0348848..7e59208c7 100644
--- a/gnu/java/util/regex/RE.java
+++ b/gnu/java/util/regex/RE.java
@@ -41,10 +41,12 @@ import gnu.java.lang.CPStringBuilder;
import java.io.InputStream;
import java.io.Serializable;
+
+import java.util.ArrayList;
+import java.util.List;
import java.util.Locale;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
-import java.util.Vector;
/**
* RE provides the user interface for compiling and matching regular
@@ -364,7 +366,7 @@ public class RE extends REToken {
int pLength = pattern.length;
numSubs = 0; // Number of subexpressions in this token.
- Vector branches = null;
+ ArrayList<REToken> branches = null;
// linked list of tokens (sort of -- some closed loops can exist)
firstToken = lastToken = null;
@@ -388,7 +390,6 @@ public class RE extends REToken {
// Buffer a token so we can create a TokenRepeated, etc.
REToken currentToken = null;
- char ch;
boolean quot = false;
// Saved syntax and flags.
@@ -451,9 +452,9 @@ public class RE extends REToken {
minimumLength = 0;
maximumLength = 0;
if (branches == null) {
- branches = new Vector();
+ branches = new ArrayList<REToken>();
}
- branches.addElement(theBranch);
+ branches.add(theBranch);
firstToken = lastToken = currentToken = null;
}
@@ -1105,7 +1106,7 @@ public class RE extends REToken {
addToken(currentToken);
if (branches != null) {
- branches.addElement(new RE(firstToken,lastToken,numSubs,subIndex,minimumLength, maximumLength));
+ branches.add(new RE(firstToken,lastToken,numSubs,subIndex,minimumLength, maximumLength));
branches.trimToSize(); // compact the Vector
minimumLength = 0;
maximumLength = 0;
@@ -1139,8 +1140,8 @@ public class RE extends REToken {
boolean insens = ((cflags & REG_ICASE) > 0);
boolean insensUSASCII = ((cflags & REG_ICASE_USASCII) > 0);
- Vector options = new Vector();
- Vector addition = new Vector();
+ final ArrayList<REToken> options = new ArrayList<REToken>();
+ ArrayList<Object> addition = new ArrayList<Object>();
boolean additionAndAppeared = false;
final int RETURN_AT_AND = 0x01;
boolean returnAtAndOperator = ((pflags & RETURN_AT_AND) != 0);
@@ -1170,7 +1171,7 @@ public class RE extends REToken {
if ((ch = pattern[index]) == ']') {
RETokenChar t = new RETokenChar(subIndex,lastChar,insens);
if (insensUSASCII) t.unicodeAware = false;
- options.addElement(t);
+ options.add(t);
lastChar = '-';
} else {
if ((ch == '\\') && syntax.get(RESyntax.RE_BACKSLASH_ESCAPE_IN_LISTS)) {
@@ -1182,7 +1183,7 @@ public class RE extends REToken {
}
RETokenRange t = new RETokenRange(subIndex,lastChar,ch,insens);
if (insensUSASCII) t.unicodeAware = false;
- options.addElement(t);
+ options.add(t);
lastChar = 0; lastCharIsSet = false;
index++;
}
@@ -1228,17 +1229,17 @@ public class RE extends REToken {
if (lastCharIsSet) {
RETokenChar t = new RETokenChar(subIndex,lastChar,insens);
if (insensUSASCII) t.unicodeAware = false;
- options.addElement(t);
+ options.add(t);
}
if (posixID != -1) {
RETokenPOSIX t = new RETokenPOSIX(subIndex,posixID,insens,negate);
if (insensUSASCII) t.unicodeAware = false;
- options.addElement(t);
+ options.add(t);
} else if (np != null) {
RETokenNamedProperty t = getRETokenNamedProperty(subIndex,np,insens,index);
if (insensUSASCII) t.unicodeAware = false;
- options.addElement(t);
+ options.add(t);
} else if (asciiEscIsSet) {
lastChar = asciiEsc; lastCharIsSet = true;
} else {
@@ -1252,13 +1253,13 @@ public class RE extends REToken {
if (posixId != -1) {
RETokenPOSIX t = new RETokenPOSIX(subIndex,posixId,insens,false);
if (insensUSASCII) t.unicodeAware = false;
- options.addElement(t);
+ options.add(t);
}
} else if ((ch == '[') && (syntax.get(RESyntax.RE_NESTED_CHARCLASS))) {
ParseCharClassResult result = parseCharClass(
subIndex, pattern, index, pLength, cflags, syntax, 0);
- addition.addElement(result.token);
- addition.addElement("|");
+ addition.add(result.token);
+ addition.add("|");
index = result.index;
} else if ((ch == '&') &&
(syntax.get(RESyntax.RE_NESTED_CHARCLASS)) &&
@@ -1266,7 +1267,7 @@ public class RE extends REToken {
if (returnAtAndOperator) {
ParseCharClassResult result = new ParseCharClassResult();
options.trimToSize();
- if (additionAndAppeared) addition.addElement("&");
+ if (additionAndAppeared) addition.add("&");
if (addition.size() == 0) addition = null;
result.token = new RETokenOneOf(subIndex,
options, addition, negative);
@@ -1281,8 +1282,8 @@ public class RE extends REToken {
// So, "&&[a-b][k-m]" will be stored in the Vecter
// addition in this order:
// Boolean.FALSE, [a-b], "|", [k-m], "|", "&"
- if (additionAndAppeared) addition.addElement("&");
- addition.addElement(Boolean.FALSE);
+ if (additionAndAppeared) addition.add("&");
+ addition.add(Boolean.FALSE);
additionAndAppeared = true;
// The part on which "&&" operates may be either
@@ -1296,8 +1297,8 @@ public class RE extends REToken {
ParseCharClassResult result = parseCharClass(
subIndex, pattern, index+1, pLength, cflags, syntax,
RETURN_AT_AND);
- addition.addElement(result.token);
- addition.addElement("|");
+ addition.add(result.token);
+ addition.add("|");
// If the method returned at the next "&&", it is OK.
// Otherwise we have eaten the mark of the end of this
// character list "]". In this case we must give back
@@ -1309,7 +1310,7 @@ public class RE extends REToken {
if (lastCharIsSet) {
RETokenChar t = new RETokenChar(subIndex,lastChar,insens);
if (insensUSASCII) t.unicodeAware = false;
- options.addElement(t);
+ options.add(t);
}
lastChar = ch; lastCharIsSet = true;
}
@@ -1320,13 +1321,13 @@ public class RE extends REToken {
if (lastCharIsSet) {
RETokenChar t = new RETokenChar(subIndex,lastChar,insens);
if (insensUSASCII) t.unicodeAware = false;
- options.addElement(t);
+ options.add(t);
}
ParseCharClassResult result = new ParseCharClassResult();
// Create a new RETokenOneOf
options.trimToSize();
- if (additionAndAppeared) addition.addElement("&");
+ if (additionAndAppeared) addition.add("&");
if (addition.size() == 0) addition = null;
result.token = new RETokenOneOf(subIndex,options, addition, negative);
result.index = index;
@@ -1644,10 +1645,10 @@ public class RE extends REToken {
// this has been changed since 1.03 to be non-overlapping matches
private REMatch[] getAllMatchesImpl(CharIndexed input, int index, int eflags) {
- Vector all = new Vector();
+ List<REMatch> all = new ArrayList<REMatch>();
REMatch m = null;
while ((m = getMatchImpl(input,index,eflags,null)) != null) {
- all.addElement(m);
+ all.add(m);
index = m.getEndIndex();
if (m.end[0] == 0) { // handle pathological case of zero-length match
index++;
@@ -1657,9 +1658,7 @@ public class RE extends REToken {
}
if (!input.isValid()) break;
}
- REMatch[] mset = new REMatch[all.size()];
- all.copyInto(mset);
- return mset;
+ return all.toArray(new REMatch[all.size()]);
}
/* Implements abstract method REToken.match() */
diff --git a/gnu/java/util/regex/REMatchEnumeration.java b/gnu/java/util/regex/REMatchEnumeration.java
index a9142a220..02a61b177 100644
--- a/gnu/java/util/regex/REMatchEnumeration.java
+++ b/gnu/java/util/regex/REMatchEnumeration.java
@@ -69,17 +69,18 @@ import java.util.NoSuchElementException;
*
* @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
*/
-public class REMatchEnumeration implements Enumeration, Serializable {
+public class REMatchEnumeration
+ implements Enumeration<REMatch>, Serializable {
private static final int YES = 1;
private static final int MAYBE = 0;
private static final int NO = -1;
private int more;
private REMatch match;
- private RE expr;
- private CharIndexed input;
- private int eflags;
- private int index;
+ private final RE expr;
+ private final CharIndexed input;
+ private final int eflags;
+ private int index;
// Package scope constructor is used by RE.getMatchEnumeration()
REMatchEnumeration(RE expr, CharIndexed input, int index, int eflags) {
@@ -118,20 +119,14 @@ public class REMatchEnumeration implements Enumeration, Serializable {
}
/** Returns the next match in the input text. */
- public Object nextElement() throws NoSuchElementException {
- return nextMatch();
- }
-
- /**
- * Returns the next match in the input text. This method is provided
- * for convenience to avoid having to explicitly cast the return value
- * to class REMatch.
- */
- public REMatch nextMatch() throws NoSuchElementException {
- if (hasMoreElements()) {
+ public REMatch nextElement()
+ throws NoSuchElementException
+ {
+ if (hasMoreElements())
+ {
more = (input.isValid()) ? MAYBE : NO;
return match;
- }
+ }
throw new NoSuchElementException();
}
}
diff --git a/gnu/java/util/regex/RETokenLookBehind.java b/gnu/java/util/regex/RETokenLookBehind.java
index 400cebdad..d02101714 100644
--- a/gnu/java/util/regex/RETokenLookBehind.java
+++ b/gnu/java/util/regex/RETokenLookBehind.java
@@ -62,8 +62,6 @@ final class RETokenLookBehind extends REToken
int max = re.getMaximumLength();
CharIndexed behind = input.lookBehind(mymatch.index, max);
REMatch trymatch = (REMatch)mymatch.clone();
- REMatch trymatch1 = (REMatch)mymatch.clone();
- REMatch newMatch = null;
int diff = behind.length() - input.length();
int curIndex = trymatch.index + diff;
trymatch.index = 0;