SearchIterator that provides
language-sensitive text searching based on the comparison rules defined
in a RuleBasedCollator object.
StringSearch ensures that language eccentricity can be
handled, e.g. for the German collator, characters ß and SS will be matched
if case is chosen to be ignored.
See the
"ICU Collation Design Document" for more information.
There are 2 match options for selection:
Let S' be the sub-string of a text string S between the offsets start and
end [start, end].
A pattern string P matches a text string S at the offsets [start, end]
if
option 1. Some canonical equivalent of P matches some canonical equivalent
of S'
option 2. P matches S' and if P starts or ends with a combining mark,
there exists no non-ignorable combining mark before or after S?
in S respectively.
Option 2. is the default.
This search has APIs similar to that of other text iteration mechanisms
such as the break iterators in BreakIterator. Using these
APIs, it is easy to scan through text looking for all occurrences of
a given pattern. This search iterator allows changing of direction by
calling a reset followed by a next or previous.
Though a direction change can occur without calling reset first,
this operation comes with some speed penalty.
Match results in the forward direction will match the result matches in
the backwards direction in the reverse order
SearchIterator provides APIs to specify the starting position
within the text string to be searched, e.g. setIndex,
preceding and following.
Since the starting position will be set as it is specified, please take note that
there are some danger points at which the search may render incorrect
results:
A BreakIterator can be used if only matches at logical breaks are desired.
Using a BreakIterator will only give you results that exactly matches the
boundaries given by the BreakIterator. For instance the pattern "e" will
not be found in the string "é" if a character break iterator is used.
Options are provided to handle overlapping matches. E.g. In English, overlapping matches produces the result 0 and 2 for the pattern "abab" in the text "ababab", where mutually exclusive matches only produces the result of 0.
Options are also provided to implement "asymmetric search" as described in UTS #10 Unicode Collation Algorithm, specifically the ElementComparisonType values.
Though collator attributes will be taken into consideration while
performing matches, there are no APIs here for setting and getting the
attributes. These attributes can be set by getting the collator
from getCollator and using the APIs in RuleBasedCollator.
Lastly to update StringSearch to the new collator attributes,
reset has to be called.
Restriction:
Currently there are no composite characters that consists of a
character with combining class > 0 before a character with combining
class == 0. However, if such a character exists in the future,
StringSearch does not guarantee the results for option 1.
Consult the SearchIterator documentation for information on
and examples of how to use instances of this class to implement text
searching.
Note, StringSearch is not to be subclassed.
SearchIterator, RuleBasedCollator
| Modifier and Type | Class and Description |
|---|---|
| private static class | StringSearch.CEBuffer
CEBuffer A circular buffer of CEs from the text being searched |
| private static class | StringSearch.CEI
Java port of ICU4C CEI (usearch.cpp) CEI Collation Element + source text index. |
| private static class | StringSearch.CollationPCE
Java port of ICU4C UCollationPCE (usrchimp.h) |
| private static class | StringSearch.Match
An object used for receiving matched index in search() and searchBackwards(). |
| private static class | StringSearch.Pattern
Java port of ICU4C struct UPattern (usrchimp.h) |
| Modifier and Type | Field and Description |
|---|---|
| private static int | |
| private static int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| pack-priv int | |
| private RuleBasedCollator | |
| private static final int | |
| private Normalizer2 | |
| private StringSearch. | |
| private static final int | |
| private static final int | |
| private int | |
| private static final int | |
| private CollationElementIterator | |
| private StringSearch. | |
| private boolean | |
| private CollationElementIterator | |
| pack-priv int |
| Access | Constructor and Description |
|---|---|
| public | StringSearch(String
text to look for. pattern, CharacterIterator target text to search for pattern. target, RuleBasedCollator RuleBasedCollator that defines the language rulesA breakiter)BreakIterator that is used to determine the
boundaries of a logical match. This argument can be null.Initializes the iterator to use the language-specific rules defined in the argument collator to search for argument pattern in the argument target text. |
| public | StringSearch(String
text to look for. pattern, CharacterIterator target text to search for pattern. target, RuleBasedCollator RuleBasedCollator that defines the language rulesInitializes the iterator to use the language-specific rules defined in the argument collator to search for argument pattern in the argument target text. |
| public | StringSearch(String
text to look for. pattern, CharacterIterator target text to search for pattern. target, Locale locale to use for language and break iterator rules locale)Initializes the iterator to use the language-specific rules and break iterator rules defined in the argument locale to search for argument pattern in the argument target text. |
| public | StringSearch(String
text to look for. pattern, CharacterIterator target text to search for pattern. target, ULocale locale to use for language and break iterator rules locale)Initializes the iterator to use the language-specific rules and break iterator rules defined in the argument locale to search for argument pattern in the argument target text. |
| public | StringSearch(String
text to look for. pattern, String target text to search for pattern. target)Initializes the iterator to use the language-specific rules and break iterator rules defined in the default locale to search for argument pattern in the argument target text. |
| Modifier and Type | Method and Description |
|---|---|
| private static int[] | Returns: new destination array, destination if there was no new allocationtarget array destination, int destination offset to add value offset, int to be added value, int incremental size expected increments)Direct port of ICU4C static int32_t * addTouint32_tArray(...) in usearch.cpp (except not taking destination buffer size and status param). |
| private static long[] | Returns: new destination array, destination if there was no new allocationtarget array destination, int destination offset to add value offset, int target array size destinationlength, long to be added value, int incremental size expected increments)Direct port of ICU4C static int64_t * addTouint64_tArray(...) in usearch.cpp. |
| private boolean | Returns: true if identical match is foundoffset of possible match start, int offset of possible match end)Checks for identical match |
| private static int | |
| private static int | |
| private static int | |
| private int | Returns: the modified collation elementGetting the modified collation elements taking into account the collation attributes. |
| public RuleBasedCollator | Returns: RuleBasedCollator used by this StringSearchGets the |
| public int | getIndex()
Implements abstract com. |
| private static int | Returns: collation element maskcollation strength strength)Getting the mask for collation strength |
| public String | Returns: the pattern searched forReturns the pattern for which StringSearch is searching for. |
| private static final String | Returns: substring from text starting at start and length lengthCharacterIterator text, int start offset start, int of substring length)Gets a substring out of a CharacterIterator Java porting note: Not available in ICU4C |
| protected int | handleNext(int
The index in the target text at which the search
should start. position)Implements abstract com. |
| private boolean | |
| private boolean | |
| private boolean | |
| protected int | handlePrevious(int
The index in the target text at which the search
should start. position)Implements abstract com. |
| private boolean | |
| private boolean | |
| private boolean | |
| private void | |
| private int | |
| private int | Returns: total number of expansionsInitializing the ce table for a pattern. |
| private int | Returns: total number of expansionsInitializing the pce table for a pattern. |
| private boolean | |
| private boolean | |
| public boolean | Returns: true if canonical matches is set, false otherwiseDetermines whether canonical matches (option 1, as described in the class documentation) is set. |
| private static final boolean | Returns: true if offset is out of bounds, false otherwiseoffset of the first character in the range textstart, int limit offset of the text string range textlimit, int to test offset)Checks if the offset runs out of the text string range |
| private int | |
| public void | |
| private boolean | |
| private boolean | |
| public void | setCanonical(boolean
flag indicator if canonical matches are allowed allowCanonical)Set the canonical match mode. |
| public void | setCollator(RuleBasedCollator
to use for this StringSearch collator)Sets the |
| public void | setIndex(int
position from which to start the next search position)Overrides com. Sets the position in the target text at which the next search will start. |
| protected void | setMatchNotFound()
Overrides com.
Deprecated
This API is ICU internal only.
|
| public void | |
| public void | setTarget(CharacterIterator
new text iterator to look for match, text)Overrides com. |