public abstract class StrMatcher
extends java.lang.Object
This class comes complete with various factory methods. If these do not suffice, you can subclass and implement your own matcher.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
StrMatcher.CharMatcher
Class used to define a character for matching purposes.
|
(package private) static class |
StrMatcher.CharSetMatcher
Class used to define a set of characters for matching purposes.
|
(package private) static class |
StrMatcher.NoMatcher
Class used to match no characters.
|
(package private) static class |
StrMatcher.StringMatcher
Class used to define a set of characters for matching purposes.
|
(package private) static class |
StrMatcher.TrimMatcher
Class used to match whitespace as per trim().
|
Modifier and Type | Field and Description |
---|---|
private static StrMatcher |
COMMA_MATCHER
Matches the comma character.
|
private static StrMatcher |
DOUBLE_QUOTE_MATCHER
Matches the double quote character.
|
private static StrMatcher |
NONE_MATCHER
Matches no characters.
|
private static StrMatcher |
QUOTE_MATCHER
Matches the single or double quote character.
|
private static StrMatcher |
SINGLE_QUOTE_MATCHER
Matches the double quote character.
|
private static StrMatcher |
SPACE_MATCHER
Matches the space character.
|
private static StrMatcher |
SPLIT_MATCHER
Matches the same characters as StringTokenizer,
namely space, tab, newline, formfeed.
|
private static StrMatcher |
TAB_MATCHER
Matches the tab character.
|
private static StrMatcher |
TRIM_MATCHER
Matches the String trim() whitespace characters.
|
Modifier | Constructor and Description |
---|---|
protected |
StrMatcher()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static StrMatcher |
charMatcher(char ch)
Constructor that creates a matcher from a character.
|
static StrMatcher |
charSetMatcher(char... chars)
Constructor that creates a matcher from a set of characters.
|
static StrMatcher |
charSetMatcher(java.lang.String chars)
Constructor that creates a matcher from a string representing a set of characters.
|
static StrMatcher |
commaMatcher()
Returns a matcher which matches the comma character.
|
static StrMatcher |
doubleQuoteMatcher()
Returns a matcher which matches the double quote character.
|
int |
isMatch(char[] buffer,
int pos)
Returns the number of matching characters, zero for no match.
|
abstract int |
isMatch(char[] buffer,
int pos,
int bufferStart,
int bufferEnd)
Returns the number of matching characters, zero for no match.
|
static StrMatcher |
noneMatcher()
Matches no characters.
|
static StrMatcher |
quoteMatcher()
Returns a matcher which matches the single or double quote character.
|
static StrMatcher |
singleQuoteMatcher()
Returns a matcher which matches the single quote character.
|
static StrMatcher |
spaceMatcher()
Returns a matcher which matches the space character.
|
static StrMatcher |
splitMatcher()
Matches the same characters as StringTokenizer,
namely space, tab, newline and formfeed.
|
static StrMatcher |
stringMatcher(java.lang.String str)
Constructor that creates a matcher from a string.
|
static StrMatcher |
tabMatcher()
Returns a matcher which matches the tab character.
|
static StrMatcher |
trimMatcher()
Matches the String trim() whitespace characters.
|
private static final StrMatcher COMMA_MATCHER
private static final StrMatcher TAB_MATCHER
private static final StrMatcher SPACE_MATCHER
private static final StrMatcher SPLIT_MATCHER
private static final StrMatcher TRIM_MATCHER
private static final StrMatcher SINGLE_QUOTE_MATCHER
private static final StrMatcher DOUBLE_QUOTE_MATCHER
private static final StrMatcher QUOTE_MATCHER
private static final StrMatcher NONE_MATCHER
public static StrMatcher commaMatcher()
public static StrMatcher tabMatcher()
public static StrMatcher spaceMatcher()
public static StrMatcher splitMatcher()
public static StrMatcher trimMatcher()
public static StrMatcher singleQuoteMatcher()
public static StrMatcher doubleQuoteMatcher()
public static StrMatcher quoteMatcher()
public static StrMatcher noneMatcher()
public static StrMatcher charMatcher(char ch)
ch
- the character to match, must not be nullpublic static StrMatcher charSetMatcher(char... chars)
chars
- the characters to match, null or empty matches nothingpublic static StrMatcher charSetMatcher(java.lang.String chars)
chars
- the characters to match, null or empty matches nothingpublic static StrMatcher stringMatcher(java.lang.String str)
str
- the string to match, null or empty matches nothingpublic abstract int isMatch(char[] buffer, int pos, int bufferStart, int bufferEnd)
This method is called to check for a match.
The parameter pos
represents the current position to be
checked in the string buffer
(a character array which must
not be changed).
The API guarantees that pos
is a valid index for buffer
.
The character array may be larger than the active area to be matched. Only values in the buffer between the specified indices may be accessed.
The matching code may check one character or many.
It may check characters preceding pos
as well as those
after, so long as no checks exceed the bounds specified.
It must return zero for no match, or a positive number if a match was found. The number indicates the number of characters that matched.
buffer
- the text content to match against, do not changepos
- the starting position for the match, valid for bufferbufferStart
- the first active index in the buffer, valid for bufferbufferEnd
- the end index (exclusive) of the active buffer, valid for bufferpublic int isMatch(char[] buffer, int pos)
This method is called to check for a match.
The parameter pos
represents the current position to be
checked in the string buffer
(a character array which must
not be changed).
The API guarantees that pos
is a valid index for buffer
.
The matching code may check one character or many.
It may check characters preceding pos
as well as those after.
It must return zero for no match, or a positive number if a match was found. The number indicates the number of characters that matched.
buffer
- the text content to match against, do not changepos
- the starting position for the match, valid for buffer