![]() | [using it] | Interface Manipulation Package v4.0 (2008-06-25) | ![]() | ©copyright | ![]() |
java.lang.Objectimp.util.PatternReader
public class PatternReader
Defines a stream character-reader with a regular-expression reading method.
Field Summary | |
---|---|
static boolean |
ABOUT_REGULAR_EXPRESSIONS
The following regular-expressions are used in this context. |
static String |
NAME
Defines a name pattern in this context. |
static String |
NUMBER
Defines a number pattern in this context. |
Constructor Summary | |
---|---|
PatternReader(String string)
Constructs a stream for the given char-sequence. |
Method Summary | |
---|---|
void |
check(boolean condition,
String message)
Throws an exception if a parse-error is detected. |
boolean |
isAtEnd()
Returns true if the at the end of the stream else false. |
String |
read(String pattern)
Reads the given pattern starting at the current position and increments the stream position if it matches. |
String |
read(String pattern,
String message)
Reads the given pattern starting at the current position, increments the stream position if it matches or throws an exception if it does not. |
void |
set(int offset)
Sets the relative position of the stream |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final boolean ABOUT_REGULAR_EXPRESSIONS
Construct | Matches |
Characters | |
x | The character x |
\\ | The backslash character |
\n | The newline character |
\u**** | The character with hexadecimal value 0x**** |
Character classes | |
[top] | t, o, or p (simple class) |
[^top] | Any character except t, o, or p (negation) |
[a-zA-Z] | a through z or A through Z, inclusive (range) |
[a-d[m-p]] | a through d, or m through p (union) |
[a-z&&[def]] | d, e, or f (intersection) |
[a-z&&[^b]] | a through z, except for b (subtraction) |
Predefined character classes | |
. | Any character including line terminators |
\d | A digit: [0-9] |
\D | A non-digit: [^0-9] |
\s | A white-space character: [ \t\n\x0B\f\r] |
\S | A non white-space character: [^\s] |
\w | A word character: [a-zA-Z_0-9] |
\W | A non-word character: [^\w] |
\p{Lower} | A lower-case alphabetic character: [a-z] |
\p{Upper} | An upper-case alphabetic character:[A-Z] |
\p{ASCII} | All ASCII:[\x00-\x7F] |
\p{Alpha} | An alphabetic character:[\p{Lower}\p{Upper}] |
\p{Digit} | A decimal digit: [0-9] |
\p{Graph} | A visible character |
\p{Print} | A printable character: [\p{Graph}\x20] |
\p{Blank} | A space or a tab: [ \t] |
\p{XDigit} | A hexadecimal digit: [0-9a-fA-F] |
Boundary matcher | |
^ | The beginning of a line |
$ | The end of a line |
\A | The beginning of the input |
\G | The end of the previous match |
\Z | The end of the input but for the final terminator, if any |
\z | The end of the input |
Quantifiers | |
X? | X, once or not at all |
X* | X, zero or more times |
X+ | X, one or more times |
X{n} | X, exactly n times |
X{n,} | X, at least n times |
X{n,m} | X, at least n but not more than m times |
Logical operators | |
XY | X followed by Y |
X|Y | Either X or Y |
(X) | X, as a capturing group |
Back references | |
\# | Whatever the # |
Special constructs (non-capturing) | |
(?:X) | X, as a non-capturing group |
public static final String NAME
public static final String NUMBER
Constructor Detail |
---|
public PatternReader(String string)
Method Detail |
---|
public void check(boolean condition, String message)
condition
- If false an IllegalArgumentException is thrown.message
- The parse error description.
IllegalArgumentException
- If the condition is false.public boolean isAtEnd()
public String read(String pattern)
pattern
- The regular expression defining the pattern.
public String read(String pattern, String message)
pattern
- The regular expression defining the pattern.message
- The parse error description.
IllegalArgumentException
- If the pattern does not match at the current position.public void set(int offset)
offset
- Relative position increment (e.g. -1 allows to re-read the last char)