Share via


StringSearch Class

Definition

StringSearch is a SearchIterator that provides language-sensitive text searching based on the comparison rules defined in a RuleBasedCollator object.

[Android.Runtime.Register("android/icu/text/StringSearch", ApiSince=24, DoNotGenerateAcw=true)]
public sealed class StringSearch : Android.Icu.Text.SearchIterator
[<Android.Runtime.Register("android/icu/text/StringSearch", ApiSince=24, DoNotGenerateAcw=true)>]
type StringSearch = class
    inherit SearchIterator
Inheritance
Attributes

Remarks

StringSearch is a 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 &szlig; 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:<br> Let S' be the sub-string of a text string S between the offsets start and end [start, end]. <br> 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. SearchIterator#setIndex setIndex, SearchIterator#preceding preceding and SearchIterator#following 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: <ul> <li> In the midst of a substring that requires normalization. <li> If the following match is to be found, the position should not be the second character which requires swapping with the preceding character. Vice versa, if the preceding match is to be found, the position to search from should not be the first character which requires swapping with the next character. E.g certain Thai and Lao characters require swapping. <li> If a following pattern match is to be found, any position within a contracting sequence except the first will fail. Vice versa if a preceding pattern match is to be found, an invalid starting point would be any character within a contracting sequence except the last. </ul>

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 "\u00e9" 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: <br> Currently there are no composite characters that consists of a character with combining class &gt; 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.

Java documentation for android.icu.text.StringSearch.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

StringSearch(String, ICharacterIterator, 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.

StringSearch(String, ICharacterIterator, RuleBasedCollator, BreakIterator)

Initializes the iterator to use the language-specific rules defined in the argument collator to search for argument pattern in the argument target text.

StringSearch(String, ICharacterIterator, RuleBasedCollator)

Initializes the iterator to use the language-specific rules defined in the argument collator to search for argument pattern in the argument target text.

StringSearch(String, ICharacterIterator, ULocale)

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.

StringSearch(String, String)

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.

Fields

Done

DONE is returned by previous() and next() after all valid matches have been returned, and by first() and last() if there are no matches at all.

(Inherited from SearchIterator)

Properties

BreakIterator

Returns the BreakIterator that is used to restrict the indexes at which matches are detected. -or- Set the BreakIterator that will be used to restrict the points at which matches are detected.

(Inherited from SearchIterator)
Canonical

Determines whether canonical matches (option 1, as described in the class documentation) is set. -or- Set the canonical match mode.

Class

Returns the runtime class of this Object.

(Inherited from Object)
Collator

Gets the RuleBasedCollator used for the language rules. -or- Sets the RuleBasedCollator to be used for language-specific searching.

Handle

The handle to the underlying Android instance.

(Inherited from Object)
Index

To be added

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
MatchedText

Returns the text that was matched by the most recent call to #first, #next, #previous, or #last.

(Inherited from SearchIterator)
MatchLength

Returns the length of text in the string which matches the search pattern.

(Inherited from SearchIterator)
MatchStart

Returns the index to the match in the text string that was searched.

(Inherited from SearchIterator)
Overlapping

Return true if the overlapping property has been set. -or- Determines whether overlapping matches are returned.

(Inherited from SearchIterator)
Pattern

Returns the pattern for which StringSearch is searching for. -or- Set the pattern to search for.

PeerReference (Inherited from Object)
Target

Return the string text to be searched. -or- Set the target text to be searched.

(Inherited from SearchIterator)
TargetText

Target text for searching.

(Inherited from SearchIterator)
ThresholdClass (Inherited from SearchIterator)
ThresholdType (Inherited from SearchIterator)

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
First()

Returns the first index at which the string text matches the search pattern.

(Inherited from SearchIterator)
Following(Int32)

Returns the first index equal or greater than position at which the string text matches the search pattern.

(Inherited from SearchIterator)
GetElementComparisonType() (Inherited from SearchIterator)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
HandleNext(Int32)

Abstract method which subclasses override to provide the mechanism for finding the next match in the target text.

(Inherited from SearchIterator)
HandlePrevious(Int32)

Abstract method which subclasses override to provide the mechanism for finding the previous match in the target text.

(Inherited from SearchIterator)
JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Last()

Returns the last index in the target text at which it matches the search pattern.

(Inherited from SearchIterator)
Next()

Returns the index of the next point at which the text matches the search pattern, starting from the current position The iterator is adjusted so that its current index (as returned by #getIndex) is the match position if one was found.

(Inherited from SearchIterator)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
Preceding(Int32)

Returns the first index less than position at which the string text matches the search pattern.

(Inherited from SearchIterator)
Previous()

Returns the index of the previous point at which the string text matches the search pattern, starting at the current position.

(Inherited from SearchIterator)
Reset()

Resets the iteration.

(Inherited from SearchIterator)
SetElementComparisonType(SearchIterator+ElementComparisonType) (Inherited from SearchIterator)
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetIndex(Int32)

Sets the position in the target text at which the next search will start.

(Inherited from SearchIterator)
SetMatchLength(Int32)

Sets the length of the most recent match in the target text.

(Inherited from SearchIterator)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Gets the JNI name of the type of the instance self.

JavaAs<TResult>(IJavaPeerable)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

TryJavaCast<TResult>(IJavaPeerable, TResult)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

Applies to