public final class StringMatcher extends Object
Modifier and Type | Class and Description |
---|---|
static class |
StringMatcher.Position |
Modifier and Type | Field and Description |
---|---|
protected int |
bound |
protected boolean |
hasLeadingStar |
protected boolean |
hasTrailingStar |
protected boolean |
ignoreCase |
protected boolean |
ignoreWildCards |
protected int |
length |
protected String |
pattern |
protected String[] |
segments |
protected static char |
singleWildCard |
Constructor and Description |
---|
StringMatcher(String pattern,
boolean ignoreCase,
boolean ignoreWildCards)
StringMatcher constructor takes in a String object that is a simple
pattern which may contain '*' for 0 and many characters and '?' for
exactly one character.
|
Modifier and Type | Method and Description |
---|---|
StringMatcher.Position |
find(String text,
int start,
int end)
Find the first occurrence of the pattern between
start end(exclusive). |
static Predicate<String> |
fuzzy(String query) |
boolean |
match(String text)
match the given
text with the pattern |
boolean |
match(String text,
int start,
int end)
Given the starting (inclusive) and the ending (exclusive) positions in
the
text , determine if the given substring matches with
aPattern |
protected int |
posIn(String text,
int start,
int end) |
protected int |
regExpPosIn(String text,
int start,
int end,
String p) |
protected boolean |
regExpRegionMatches(String text,
int tstart,
String p,
int pstart,
int len) |
protected int |
textPosIn(String text,
int start,
int end,
String p) |
protected String pattern
protected int length
protected boolean ignoreWildCards
protected boolean ignoreCase
protected boolean hasLeadingStar
protected boolean hasTrailingStar
protected String[] segments
protected int bound
protected static final char singleWildCard
public StringMatcher(String pattern, boolean ignoreCase, boolean ignoreWildCards)
pattern
- the pattern to match text againstignoreCase
- if true, case is ignoredignoreWildCards
- if true, wild cards and their escape sequences are ignored
(everything is taken literally).public static Predicate<String> fuzzy(String query)
query
- a raw querypublic StringMatcher.Position find(String text, int start, int end)
start
end(exclusive).text
- the String object to search instart
- the starting index of the search range, inclusiveend
- the ending index of the search range, exclusiveStringMatcher.Position
object that keeps the
starting (inclusive) and ending positions (exclusive) of the
first occurrence of the pattern in the specified range of the
text; return null if not found or subtext is empty (start==end).
A pair of zeros is returned if pattern is empty string Note that
for pattern like "*abc*" with leading and trailing stars,
position of "abc" is returned. For a pattern like"*??*" in text
"abcdf", (1,3) is returnedpublic boolean match(String text)
text
with the patterntext
- a String objectpublic boolean match(String text, int start, int end)
text
, determine if the given substring matches with
aPatterntext
- a String object that contains the substring to matchstart
- marks the starting position (inclusive) of the substringend
- marks the ending index (exclusive) of the substringprotected int posIn(String text, int start, int end)
text
- a string which contains no wildcardstart
- the starting index in the text for search, inclusiveend
- the stopping point of search, exclusiveprotected int regExpPosIn(String text, int start, int end, String p)
text
- a simple regular expression that may only contain '?'(s)start
- the starting index in the text for search, inclusiveend
- the stopping point of search, exclusivep
- a simple regular expression that may contains '?'protected boolean regExpRegionMatches(String text, int tstart, String p, int pstart, int len)
text
- a String to matchpstart
- int that indicates the starting index of match, inclusiveend
- int that indicates the ending index of match,
exclusivep
- String, String, a simple regular expression that may contain
'?'ignoreCase
- boolean indicating wether code>p is case sensitiveprotected int textPosIn(String text, int start, int end, String p)
text
- the string to matchstart
- the starting index in the text for search, inclusiveend
- the stopping point of search, exclusivep
- a pattern string that has no wildcardCopyright © 2023. All rights reserved.