|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ibm.icu.text.SearchIterator | +--com.ibm.icu.text.StringSearch
StringSearch
is a SearchIterator
that provides
language-sensitive text searching based on the comparison rules defined
in a RuleBasedCollator
object.
Instances of StringSearch
function as iterators
maintain a current position and scan over text returning the index of
characters where the pattern occurs and the length of each match.
StringSearch
uses a version of the fast Boyer-Moore search
algorithm that has been adapted to work with the large character set of
Unicode. See "Efficient Text Searching in Java", to be published in
Java Report in February, 1999, for further information on the algorithm.
Consult the SearchIterator
documentation for information on
and examples of how to use instances of this class to implement text
searching. SearchIterator
provides all of the necessary
API; this class only provides constructors and internal implementation
methods.
SearchIterator
,
RuleBasedCollator
Fields inherited from class com.ibm.icu.text.SearchIterator |
DONE |
Constructor Summary | |
StringSearch(java.lang.String pattern,
java.text.CharacterIterator target,
java.util.Locale loc)
Construct a StringSearch object using the collator and
character boundary detection rules for a given locale. |
|
StringSearch(java.lang.String pattern,
java.text.CharacterIterator target,
java.text.RuleBasedCollator collator)
Construct a StringSearch object using a specific collator. |
|
StringSearch(java.lang.String pat,
java.text.CharacterIterator target,
java.text.RuleBasedCollator coll,
java.text.BreakIterator breaker)
Construct a StringSearch object using a specific collator and set
of boundary-detection rules. |
|
StringSearch(java.lang.String pattern,
java.lang.String target)
Construct a StringSearch object using the collator for the default
locale. |
Method Summary | |
java.text.RuleBasedCollator |
getCollator()
Return the RuleBasedCollator being used for this string search. |
java.lang.String |
getPattern()
Returns the pattern for which this object is searching. |
int |
getStrength()
Returns this object's strength property, which indicates what level of differences are considered significant during a search. |
protected int |
handleNext(int start)
Search forward for matching text, starting at a given location. |
protected int |
handlePrev(int start)
Search backward for matching text ,starting at a given location. |
void |
setCollator(java.text.RuleBasedCollator coll)
Set the collator to be used for this string search. |
void |
setPattern(java.lang.String pat)
Set the pattern for which to search. |
void |
setStrength(int newStrength)
Sets this object's strength property. |
void |
setTarget(java.text.CharacterIterator target)
Set the target text which should be searched and resets the iterator's position to point before the start of the new text. |
Methods inherited from class com.ibm.icu.text.SearchIterator |
first, following, getBreakIterator, getIndex, getMatchedText, getMatchLength, getTarget, isOverlapping, last, next, preceding, previous, setBreakIterator, setMatchLength, setOverlapping |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public StringSearch(java.lang.String pat, java.text.CharacterIterator target, java.text.RuleBasedCollator coll, java.text.BreakIterator breaker)
StringSearch
object using a specific collator and set
of boundary-detection rules.
pat
- The text for which this object will search.target
- The text in which to search for the pattern.coll
- A RuleBasedCollator
object which defines the
language-sensitive comparison rules used to determine
whether text in the pattern and target matches.breaker
- A BreakIterator
object used to constrain the matches
that are found. Matches whose start and end indices
in the target text are not boundaries as determined
by the BreakIterator
are ignored. If this behavior
is not desired, null
can be passed in instead.public StringSearch(java.lang.String pattern, java.text.CharacterIterator target, java.text.RuleBasedCollator collator)
StringSearch
object using a specific collator.
pattern
- The text for which this object will search.target
- The text in which to search for the pattern.collator
- A RuleBasedCollator
object which defines the
language-sensitive comparison rules used to determine
whether text in the pattern and target matches.public StringSearch(java.lang.String pattern, java.text.CharacterIterator target, java.util.Locale loc)
StringSearch
object using the collator and
character boundary detection rules for a given locale.pattern
- The text for which this object will search.target
- The text in which to search for the pattern.loc
- The locale whose collation and break-detection rules
should be used.ClassCastException
- thrown if the collator for the specified
locale is not a RuleBasedCollator.public StringSearch(java.lang.String pattern, java.lang.String target)
StringSearch
object using the collator for the default
locale.pattern
- The text for which this object will search.target
- The text in which to search for the pattern.collator
- A RuleBasedCollator
object which defines the
language-sensitive comparison rules used to determine
whether text in the pattern and target matches.Method Detail |
public void setStrength(int newStrength)
Collator.TERTIARY
and
Collator.IDENTICAL
indicate that all differences are
considered significant, Collator.SECONDARY
indicates
that upper/lower case distinctions should be ignored, and
Collator.PRIMARY
indicates that both case and accents
should be ignored. However, the exact meanings of these constants
are determined by individual Collator objects.
Collator.PRIMARY
,
Collator.SECONDARY
,
Collator.TERTIARY
,
Collator.IDENTICAL
public int getStrength()
setStrength(int)
public void setCollator(java.text.RuleBasedCollator coll)
This method causes internal data such as Boyer-Moore shift tables to be recalculated, but the iterator's position is unchanged.
getCollator()
public java.text.RuleBasedCollator getCollator()
public void setPattern(java.lang.String pat)
public java.lang.String getPattern()
public void setTarget(java.text.CharacterIterator target)
setTarget
in class SearchIterator
com.ibm.icu.text.SearchIterator
SearchIterator.getTarget()
protected int handleNext(int start)
SearchIterator.next()
.
If a match is found, this method returns the index at which the match
starts and calls SearchIterator.setMatchLength(int)
with the number of characters in the target
text that make up the match. If no match is found, the method returns
DONE
and does not call setMatchLength.
handleNext
in class SearchIterator
start
- The index in the target text at which the search starts.SearchIterator.next()
,
SearchIterator.DONE
protected int handlePrev(int start)
SearchIterator.previous()
, which this method overrides.
If a match is found, this method returns the index at which the match
starts and calls SearchIterator.setMatchLength(int)
with the number of characters in the target
text that make up the match. If no match is found, the method returns
DONE
and does not call setMatchLength.
handlePrev
in class SearchIterator
start
- The index in the target text at which the search starts.SearchIterator.previous()
,
SearchIterator.DONE
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |