package gnu.java.util.regex;
import java.io.Serializable;
-class CharIndexedCharSequence implements CharIndexed, Serializable {
- private CharSequence s;
- private int anchor;
- private int len;
-
- CharIndexedCharSequence(CharSequence s, int index) {
- this.s = s;
- len = s.length();
- anchor = index;
- }
-
- public char charAt(int index) {
- int pos = anchor + index;
- return ((pos < len) && (pos >= 0)) ? s.charAt(pos) : OUT_OF_BOUNDS;
- }
-
- public boolean isValid() {
- return (anchor < len);
- }
-
- public boolean move(int index) {
- return ((anchor += index) < len);
- }
-
- public boolean move1(int index) {
- return ((anchor += index) <= len);
- }
-
- public CharIndexed lookBehind(int index, int length) {
- if (length > (anchor + index)) length = anchor + index;
- return new CharIndexedCharSequence(s, anchor + index - length);
- }
-
- public int length() {
- return len - anchor;
- }
-
- private REMatch lastMatch;
- public void setLastMatch(REMatch match) {
- lastMatch = (REMatch)match.clone();
- lastMatch.anchor = anchor;
- }
- public REMatch getLastMatch() { return lastMatch; }
-
- private int rightmostTriedPosition = 0;
- public void setHitEnd(REMatch match) {
- int pos = anchor + match.index;
- if (pos > rightmostTriedPosition) rightmostTriedPosition = pos;
- }
- public boolean hitEnd() { return rightmostTriedPosition >= len; }
-
- public int getAnchor() { return anchor; }
- public void setAnchor(int anchor) { this.anchor = anchor; }
+class CharIndexedCharSequence implements CharIndexed, Serializable
+{
+ private CharSequence s;
+ private int anchor;
+ private int len;
+
+ CharIndexedCharSequence (CharSequence s, int index)
+ {
+ this.s = s;
+ len = s.length ();
+ anchor = index;
+ }
+
+ public char charAt (int index)
+ {
+ int pos = anchor + index;
+ return ((pos < len) && (pos >= 0)) ? s.charAt (pos) : OUT_OF_BOUNDS;
+ }
+
+ public boolean isValid ()
+ {
+ return (anchor < len);
+ }
+
+ public boolean move (int index)
+ {
+ return ((anchor += index) < len);
+ }
+
+ public boolean move1 (int index)
+ {
+ return ((anchor += index) <= len);
+ }
+
+ public CharIndexed lookBehind (int index, int length)
+ {
+ if (length > (anchor + index))
+ length = anchor + index;
+ return new CharIndexedCharSequence (s, anchor + index - length);
+ }
+
+ public int length ()
+ {
+ return len - anchor;
+ }
+
+ private REMatch lastMatch;
+ public void setLastMatch (REMatch match)
+ {
+ lastMatch = (REMatch) match.clone ();
+ lastMatch.anchor = anchor;
+ }
+ public REMatch getLastMatch ()
+ {
+ return lastMatch;
+ }
+
+ private int rightmostTriedPosition = 0;
+ public void setHitEnd (REMatch match)
+ {
+ int pos = anchor + match.index;
+ if (pos > rightmostTriedPosition)
+ rightmostTriedPosition = pos;
+ }
+ public boolean hitEnd ()
+ {
+ return rightmostTriedPosition >= len;
+ }
+
+ public int getAnchor ()
+ {
+ return anchor;
+ }
+ public void setAnchor (int anchor)
+ {
+ this.anchor = anchor;
+ }
}