Package io.toro.martini.util
Class StringMatcher
java.lang.Object
io.toro.martini.util.StringMatcher
Based on org.eclipse.ui.internal.misc.StringMatcher.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionStringMatcher(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. -
Method Summary
Modifier and TypeMethodDescriptionFind the first occurrence of the pattern betweenstartinvalid input: '<'/code )(inclusive) andend(exclusive).booleanmatch the giventextwith the patternbooleanGiven the starting (inclusive) and the ending (exclusive) positions in thetext, determine if the given substring matches with aPatternprotected intprotected intregExpPosIn(String text, int start, int end, String p) protected booleanregExpRegionMatches(String text, int tstart, String p, int pstart, int len) protected int
-
Field Details
-
pattern
-
length
protected int length -
ignoreWildCards
protected boolean ignoreWildCards -
ignoreCase
protected boolean ignoreCase -
hasLeadingStar
protected boolean hasLeadingStar -
hasTrailingStar
protected boolean hasTrailingStar -
segments
-
bound
protected int bound -
singleWildCard
protected static final char singleWildCard- See Also:
-
-
Constructor Details
-
StringMatcher
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. Literal '*' and '?' characters must be escaped in the pattern e.g., "\*" means literal "*", etc. Escaping any other character (including the escape character itself), just results in that character in the pattern. e.g., "\a" means "a" and "\\" means "\" If invoking the StringMatcher with string literals in Java, don't forget escape characters are represented by "\\".- Parameters:
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).
-
-
Method Details
-
fuzzy
- Parameters:
query- a raw query- Returns:
- a fuzzy matcher
-
find
Find the first occurrence of the pattern betweenstartinvalid input: '<'/code )(inclusive) andend(exclusive).- Parameters:
text- the String object to search instart- the starting index of the search range, inclusiveend- the ending index of the search range, exclusive- Returns:
- an
StringMatcher.Positionobject 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 returned
-
match
match the giventextwith the pattern- Parameters:
text- a String object- Returns:
- true if matched otherwise false
-
match
Given the starting (inclusive) and the ending (exclusive) positions in thetext, determine if the given substring matches with aPattern- Parameters:
text- a String object that contains the substring to matchstart- marks the starting position (inclusive) of the substringend- marks the ending index (exclusive) of the substring- Returns:
- true if the specified portion of the text matches the pattern
-
posIn
- Parameters:
text- a string which contains no wildcardstart- the starting index in the text for search, inclusiveend- the stopping point of search, exclusive- Returns:
- the starting index in the text of the pattern , or -1 if not found
-
regExpPosIn
- Parameters:
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 '?'- Returns:
- the starting index in the text of the pattern , or -1 if not found
-
regExpRegionMatches
- Parameters:
text- a String to matchp- String, String, a simple regular expression that may contain '?'pstart- int that indicates the starting index of match, inclusiveend- int that indicates the ending index of match, exclusiveignoreCase- boolean indicating wether code>p is case sensitive- Returns:
- boolean
-
textPosIn
- Parameters:
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 wildcard- Returns:
- the starting index in the text of the pattern , or -1 if not found
-