Logo Search packages:      
Sourcecode: icu version File versions  Download package

SearchIterator Class Reference

#include <search.h>

Inheritance diagram for SearchIterator:
Collaboration diagram for SearchIterator:

List of all members.

Public Member Functions

int32_t first (UErrorCode &status)
int32_t following (int32_t position, UErrorCode &status)
USearchAttributeValue getAttribute (USearchAttribute attribute) const
const BreakIteratorgetBreakIterator (void) const
virtual UClassID getDynamicClassID () const =0
int32_t getMatchedLength (void) const
int32_t getMatchedStart (void) const
void getMatchedText (UnicodeString &result) const
virtual int32_t getOffset (void) const =0
const UnicodeStringgetText (void) const
int32_t last (UErrorCode &status)
int32_t next (UErrorCode &status)
UBool operator!= (const SearchIterator &that) const
virtual UBool operator== (const SearchIterator &that) const
int32_t preceding (int32_t position, UErrorCode &status)
int32_t previous (UErrorCode &status)
virtual void reset ()
virtual SearchIteratorsafeClone (void) const =0
 SearchIterator (const SearchIterator &other)
void setAttribute (USearchAttribute attribute, USearchAttributeValue value, UErrorCode &status)
void setBreakIterator (BreakIterator *breakiter, UErrorCode &status)
virtual void setOffset (int32_t position, UErrorCode &status)=0
virtual void setText (const UnicodeString &text, UErrorCode &status)
virtual void setText (CharacterIterator &text, UErrorCode &status)
virtual ~SearchIterator ()

Static Public Member Functions

static void U_EXPORT2 operator delete (void *p) U_NO_THROW
static void U_EXPORT2 operator delete (void *, void *) U_NO_THROW
static void U_EXPORT2 operator delete[] (void *p) U_NO_THROW
static void *U_EXPORT2 operator new (size_t size) U_NO_THROW
static void *U_EXPORT2 operator new (size_t, void *ptr) U_NO_THROW
static void *U_EXPORT2 operator new[] (size_t size) U_NO_THROW

Protected Member Functions

virtual int32_t handleNext (int32_t position, UErrorCode &status)=0
virtual int32_t handlePrev (int32_t position, UErrorCode &status)=0
SearchIteratoroperator= (const SearchIterator &that)
 SearchIterator ()
 SearchIterator (const UnicodeString &text, BreakIterator *breakiter=NULL)
 SearchIterator (CharacterIterator &text, BreakIterator *breakiter=NULL)
virtual void setMatchLength (int32_t length)
void setMatchNotFound ()
virtual void setMatchStart (int32_t position)

Protected Attributes

BreakIteratorm_breakiterator_
USearchm_search_
UnicodeString m_text_

Detailed Description

SearchIterator is an abstract base class that provides methods to search for a pattern within a text string. Instances of SearchIterator maintain a current position and scans over the target text, returning the indices the pattern is matched and the length of each match.

SearchIterator defines a protocol for text searching. Subclasses provide concrete implementations of various search algorithms. For example, StringSearch implements language-sensitive pattern matching based on the comparison rules defined in a RuleBasedCollator object.

Other options for searching includes using a BreakIterator to restrict the points at which matches are detected.

SearchIterator provides an API that is similar to that of other text iteration classes such as BreakIterator. Using this class, it is easy to scan through text looking for all occurances of a given pattern. The following example uses a StringSearch object to find all instances of "fox" in the target string. Any other subclass of SearchIterator can be used in an identical manner.


 UnicodeString target("The quick brown fox jumped over the lazy fox");
 UnicodeString pattern("fox");
 SearchIterator *iter  = new StringSearch(pattern, target);
 UErrorCode      error = U_ZERO_ERROR;
 for (int pos = iter->first(error); pos != USEARCH_DONE; 
                               pos = iter->next(error)) {
     printf("Found match at %d pos, length is %d\n", pos, 
                                             iter.getMatchLength());
 }
 
See also:
StringSearch
RuleBasedCollator

Definition at line 79 of file search.h.


The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index