Class StringMatcher
java.lang.Object
org.eclipse.nebula.widgets.xviewer.util.internal.StringMatcher
public class StringMatcher
extends java.lang.Object
Copied from JDT UI
A string pattern matcher. Supports '*' and '?' wildcards.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
StringMatcher.Position
-
Field Summary
Fields Modifier and Type Field Description protected int
fBound
protected boolean
fHasLeadingStar
protected boolean
fHasTrailingStar
protected boolean
fIgnoreCase
protected boolean
fIgnoreWildCards
protected int
fLength
protected java.lang.String
fPattern
protected java.lang.String[]
fSegments
protected static char
fSingleWildCard
-
Constructor Summary
Constructors Constructor Description StringMatcher(java.lang.String pattern, boolean ignoreCase, boolean ignoreWildCards)
StringMatcher constructor takes in a String object that is a simple pattern. -
Method Summary
Modifier and Type Method Description StringMatcher.Position
find(java.lang.String text, int start, int end)
Find the first occurrence of the pattern betweenstart
end(exclusive).boolean
match(java.lang.String text)
match the giventext
with the patternboolean
match(java.lang.String text, int start, int end)
Given the starting (inclusive) and the ending (exclusive) positions in thetext
, determine if the given substring matches with aPatternprotected int
posIn(java.lang.String text, int start, int end)
protected int
regExpPosIn(java.lang.String text, int start, int end, java.lang.String p)
protected boolean
regExpRegionMatches(java.lang.String text, int tStart, java.lang.String p, int pStart, int plen)
protected int
textPosIn(java.lang.String text, int start, int end, java.lang.String p)
-
Field Details
-
fPattern
protected java.lang.String fPattern -
fLength
protected int fLength -
fIgnoreWildCards
protected boolean fIgnoreWildCards -
fIgnoreCase
protected boolean fIgnoreCase -
fHasLeadingStar
protected boolean fHasLeadingStar -
fHasTrailingStar
protected boolean fHasTrailingStar -
fSegments
protected java.lang.String[] fSegments -
fBound
protected int fBound -
fSingleWildCard
protected static final char fSingleWildCard- See Also:
- Constant Field Values
-
-
Constructor Details
-
StringMatcher
public StringMatcher(java.lang.String pattern, boolean ignoreCase, boolean ignoreWildCards)StringMatcher constructor takes in a String object that is a simple pattern. The pattern 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
-
find
Find the first occurrence of the pattern betweenstart
end(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.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 returned
-
match
public boolean match(java.lang.String text)match the giventext
with the pattern- Parameters:
text
- a String object- Returns:
- true if matched eitherwise false
-
match
public boolean match(java.lang.String text, int start, int end)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
protected int posIn(java.lang.String text, int start, int end)- 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
protected int regExpPosIn(java.lang.String text, int start, int end, java.lang.String p)- 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
protected boolean regExpRegionMatches(java.lang.String text, int tStart, java.lang.String p, int pStart, int plen) -
textPosIn
protected int textPosIn(java.lang.String text, int start, int end, java.lang.String p)- Parameters:
text
- the string to matchstart
- the starting index in the text for search, inclusiveend
- the stopping point of search, exclusivep
- a string that has no wildcard- Returns:
- the starting index in the text of the pattern , or -1 if not found
-