summaryrefslogtreecommitdiff
path: root/gnu/java/util/regex/REToken.java
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2008-09-01 17:19:54 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2008-09-01 17:19:54 +0000
commit5f55de7aeceb54ed19113fcda5decbfb21d3c8f9 (patch)
tree1498de7d21de9f6138c217484f3bef4a695179c8 /gnu/java/util/regex/REToken.java
parente6b426c06016fe3f2c5ad814caf42d486564b9a0 (diff)
downloadclasspath-5f55de7aeceb54ed19113fcda5decbfb21d3c8f9.tar.gz
2008-09-01 Andrew John Hughes <gnu_andrew@member.fsf.org>
* gnu/java/util/regex/BacktrackStack.java, * gnu/java/util/regex/CharIndexed.java, * gnu/java/util/regex/CharIndexedCharArray.java, * gnu/java/util/regex/CharIndexedCharSequence.java, * gnu/java/util/regex/CharIndexedInputStream.java, * gnu/java/util/regex/CharIndexedString.java, * gnu/java/util/regex/CharIndexedStringBuffer.java, * gnu/java/util/regex/RE.java, * gnu/java/util/regex/REException.java, * gnu/java/util/regex/REFilterInputStream.java, * gnu/java/util/regex/REMatch.java, * gnu/java/util/regex/REMatchEnumeration.java, * gnu/java/util/regex/RESyntax.java, * gnu/java/util/regex/REToken.java, * gnu/java/util/regex/RETokenAny.java, * gnu/java/util/regex/RETokenBackRef.java, * gnu/java/util/regex/RETokenChar.java, * gnu/java/util/regex/RETokenEnd.java, * gnu/java/util/regex/RETokenEndOfPreviousMatch.java, * gnu/java/util/regex/RETokenEndSub.java, * gnu/java/util/regex/RETokenIndependent.java, * gnu/java/util/regex/RETokenLookAhead.java, * gnu/java/util/regex/RETokenLookBehind.java, * gnu/java/util/regex/RETokenNamedProperty.java, * gnu/java/util/regex/RETokenOneOf.java, * gnu/java/util/regex/RETokenPOSIX.java, * gnu/java/util/regex/RETokenRange.java, * gnu/java/util/regex/RETokenRepeated.java, * gnu/java/util/regex/RETokenStart.java, * gnu/java/util/regex/RETokenWordBoundary.java, * gnu/java/util/regex/UncheckedRE.java: Fix indentation.
Diffstat (limited to 'gnu/java/util/regex/REToken.java')
-rw-r--r--gnu/java/util/regex/REToken.java193
1 files changed, 115 insertions, 78 deletions
diff --git a/gnu/java/util/regex/REToken.java b/gnu/java/util/regex/REToken.java
index 41b4c633c..681ac517f 100644
--- a/gnu/java/util/regex/REToken.java
+++ b/gnu/java/util/regex/REToken.java
@@ -41,63 +41,79 @@ import gnu.java.lang.CPStringBuilder;
import java.io.Serializable;
-abstract class REToken implements Serializable, Cloneable {
+abstract class REToken implements Serializable, Cloneable
+{
protected REToken next = null;
protected REToken uncle = null;
protected int subIndex;
protected boolean unicodeAware = true;
- public Object clone() {
- try {
- REToken copy = (REToken) super.clone();
- return copy;
- } catch (CloneNotSupportedException e) {
- throw new Error(); // doesn't happen
+ public Object clone ()
+ {
+ try
+ {
+ REToken copy = (REToken) super.clone ();
+ return copy;
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw new Error (); // doesn't happen
}
}
- protected REToken(int subIndex) {
- this.subIndex = subIndex;
+ protected REToken (int subIndex)
+ {
+ this.subIndex = subIndex;
}
- int getMinimumLength() {
+ int getMinimumLength ()
+ {
return 0;
}
- int getMaximumLength() {
+ int getMaximumLength ()
+ {
return Integer.MAX_VALUE;
}
- void setUncle(REToken anUncle) {
+ void setUncle (REToken anUncle)
+ {
uncle = anUncle;
}
/** Returns true if the match succeeded, false if it failed. */
- boolean match(CharIndexed input, REMatch mymatch) {
- return match(input, mymatch, false);
- }
- boolean matchFake(CharIndexed input, REMatch mymatch) {
- return match(input, mymatch, true);
- }
+ boolean match (CharIndexed input, REMatch mymatch)
+ {
+ return match (input, mymatch, false);
+ }
+ boolean matchFake (CharIndexed input, REMatch mymatch)
+ {
+ return match (input, mymatch, true);
+ }
- private boolean match(CharIndexed input, REMatch mymatch, boolean fake) {
- if (!fake) {
- setHitEnd(input, mymatch);
- }
- REMatch m = matchThis(input, mymatch);
- if (m == null) return false;
- if (next(input, m)) {
- mymatch.assignFrom(m);
- return true;
- }
- return false;
- }
+ private boolean match (CharIndexed input, REMatch mymatch, boolean fake)
+ {
+ if (!fake)
+ {
+ setHitEnd (input, mymatch);
+ }
+ REMatch m = matchThis (input, mymatch);
+ if (m == null)
+ return false;
+ if (next (input, m))
+ {
+ mymatch.assignFrom (m);
+ return true;
+ }
+ return false;
+ }
/** Sets whether the matching occurs at the end of input */
- void setHitEnd(CharIndexed input, REMatch mymatch) {
- input.setHitEnd(mymatch);
- }
+ void setHitEnd (CharIndexed input, REMatch mymatch)
+ {
+ input.setHitEnd (mymatch);
+ }
/** Returns true if the match succeeded, false if it failed.
* The matching is done against this REToken only. Chained
@@ -109,22 +125,27 @@ abstract class REToken implements Serializable, Cloneable {
* subclasses of REToken, which needs a special match method,
* do not have to implement this method.
*/
- REMatch matchThis(CharIndexed input, REMatch mymatch) {
- throw new UnsupportedOperationException(
- "This REToken does not have a matchThis method");
- }
-
+ REMatch matchThis (CharIndexed input, REMatch mymatch)
+ {
+ throw new
+ UnsupportedOperationException
+ ("This REToken does not have a matchThis method");
+ }
+
/** Returns true if the rest of the tokens match, false if they fail. */
- protected boolean next(CharIndexed input, REMatch mymatch) {
- REToken nextToken = getNext();
- if (nextToken == null) return true;
- return nextToken.match(input, mymatch);
- }
+ protected boolean next (CharIndexed input, REMatch mymatch)
+ {
+ REToken nextToken = getNext ();
+ if (nextToken == null)
+ return true;
+ return nextToken.match (input, mymatch);
+ }
/** Returns the next REToken chained to this REToken. */
- REToken getNext() {
- return (next != null ? next : uncle);
- }
+ REToken getNext ()
+ {
+ return (next != null ? next : uncle);
+ }
/** Finds a match at the position specified by the given REMatch.
* If necessary, adds a BacktrackStack.Backtrack object to backtrackStack
@@ -135,45 +156,55 @@ abstract class REToken implements Serializable, Cloneable {
* @param mymatch Position at which a match should be found
* @return REMatch object if a match was found, null otherwise.
*/
- REMatch findMatch(CharIndexed input, REMatch mymatch) {
- boolean b = match(input, mymatch);
- if (b) return mymatch;
- return null;
- }
+ REMatch findMatch (CharIndexed input, REMatch mymatch)
+ {
+ boolean b = match (input, mymatch);
+ if (b)
+ return mymatch;
+ return null;
+ }
- boolean returnsFixedLengthMatches() {
- return false;
- }
+ boolean returnsFixedLengthMatches ()
+ {
+ return false;
+ }
- int findFixedLengthMatches(CharIndexed input, REMatch mymatch, int max) {
- throw new UnsupportedOperationException(
- "This token does not support findFixedLengthMatches");
- }
+ int findFixedLengthMatches (CharIndexed input, REMatch mymatch, int max)
+ {
+ throw new
+ UnsupportedOperationException
+ ("This token does not support findFixedLengthMatches");
+ }
/**
* Backtrack to another possibility.
* Ordinary REToken cannot do anything if this method is called.
*/
- REMatch backtrack(CharIndexed input, REMatch mymatch, Object param) {
- throw new IllegalStateException("This token cannot be backtracked to");
- }
+ REMatch backtrack (CharIndexed input, REMatch mymatch, Object param)
+ {
+ throw new IllegalStateException ("This token cannot be backtracked to");
+ }
- boolean chain(REToken token) {
- next = token;
- return true; // Token was accepted
+ boolean chain (REToken token)
+ {
+ next = token;
+ return true; // Token was accepted
}
- abstract void dump(CPStringBuilder os);
+ abstract void dump (CPStringBuilder os);
- void dumpAll(CPStringBuilder os) {
- dump(os);
- if (next != null) next.dumpAll(os);
+ void dumpAll (CPStringBuilder os)
+ {
+ dump (os);
+ if (next != null)
+ next.dumpAll (os);
}
- public String toString() {
- CPStringBuilder os = new CPStringBuilder();
- dump(os);
- return os.toString();
+ public String toString ()
+ {
+ CPStringBuilder os = new CPStringBuilder ();
+ dump (os);
+ return os.toString ();
}
/**
@@ -184,9 +215,12 @@ abstract class REToken implements Serializable, Cloneable {
* @return the lowercase equivalent of the character, if any;
* otherwise, the character itself.
*/
- public static char toLowerCase(char ch, boolean unicodeAware) {
- if (unicodeAware) return Character.toLowerCase(ch);
- if (ch >= 'A' && ch <= 'Z') return (char)(ch + 'a' - 'A');
+ public static char toLowerCase (char ch, boolean unicodeAware)
+ {
+ if (unicodeAware)
+ return Character.toLowerCase (ch);
+ if (ch >= 'A' && ch <= 'Z')
+ return (char) (ch + 'a' - 'A');
return ch;
}
@@ -198,9 +232,12 @@ abstract class REToken implements Serializable, Cloneable {
* @return the uppercase equivalent of the character, if any;
* otherwise, the character itself.
*/
- public static char toUpperCase(char ch, boolean unicodeAware) {
- if (unicodeAware) return Character.toUpperCase(ch);
- if (ch >= 'a' && ch <= 'z') return (char)(ch + 'A' - 'a');
+ public static char toUpperCase (char ch, boolean unicodeAware)
+ {
+ if (unicodeAware)
+ return Character.toUpperCase (ch);
+ if (ch >= 'a' && ch <= 'z')
+ return (char) (ch + 'A' - 'a');
return ch;
}