intl/icu/source/i18n/unicode/search.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/i18n/unicode/search.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,575 @@
     1.4 +/*
     1.5 +**********************************************************************
     1.6 +*   Copyright (C) 2001-2011 IBM and others. All rights reserved.
     1.7 +**********************************************************************
     1.8 +*   Date        Name        Description
     1.9 +*  03/22/2000   helena      Creation.
    1.10 +**********************************************************************
    1.11 +*/
    1.12 +
    1.13 +#ifndef SEARCH_H
    1.14 +#define SEARCH_H
    1.15 +
    1.16 +#include "unicode/utypes.h"
    1.17 +
    1.18 +/**
    1.19 + * \file 
    1.20 + * \brief C++ API: SearchIterator object.
    1.21 + */
    1.22 + 
    1.23 +#if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
    1.24 +
    1.25 +#include "unicode/uobject.h"
    1.26 +#include "unicode/unistr.h"
    1.27 +#include "unicode/chariter.h"
    1.28 +#include "unicode/brkiter.h"
    1.29 +#include "unicode/usearch.h"
    1.30 +
    1.31 +/**
    1.32 +* @stable ICU 2.0
    1.33 +*/
    1.34 +struct USearch;
    1.35 +/**
    1.36 +* @stable ICU 2.0
    1.37 +*/
    1.38 +typedef struct USearch USearch;
    1.39 +
    1.40 +U_NAMESPACE_BEGIN
    1.41 +
    1.42 +/**
    1.43 + *
    1.44 + * <tt>SearchIterator</tt> is an abstract base class that provides 
    1.45 + * methods to search for a pattern within a text string. Instances of
    1.46 + * <tt>SearchIterator</tt> maintain a current position and scans over the 
    1.47 + * target text, returning the indices the pattern is matched and the length 
    1.48 + * of each match.
    1.49 + * <p>
    1.50 + * <tt>SearchIterator</tt> defines a protocol for text searching. 
    1.51 + * Subclasses provide concrete implementations of various search algorithms. 
    1.52 + * For example, <tt>StringSearch</tt> implements language-sensitive pattern 
    1.53 + * matching based on the comparison rules defined in a 
    1.54 + * <tt>RuleBasedCollator</tt> object. 
    1.55 + * <p> 
    1.56 + * Other options for searching includes using a BreakIterator to restrict 
    1.57 + * the points at which matches are detected.
    1.58 + * <p>
    1.59 + * <tt>SearchIterator</tt> provides an API that is similar to that of
    1.60 + * other text iteration classes such as <tt>BreakIterator</tt>. Using 
    1.61 + * this class, it is easy to scan through text looking for all occurances of 
    1.62 + * a given pattern. The following example uses a <tt>StringSearch</tt> 
    1.63 + * object to find all instances of "fox" in the target string. Any other 
    1.64 + * subclass of <tt>SearchIterator</tt> can be used in an identical 
    1.65 + * manner.
    1.66 + * <pre><code>
    1.67 + * UnicodeString target("The quick brown fox jumped over the lazy fox");
    1.68 + * UnicodeString pattern("fox");
    1.69 + *
    1.70 + * SearchIterator *iter  = new StringSearch(pattern, target);
    1.71 + * UErrorCode      error = U_ZERO_ERROR;
    1.72 + * for (int pos = iter->first(error); pos != USEARCH_DONE; 
    1.73 + *                               pos = iter->next(error)) {
    1.74 + *     printf("Found match at %d pos, length is %d\n", pos, 
    1.75 + *                                             iter.getMatchLength());
    1.76 + * }
    1.77 + * </code></pre>
    1.78 + *
    1.79 + * @see StringSearch
    1.80 + * @see RuleBasedCollator
    1.81 + */
    1.82 +class U_I18N_API SearchIterator : public UObject {
    1.83 +
    1.84 +public:
    1.85 +
    1.86 +    // public constructors and destructors -------------------------------
    1.87 +
    1.88 +    /** 
    1.89 +    * Copy constructor that creates a SearchIterator instance with the same 
    1.90 +    * behavior, and iterating over the same text. 
    1.91 +    * @param other the SearchIterator instance to be copied.
    1.92 +    * @stable ICU 2.0
    1.93 +    */
    1.94 +    SearchIterator(const SearchIterator &other);
    1.95 +
    1.96 +    /**
    1.97 +     * Destructor. Cleans up the search iterator data struct.
    1.98 +     * @stable ICU 2.0
    1.99 +     */
   1.100 +    virtual ~SearchIterator();
   1.101 +
   1.102 +    // public get and set methods ----------------------------------------
   1.103 +
   1.104 +    /**
   1.105 +     * Sets the index to point to the given position, and clears any state 
   1.106 +     * that's affected.
   1.107 +     * <p>
   1.108 +     * This method takes the argument index and sets the position in the text 
   1.109 +     * string accordingly without checking if the index is pointing to a 
   1.110 +     * valid starting point to begin searching. 
   1.111 +     * @param position within the text to be set. If position is less
   1.112 +     *             than or greater than the text range for searching, 
   1.113 +     *          an U_INDEX_OUTOFBOUNDS_ERROR will be returned
   1.114 +     * @param status for errors if it occurs
   1.115 +     * @stable ICU 2.0
   1.116 +     */
   1.117 +    virtual void setOffset(int32_t position, UErrorCode &status) = 0;
   1.118 +
   1.119 +    /**
   1.120 +     * Return the current index in the text being searched.
   1.121 +     * If the iteration has gone past the end of the text
   1.122 +     * (or past the beginning for a backwards search), USEARCH_DONE
   1.123 +     * is returned.
   1.124 +     * @return current index in the text being searched.
   1.125 +     * @stable ICU 2.0
   1.126 +     */
   1.127 +    virtual int32_t getOffset(void) const = 0;
   1.128 +
   1.129 +    /**
   1.130 +    * Sets the text searching attributes located in the enum 
   1.131 +    * USearchAttribute with values from the enum USearchAttributeValue.
   1.132 +    * USEARCH_DEFAULT can be used for all attributes for resetting.
   1.133 +    * @param attribute text attribute (enum USearchAttribute) to be set
   1.134 +    * @param value text attribute value
   1.135 +    * @param status for errors if it occurs
   1.136 +    * @stable ICU 2.0
   1.137 +    */
   1.138 +    void setAttribute(USearchAttribute       attribute,
   1.139 +                      USearchAttributeValue  value,
   1.140 +                      UErrorCode            &status);
   1.141 +
   1.142 +    /**    
   1.143 +    * Gets the text searching attributes
   1.144 +    * @param attribute text attribute (enum USearchAttribute) to be retrieve
   1.145 +    * @return text attribute value
   1.146 +    * @stable ICU 2.0
   1.147 +    */
   1.148 +    USearchAttributeValue getAttribute(USearchAttribute  attribute) const;
   1.149 +    
   1.150 +    /**
   1.151 +    * Returns the index to the match in the text string that was searched.
   1.152 +    * This call returns a valid result only after a successful call to 
   1.153 +    * <tt>first</tt>, <tt>next</tt>, <tt>previous</tt>, or <tt>last</tt>.
   1.154 +    * Just after construction, or after a searching method returns 
   1.155 +    * <tt>USEARCH_DONE</tt>, this method will return <tt>USEARCH_DONE</tt>.
   1.156 +    * <p>
   1.157 +    * Use getMatchedLength to get the matched string length.
   1.158 +    * @return index of a substring within the text string that is being 
   1.159 +    *         searched.
   1.160 +    * @see #first
   1.161 +    * @see #next
   1.162 +    * @see #previous
   1.163 +    * @see #last
   1.164 +    * @stable ICU 2.0
   1.165 +    */
   1.166 +    int32_t getMatchedStart(void) const;
   1.167 +
   1.168 +    /**
   1.169 +     * Returns the length of text in the string which matches the search 
   1.170 +     * pattern. This call returns a valid result only after a successful call 
   1.171 +     * to <tt>first</tt>, <tt>next</tt>, <tt>previous</tt>, or <tt>last</tt>.
   1.172 +     * Just after construction, or after a searching method returns 
   1.173 +     * <tt>USEARCH_DONE</tt>, this method will return 0.
   1.174 +     * @return The length of the match in the target text, or 0 if there
   1.175 +     *         is no match currently.
   1.176 +     * @see #first
   1.177 +     * @see #next
   1.178 +     * @see #previous
   1.179 +     * @see #last
   1.180 +     * @stable ICU 2.0
   1.181 +     */
   1.182 +    int32_t getMatchedLength(void) const;
   1.183 +    
   1.184 +    /**
   1.185 +     * Returns the text that was matched by the most recent call to 
   1.186 +     * <tt>first</tt>, <tt>next</tt>, <tt>previous</tt>, or <tt>last</tt>.
   1.187 +     * If the iterator is not pointing at a valid match (e.g. just after 
   1.188 +     * construction or after <tt>USEARCH_DONE</tt> has been returned, 
   1.189 +     * returns an empty string. 
   1.190 +     * @param result stores the matched string or an empty string if a match
   1.191 +     *        is not found.
   1.192 +     * @see #first
   1.193 +     * @see #next
   1.194 +     * @see #previous
   1.195 +     * @see #last
   1.196 +     * @stable ICU 2.0
   1.197 +     */
   1.198 +    void getMatchedText(UnicodeString &result) const;
   1.199 +    
   1.200 +    /**
   1.201 +     * Set the BreakIterator that will be used to restrict the points
   1.202 +     * at which matches are detected. The user is responsible for deleting 
   1.203 +     * the breakiterator.
   1.204 +     * @param breakiter A BreakIterator that will be used to restrict the 
   1.205 +     *                points at which matches are detected. If a match is 
   1.206 +     *                found, but the match's start or end index is not a 
   1.207 +     *                boundary as determined by the <tt>BreakIterator</tt>, 
   1.208 +     *                the match will be rejected and another will be searched 
   1.209 +     *                for. If this parameter is <tt>NULL</tt>, no break
   1.210 +     *                detection is attempted.
   1.211 +     * @param status for errors if it occurs
   1.212 +     * @see BreakIterator
   1.213 +     * @stable ICU 2.0
   1.214 +     */
   1.215 +    void setBreakIterator(BreakIterator *breakiter, UErrorCode &status);
   1.216 +    
   1.217 +    /**
   1.218 +     * Returns the BreakIterator that is used to restrict the points at 
   1.219 +     * which matches are detected.  This will be the same object that was 
   1.220 +     * passed to the constructor or to <tt>setBreakIterator</tt>.
   1.221 +     * Note that <tt>NULL</tt> is a legal value; it means that break
   1.222 +     * detection should not be attempted.
   1.223 +     * @return BreakIterator used to restrict matchings.
   1.224 +     * @see #setBreakIterator
   1.225 +     * @stable ICU 2.0
   1.226 +     */
   1.227 +    const BreakIterator * getBreakIterator(void) const;
   1.228 +
   1.229 +    /**
   1.230 +     * Set the string text to be searched. Text iteration will hence begin at 
   1.231 +     * the start of the text string. This method is useful if you want to 
   1.232 +     * re-use an iterator to search for the same pattern within a different 
   1.233 +     * body of text. The user is responsible for deleting the text.
   1.234 +     * @param text string to be searched.
   1.235 +     * @param status for errors. If the text length is 0, 
   1.236 +     *        an U_ILLEGAL_ARGUMENT_ERROR is returned.
   1.237 +     * @stable ICU 2.0
   1.238 +     */
   1.239 +    virtual void setText(const UnicodeString &text, UErrorCode &status);    
   1.240 +
   1.241 +    /**
   1.242 +     * Set the string text to be searched. Text iteration will hence begin at 
   1.243 +     * the start of the text string. This method is useful if you want to 
   1.244 +     * re-use an iterator to search for the same pattern within a different 
   1.245 +     * body of text.
   1.246 +     * <p>
   1.247 +     * Note: No parsing of the text within the <tt>CharacterIterator</tt> 
   1.248 +     * will be done during searching for this version. The block of text 
   1.249 +     * in <tt>CharacterIterator</tt> will be used as it is.
   1.250 +     * The user is responsible for deleting the text.
   1.251 +     * @param text string iterator to be searched.
   1.252 +     * @param status for errors if any. If the text length is 0 then an 
   1.253 +     *        U_ILLEGAL_ARGUMENT_ERROR is returned.
   1.254 +     * @stable ICU 2.0
   1.255 +     */
   1.256 +    virtual void setText(CharacterIterator &text, UErrorCode &status);
   1.257 +    
   1.258 +    /**
   1.259 +     * Return the string text to be searched.
   1.260 +     * @return text string to be searched.
   1.261 +     * @stable ICU 2.0
   1.262 +     */
   1.263 +    const UnicodeString & getText(void) const;
   1.264 +
   1.265 +    // operator overloading ----------------------------------------------
   1.266 +
   1.267 +    /**
   1.268 +     * Equality operator. 
   1.269 +     * @param that SearchIterator instance to be compared.
   1.270 +     * @return TRUE if both BreakIterators are of the same class, have the 
   1.271 +     *         same behavior, terates over the same text and have the same
   1.272 +     *         attributes. FALSE otherwise.
   1.273 +     * @stable ICU 2.0
   1.274 +     */
   1.275 +    virtual UBool operator==(const SearchIterator &that) const;
   1.276 +
   1.277 +    /**
   1.278 +     * Not-equal operator. 
   1.279 +     * @param that SearchIterator instance to be compared.
   1.280 +     * @return FALSE if operator== returns TRUE, and vice versa.
   1.281 +     * @stable ICU 2.0
   1.282 +     */
   1.283 +    UBool operator!=(const SearchIterator &that) const;
   1.284 +
   1.285 +    // public methods ----------------------------------------------------
   1.286 +
   1.287 +    /**
   1.288 +     * Returns a copy of SearchIterator with the same behavior, and 
   1.289 +     * iterating over the same text, as this one. Note that all data will be
   1.290 +     * replicated, except for the text string to be searched.
   1.291 +     * @return cloned object
   1.292 +     * @stable ICU 2.0
   1.293 +     */
   1.294 +    virtual SearchIterator* safeClone(void) const = 0;
   1.295 +
   1.296 +    /**
   1.297 +     * Returns the first index at which the string text matches the search 
   1.298 +     * pattern. The iterator is adjusted so that its current index (as 
   1.299 +     * returned by <tt>getOffset</tt>) is the match position if one 
   1.300 +     * was found.
   1.301 +     * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
   1.302 +     * the iterator will be adjusted to the index USEARCH_DONE
   1.303 +     * @param  status for errors if it occurs
   1.304 +     * @return The character index of the first match, or 
   1.305 +     *         <tt>USEARCH_DONE</tt> if there are no matches.
   1.306 +     * @see #getOffset
   1.307 +     * @stable ICU 2.0
   1.308 +     */
   1.309 +    int32_t first(UErrorCode &status);
   1.310 +
   1.311 +    /**
   1.312 +     * Returns the first index equal or greater than <tt>position</tt> at which the 
   1.313 +     * string text matches the search pattern. The iterator is adjusted so 
   1.314 +     * that its current index (as returned by <tt>getOffset</tt>) is the 
   1.315 +     * match position if one was found.
   1.316 +     * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and the
   1.317 +     * iterator will be adjusted to the index <tt>USEARCH_DONE</tt>.
   1.318 +     * @param  position where search if to start from. If position is less
   1.319 +     *             than or greater than the text range for searching, 
   1.320 +     *          an U_INDEX_OUTOFBOUNDS_ERROR will be returned
   1.321 +     * @param  status for errors if it occurs
   1.322 +     * @return The character index of the first match following 
   1.323 +     *         <tt>position</tt>, or <tt>USEARCH_DONE</tt> if there are no 
   1.324 +     *         matches.
   1.325 +     * @see #getOffset
   1.326 +     * @stable ICU 2.0
   1.327 +     */
   1.328 +    int32_t following(int32_t position, UErrorCode &status);
   1.329 +    
   1.330 +    /**
   1.331 +     * Returns the last index in the target text at which it matches the 
   1.332 +     * search pattern. The iterator is adjusted so that its current index 
   1.333 +     * (as returned by <tt>getOffset</tt>) is the match position if one was 
   1.334 +     * found.
   1.335 +     * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
   1.336 +     * the iterator will be adjusted to the index USEARCH_DONE.
   1.337 +     * @param  status for errors if it occurs
   1.338 +     * @return The index of the first match, or <tt>USEARCH_DONE</tt> if 
   1.339 +     *         there are no matches.
   1.340 +     * @see #getOffset
   1.341 +     * @stable ICU 2.0
   1.342 +     */
   1.343 +    int32_t last(UErrorCode &status);
   1.344 +
   1.345 +    /**
   1.346 +     * Returns the first index less than <tt>position</tt> at which the string 
   1.347 +     * text matches the search pattern. The iterator is adjusted so that its 
   1.348 +     * current index (as returned by <tt>getOffset</tt>) is the match 
   1.349 +     * position if one was found. If a match is not found, 
   1.350 +     * <tt>USEARCH_DONE</tt> will be returned and the iterator will be 
   1.351 +     * adjusted to the index USEARCH_DONE
   1.352 +     * <p>
   1.353 +     * When <tt>USEARCH_OVERLAP</tt> option is off, the last index of the
   1.354 +     * result match is always less than <tt>position</tt>.
   1.355 +     * When <tt>USERARCH_OVERLAP</tt> is on, the result match may span across
   1.356 +     * <tt>position</tt>.
   1.357 +     *
   1.358 +     * @param  position where search is to start from. If position is less
   1.359 +     *             than or greater than the text range for searching, 
   1.360 +     *          an U_INDEX_OUTOFBOUNDS_ERROR will be returned
   1.361 +     * @param  status for errors if it occurs
   1.362 +     * @return The character index of the first match preceding 
   1.363 +     *         <tt>position</tt>, or <tt>USEARCH_DONE</tt> if there are 
   1.364 +     *         no matches.
   1.365 +     * @see #getOffset
   1.366 +     * @stable ICU 2.0
   1.367 +     */
   1.368 +    int32_t preceding(int32_t position, UErrorCode &status);
   1.369 +
   1.370 +    /**
   1.371 +     * Returns the index of the next point at which the text matches the
   1.372 +     * search pattern, starting from the current position
   1.373 +     * The iterator is adjusted so that its current index (as returned by 
   1.374 +     * <tt>getOffset</tt>) is the match position if one was found.
   1.375 +     * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
   1.376 +     * the iterator will be adjusted to a position after the end of the text 
   1.377 +     * string.
   1.378 +     * @param  status for errors if it occurs
   1.379 +     * @return The index of the next match after the current position,
   1.380 +     *          or <tt>USEARCH_DONE</tt> if there are no more matches.
   1.381 +     * @see #getOffset
   1.382 +     * @stable ICU 2.0
   1.383 +     */
   1.384 +     int32_t next(UErrorCode &status);
   1.385 +
   1.386 +    /**
   1.387 +     * Returns the index of the previous point at which the string text 
   1.388 +     * matches the search pattern, starting at the current position.
   1.389 +     * The iterator is adjusted so that its current index (as returned by 
   1.390 +     * <tt>getOffset</tt>) is the match position if one was found.
   1.391 +     * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
   1.392 +     * the iterator will be adjusted to the index USEARCH_DONE
   1.393 +     * @param  status for errors if it occurs
   1.394 +     * @return The index of the previous match before the current position,
   1.395 +     *          or <tt>USEARCH_DONE</tt> if there are no more matches.
   1.396 +     * @see #getOffset
   1.397 +     * @stable ICU 2.0
   1.398 +     */
   1.399 +    int32_t previous(UErrorCode &status);
   1.400 +
   1.401 +    /** 
   1.402 +    * Resets the iteration.
   1.403 +    * Search will begin at the start of the text string if a forward 
   1.404 +    * iteration is initiated before a backwards iteration. Otherwise if a 
   1.405 +    * backwards iteration is initiated before a forwards iteration, the 
   1.406 +    * search will begin at the end of the text string.    
   1.407 +    * @stable ICU 2.0
   1.408 +    */
   1.409 +    virtual void reset();
   1.410 +
   1.411 +protected:
   1.412 +    // protected data members ---------------------------------------------
   1.413 +
   1.414 +    /**
   1.415 +    * C search data struct
   1.416 +    * @stable ICU 2.0
   1.417 +    */
   1.418 +    USearch *m_search_;
   1.419 +
   1.420 +    /**
   1.421 +    * Break iterator.
   1.422 +    * Currently the C++ breakiterator does not have getRules etc to reproduce
   1.423 +    * another in C. Hence we keep the original around and do the verification
   1.424 +    * at the end of the match. The user is responsible for deleting this
   1.425 +    * break iterator.
   1.426 +    * @stable ICU 2.0
   1.427 +    */
   1.428 +    BreakIterator *m_breakiterator_;
   1.429 +    
   1.430 +    /**
   1.431 +    * Unicode string version of the search text
   1.432 +    * @stable ICU 2.0
   1.433 +    */
   1.434 +    UnicodeString  m_text_;
   1.435 +
   1.436 +    // protected constructors and destructors -----------------------------
   1.437 +
   1.438 +    /**
   1.439 +    * Default constructor.
   1.440 +    * Initializes data to the default values.
   1.441 +    * @stable ICU 2.0
   1.442 +    */
   1.443 +    SearchIterator();
   1.444 +
   1.445 +    /**
   1.446 +     * Constructor for use by subclasses.
   1.447 +     * @param text The target text to be searched.
   1.448 +     * @param breakiter A {@link BreakIterator} that is used to restrict the 
   1.449 +     *                points at which matches are detected. If 
   1.450 +     *                <tt>handleNext</tt> or <tt>handlePrev</tt> finds a 
   1.451 +     *                match, but the match's start or end index is not a 
   1.452 +     *                boundary as determined by the <tt>BreakIterator</tt>, 
   1.453 +     *                the match is rejected and <tt>handleNext</tt> or 
   1.454 +     *                <tt>handlePrev</tt> is called again. If this parameter 
   1.455 +     *                is <tt>NULL</tt>, no break detection is attempted.  
   1.456 +     * @see #handleNext
   1.457 +     * @see #handlePrev
   1.458 +     * @stable ICU 2.0
   1.459 +     */
   1.460 +    SearchIterator(const UnicodeString &text, 
   1.461 +                         BreakIterator *breakiter = NULL);
   1.462 +
   1.463 +    /**
   1.464 +     * Constructor for use by subclasses.
   1.465 +     * <p>
   1.466 +     * Note: No parsing of the text within the <tt>CharacterIterator</tt> 
   1.467 +     * will be done during searching for this version. The block of text 
   1.468 +     * in <tt>CharacterIterator</tt> will be used as it is.
   1.469 +     * @param text The target text to be searched.
   1.470 +     * @param breakiter A {@link BreakIterator} that is used to restrict the 
   1.471 +     *                points at which matches are detected. If 
   1.472 +     *                <tt>handleNext</tt> or <tt>handlePrev</tt> finds a 
   1.473 +     *                match, but the match's start or end index is not a 
   1.474 +     *                boundary as determined by the <tt>BreakIterator</tt>, 
   1.475 +     *                the match is rejected and <tt>handleNext</tt> or 
   1.476 +     *                <tt>handlePrev</tt> is called again. If this parameter 
   1.477 +     *                is <tt>NULL</tt>, no break detection is attempted.
   1.478 +     * @see #handleNext
   1.479 +     * @see #handlePrev
   1.480 +     * @stable ICU 2.0
   1.481 +     */
   1.482 +    SearchIterator(CharacterIterator &text, BreakIterator *breakiter = NULL);
   1.483 +
   1.484 +    // protected methods --------------------------------------------------
   1.485 +
   1.486 +    /**
   1.487 +     * Assignment operator. Sets this iterator to have the same behavior,
   1.488 +     * and iterate over the same text, as the one passed in.
   1.489 +     * @param that instance to be copied.
   1.490 +     * @stable ICU 2.0
   1.491 +     */
   1.492 +    SearchIterator & operator=(const SearchIterator &that);
   1.493 +
   1.494 +    /**
   1.495 +     * Abstract method which subclasses override to provide the mechanism
   1.496 +     * for finding the next match in the target text. This allows different
   1.497 +     * subclasses to provide different search algorithms.
   1.498 +     * <p>
   1.499 +     * If a match is found, the implementation should return the index at
   1.500 +     * which the match starts and should call 
   1.501 +     * <tt>setMatchLength</tt> with the number of characters 
   1.502 +     * in the target text that make up the match. If no match is found, the 
   1.503 +     * method should return USEARCH_DONE.
   1.504 +     * <p>
   1.505 +     * @param position The index in the target text at which the search 
   1.506 +     *                 should start.
   1.507 +     * @param status for error codes if it occurs.
   1.508 +     * @return index at which the match starts, else if match is not found 
   1.509 +     *         USEARCH_DONE is returned
   1.510 +     * @see #setMatchLength
   1.511 +     * @stable ICU 2.0
   1.512 +     */
   1.513 +    virtual int32_t handleNext(int32_t position, UErrorCode &status) 
   1.514 +                                                                         = 0;
   1.515 +
   1.516 +    /**
   1.517 +     * Abstract method which subclasses override to provide the mechanism for
   1.518 +     * finding the previous match in the target text. This allows different
   1.519 +     * subclasses to provide different search algorithms.
   1.520 +     * <p>
   1.521 +     * If a match is found, the implementation should return the index at
   1.522 +     * which the match starts and should call 
   1.523 +     * <tt>setMatchLength</tt> with the number of characters 
   1.524 +     * in the target text that make up the match. If no match is found, the 
   1.525 +     * method should return USEARCH_DONE.
   1.526 +     * <p>
   1.527 +     * @param position The index in the target text at which the search 
   1.528 +     *                 should start.
   1.529 +     * @param status for error codes if it occurs.
   1.530 +     * @return index at which the match starts, else if match is not found 
   1.531 +     *         USEARCH_DONE is returned
   1.532 +     * @see #setMatchLength
   1.533 +     * @stable ICU 2.0
   1.534 +     */
   1.535 +     virtual int32_t handlePrev(int32_t position, UErrorCode &status) 
   1.536 +                                                                         = 0;
   1.537 +
   1.538 +    /**
   1.539 +     * Sets the length of the currently matched string in the text string to
   1.540 +     * be searched.
   1.541 +     * Subclasses' <tt>handleNext</tt> and <tt>handlePrev</tt>
   1.542 +     * methods should call this when they find a match in the target text.
   1.543 +     * @param length length of the matched text.
   1.544 +     * @see #handleNext
   1.545 +     * @see #handlePrev
   1.546 +     * @stable ICU 2.0
   1.547 +     */
   1.548 +    virtual void setMatchLength(int32_t length);
   1.549 +
   1.550 +    /**
   1.551 +     * Sets the offset of the currently matched string in the text string to
   1.552 +     * be searched.
   1.553 +     * Subclasses' <tt>handleNext</tt> and <tt>handlePrev</tt>
   1.554 +     * methods should call this when they find a match in the target text.
   1.555 +     * @param position start offset of the matched text.
   1.556 +     * @see #handleNext
   1.557 +     * @see #handlePrev
   1.558 +     * @stable ICU 2.0
   1.559 +     */
   1.560 +    virtual void setMatchStart(int32_t position);
   1.561 +
   1.562 +    /**
   1.563 +    * sets match not found 
   1.564 +    * @stable ICU 2.0
   1.565 +    */
   1.566 +    void setMatchNotFound();
   1.567 +};
   1.568 +
   1.569 +inline UBool SearchIterator::operator!=(const SearchIterator &that) const
   1.570 +{
   1.571 +   return !operator==(that); 
   1.572 +}
   1.573 +U_NAMESPACE_END
   1.574 +
   1.575 +#endif /* #if !UCONFIG_NO_COLLATION */
   1.576 +
   1.577 +#endif
   1.578 +

mercurial