Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | ********************************************************************** |
michael@0 | 3 | * Copyright (C) 2001-2008 IBM and others. All rights reserved. |
michael@0 | 4 | ********************************************************************** |
michael@0 | 5 | * Date Name Description |
michael@0 | 6 | * 03/22/2000 helena Creation. |
michael@0 | 7 | ********************************************************************** |
michael@0 | 8 | */ |
michael@0 | 9 | |
michael@0 | 10 | #ifndef STSEARCH_H |
michael@0 | 11 | #define STSEARCH_H |
michael@0 | 12 | |
michael@0 | 13 | #include "unicode/utypes.h" |
michael@0 | 14 | |
michael@0 | 15 | /** |
michael@0 | 16 | * \file |
michael@0 | 17 | * \brief C++ API: Service for searching text based on RuleBasedCollator. |
michael@0 | 18 | */ |
michael@0 | 19 | |
michael@0 | 20 | #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION |
michael@0 | 21 | |
michael@0 | 22 | #include "unicode/tblcoll.h" |
michael@0 | 23 | #include "unicode/coleitr.h" |
michael@0 | 24 | #include "unicode/search.h" |
michael@0 | 25 | |
michael@0 | 26 | U_NAMESPACE_BEGIN |
michael@0 | 27 | |
michael@0 | 28 | /** |
michael@0 | 29 | * |
michael@0 | 30 | * <tt>StringSearch</tt> is a <tt>SearchIterator</tt> that provides |
michael@0 | 31 | * language-sensitive text searching based on the comparison rules defined |
michael@0 | 32 | * in a {@link RuleBasedCollator} object. |
michael@0 | 33 | * StringSearch ensures that language eccentricity can be |
michael@0 | 34 | * handled, e.g. for the German collator, characters ß and SS will be matched |
michael@0 | 35 | * if case is chosen to be ignored. |
michael@0 | 36 | * See the <a href="http://source.icu-project.org/repos/icu/icuhtml/trunk/design/collation/ICU_collation_design.htm"> |
michael@0 | 37 | * "ICU Collation Design Document"</a> for more information. |
michael@0 | 38 | * <p> |
michael@0 | 39 | * The algorithm implemented is a modified form of the Boyer Moore's search. |
michael@0 | 40 | * For more information see |
michael@0 | 41 | * <a href="http://icu-project.org/docs/papers/efficient_text_searching_in_java.html"> |
michael@0 | 42 | * "Efficient Text Searching in Java"</a>, published in <i>Java Report</i> |
michael@0 | 43 | * in February, 1999, for further information on the algorithm. |
michael@0 | 44 | * <p> |
michael@0 | 45 | * There are 2 match options for selection:<br> |
michael@0 | 46 | * Let S' be the sub-string of a text string S between the offsets start and |
michael@0 | 47 | * end <start, end>. |
michael@0 | 48 | * <br> |
michael@0 | 49 | * A pattern string P matches a text string S at the offsets <start, end> |
michael@0 | 50 | * if |
michael@0 | 51 | * <pre> |
michael@0 | 52 | * option 1. Some canonical equivalent of P matches some canonical equivalent |
michael@0 | 53 | * of S' |
michael@0 | 54 | * option 2. P matches S' and if P starts or ends with a combining mark, |
michael@0 | 55 | * there exists no non-ignorable combining mark before or after S? |
michael@0 | 56 | * in S respectively. |
michael@0 | 57 | * </pre> |
michael@0 | 58 | * Option 2. will be the default. |
michael@0 | 59 | * <p> |
michael@0 | 60 | * This search has APIs similar to that of other text iteration mechanisms |
michael@0 | 61 | * such as the break iterators in <tt>BreakIterator</tt>. Using these |
michael@0 | 62 | * APIs, it is easy to scan through text looking for all occurances of |
michael@0 | 63 | * a given pattern. This search iterator allows changing of direction by |
michael@0 | 64 | * calling a <tt>reset</tt> followed by a <tt>next</tt> or <tt>previous</tt>. |
michael@0 | 65 | * Though a direction change can occur without calling <tt>reset</tt> first, |
michael@0 | 66 | * this operation comes with some speed penalty. |
michael@0 | 67 | * Match results in the forward direction will match the result matches in |
michael@0 | 68 | * the backwards direction in the reverse order |
michael@0 | 69 | * <p> |
michael@0 | 70 | * <tt>SearchIterator</tt> provides APIs to specify the starting position |
michael@0 | 71 | * within the text string to be searched, e.g. <tt>setOffset</tt>, |
michael@0 | 72 | * <tt>preceding</tt> and <tt>following</tt>. Since the |
michael@0 | 73 | * starting position will be set as it is specified, please take note that |
michael@0 | 74 | * there are some danger points which the search may render incorrect |
michael@0 | 75 | * results: |
michael@0 | 76 | * <ul> |
michael@0 | 77 | * <li> The midst of a substring that requires normalization. |
michael@0 | 78 | * <li> If the following match is to be found, the position should not be the |
michael@0 | 79 | * second character which requires to be swapped with the preceding |
michael@0 | 80 | * character. Vice versa, if the preceding match is to be found, |
michael@0 | 81 | * position to search from should not be the first character which |
michael@0 | 82 | * requires to be swapped with the next character. E.g certain Thai and |
michael@0 | 83 | * Lao characters require swapping. |
michael@0 | 84 | * <li> If a following pattern match is to be found, any position within a |
michael@0 | 85 | * contracting sequence except the first will fail. Vice versa if a |
michael@0 | 86 | * preceding pattern match is to be found, a invalid starting point |
michael@0 | 87 | * would be any character within a contracting sequence except the last. |
michael@0 | 88 | * </ul> |
michael@0 | 89 | * <p> |
michael@0 | 90 | * A breakiterator can be used if only matches at logical breaks are desired. |
michael@0 | 91 | * Using a breakiterator will only give you results that exactly matches the |
michael@0 | 92 | * boundaries given by the breakiterator. For instance the pattern "e" will |
michael@0 | 93 | * not be found in the string "\u00e9" if a character break iterator is used. |
michael@0 | 94 | * <p> |
michael@0 | 95 | * Options are provided to handle overlapping matches. |
michael@0 | 96 | * E.g. In English, overlapping matches produces the result 0 and 2 |
michael@0 | 97 | * for the pattern "abab" in the text "ababab", where else mutually |
michael@0 | 98 | * exclusive matches only produce the result of 0. |
michael@0 | 99 | * <p> |
michael@0 | 100 | * Though collator attributes will be taken into consideration while |
michael@0 | 101 | * performing matches, there are no APIs here for setting and getting the |
michael@0 | 102 | * attributes. These attributes can be set by getting the collator |
michael@0 | 103 | * from <tt>getCollator</tt> and using the APIs in <tt>coll.h</tt>. |
michael@0 | 104 | * Lastly to update StringSearch to the new collator attributes, |
michael@0 | 105 | * reset() has to be called. |
michael@0 | 106 | * <p> |
michael@0 | 107 | * Restriction: <br> |
michael@0 | 108 | * Currently there are no composite characters that consists of a |
michael@0 | 109 | * character with combining class > 0 before a character with combining |
michael@0 | 110 | * class == 0. However, if such a character exists in the future, |
michael@0 | 111 | * StringSearch does not guarantee the results for option 1. |
michael@0 | 112 | * <p> |
michael@0 | 113 | * Consult the <tt>SearchIterator</tt> documentation for information on |
michael@0 | 114 | * and examples of how to use instances of this class to implement text |
michael@0 | 115 | * searching. |
michael@0 | 116 | * <pre><code> |
michael@0 | 117 | * UnicodeString target("The quick brown fox jumps over the lazy dog."); |
michael@0 | 118 | * UnicodeString pattern("fox"); |
michael@0 | 119 | * |
michael@0 | 120 | * UErrorCode error = U_ZERO_ERROR; |
michael@0 | 121 | * StringSearch iter(pattern, target, Locale::getUS(), NULL, status); |
michael@0 | 122 | * for (int pos = iter.first(error); |
michael@0 | 123 | * pos != USEARCH_DONE; |
michael@0 | 124 | * pos = iter.next(error)) |
michael@0 | 125 | * { |
michael@0 | 126 | * printf("Found match at %d pos, length is %d\n", pos, |
michael@0 | 127 | * iter.getMatchLength()); |
michael@0 | 128 | * } |
michael@0 | 129 | * </code></pre> |
michael@0 | 130 | * <p> |
michael@0 | 131 | * Note, StringSearch is not to be subclassed. |
michael@0 | 132 | * </p> |
michael@0 | 133 | * @see SearchIterator |
michael@0 | 134 | * @see RuleBasedCollator |
michael@0 | 135 | * @since ICU 2.0 |
michael@0 | 136 | */ |
michael@0 | 137 | |
michael@0 | 138 | class U_I18N_API StringSearch : public SearchIterator |
michael@0 | 139 | { |
michael@0 | 140 | public: |
michael@0 | 141 | |
michael@0 | 142 | // public constructors and destructors -------------------------------- |
michael@0 | 143 | |
michael@0 | 144 | /** |
michael@0 | 145 | * Creating a <tt>StringSearch</tt> instance using the argument locale |
michael@0 | 146 | * language rule set. A collator will be created in the process, which |
michael@0 | 147 | * will be owned by this instance and will be deleted during |
michael@0 | 148 | * destruction |
michael@0 | 149 | * @param pattern The text for which this object will search. |
michael@0 | 150 | * @param text The text in which to search for the pattern. |
michael@0 | 151 | * @param locale A locale which defines the language-sensitive |
michael@0 | 152 | * comparison rules used to determine whether text in the |
michael@0 | 153 | * pattern and target matches. |
michael@0 | 154 | * @param breakiter A <tt>BreakIterator</tt> object used to constrain |
michael@0 | 155 | * the matches that are found. Matches whose start and end |
michael@0 | 156 | * indices in the target text are not boundaries as |
michael@0 | 157 | * determined by the <tt>BreakIterator</tt> are |
michael@0 | 158 | * ignored. If this behavior is not desired, |
michael@0 | 159 | * <tt>NULL</tt> can be passed in instead. |
michael@0 | 160 | * @param status for errors if any. If pattern or text is NULL, or if |
michael@0 | 161 | * either the length of pattern or text is 0 then an |
michael@0 | 162 | * U_ILLEGAL_ARGUMENT_ERROR is returned. |
michael@0 | 163 | * @stable ICU 2.0 |
michael@0 | 164 | */ |
michael@0 | 165 | StringSearch(const UnicodeString &pattern, const UnicodeString &text, |
michael@0 | 166 | const Locale &locale, |
michael@0 | 167 | BreakIterator *breakiter, |
michael@0 | 168 | UErrorCode &status); |
michael@0 | 169 | |
michael@0 | 170 | /** |
michael@0 | 171 | * Creating a <tt>StringSearch</tt> instance using the argument collator |
michael@0 | 172 | * language rule set. Note, user retains the ownership of this collator, |
michael@0 | 173 | * it does not get destroyed during this instance's destruction. |
michael@0 | 174 | * @param pattern The text for which this object will search. |
michael@0 | 175 | * @param text The text in which to search for the pattern. |
michael@0 | 176 | * @param coll A <tt>RuleBasedCollator</tt> object which defines |
michael@0 | 177 | * the language-sensitive comparison rules used to |
michael@0 | 178 | * determine whether text in the pattern and target |
michael@0 | 179 | * matches. User is responsible for the clearing of this |
michael@0 | 180 | * object. |
michael@0 | 181 | * @param breakiter A <tt>BreakIterator</tt> object used to constrain |
michael@0 | 182 | * the matches that are found. Matches whose start and end |
michael@0 | 183 | * indices in the target text are not boundaries as |
michael@0 | 184 | * determined by the <tt>BreakIterator</tt> are |
michael@0 | 185 | * ignored. If this behavior is not desired, |
michael@0 | 186 | * <tt>NULL</tt> can be passed in instead. |
michael@0 | 187 | * @param status for errors if any. If either the length of pattern or |
michael@0 | 188 | * text is 0 then an U_ILLEGAL_ARGUMENT_ERROR is returned. |
michael@0 | 189 | * @stable ICU 2.0 |
michael@0 | 190 | */ |
michael@0 | 191 | StringSearch(const UnicodeString &pattern, |
michael@0 | 192 | const UnicodeString &text, |
michael@0 | 193 | RuleBasedCollator *coll, |
michael@0 | 194 | BreakIterator *breakiter, |
michael@0 | 195 | UErrorCode &status); |
michael@0 | 196 | |
michael@0 | 197 | /** |
michael@0 | 198 | * Creating a <tt>StringSearch</tt> instance using the argument locale |
michael@0 | 199 | * language rule set. A collator will be created in the process, which |
michael@0 | 200 | * will be owned by this instance and will be deleted during |
michael@0 | 201 | * destruction |
michael@0 | 202 | * <p> |
michael@0 | 203 | * Note: No parsing of the text within the <tt>CharacterIterator</tt> |
michael@0 | 204 | * will be done during searching for this version. The block of text |
michael@0 | 205 | * in <tt>CharacterIterator</tt> will be used as it is. |
michael@0 | 206 | * @param pattern The text for which this object will search. |
michael@0 | 207 | * @param text The text iterator in which to search for the pattern. |
michael@0 | 208 | * @param locale A locale which defines the language-sensitive |
michael@0 | 209 | * comparison rules used to determine whether text in the |
michael@0 | 210 | * pattern and target matches. User is responsible for |
michael@0 | 211 | * the clearing of this object. |
michael@0 | 212 | * @param breakiter A <tt>BreakIterator</tt> object used to constrain |
michael@0 | 213 | * the matches that are found. Matches whose start and end |
michael@0 | 214 | * indices in the target text are not boundaries as |
michael@0 | 215 | * determined by the <tt>BreakIterator</tt> are |
michael@0 | 216 | * ignored. If this behavior is not desired, |
michael@0 | 217 | * <tt>NULL</tt> can be passed in instead. |
michael@0 | 218 | * @param status for errors if any. If either the length of pattern or |
michael@0 | 219 | * text is 0 then an U_ILLEGAL_ARGUMENT_ERROR is returned. |
michael@0 | 220 | * @stable ICU 2.0 |
michael@0 | 221 | */ |
michael@0 | 222 | StringSearch(const UnicodeString &pattern, CharacterIterator &text, |
michael@0 | 223 | const Locale &locale, |
michael@0 | 224 | BreakIterator *breakiter, |
michael@0 | 225 | UErrorCode &status); |
michael@0 | 226 | |
michael@0 | 227 | /** |
michael@0 | 228 | * Creating a <tt>StringSearch</tt> instance using the argument collator |
michael@0 | 229 | * language rule set. Note, user retains the ownership of this collator, |
michael@0 | 230 | * it does not get destroyed during this instance's destruction. |
michael@0 | 231 | * <p> |
michael@0 | 232 | * Note: No parsing of the text within the <tt>CharacterIterator</tt> |
michael@0 | 233 | * will be done during searching for this version. The block of text |
michael@0 | 234 | * in <tt>CharacterIterator</tt> will be used as it is. |
michael@0 | 235 | * @param pattern The text for which this object will search. |
michael@0 | 236 | * @param text The text in which to search for the pattern. |
michael@0 | 237 | * @param coll A <tt>RuleBasedCollator</tt> object which defines |
michael@0 | 238 | * the language-sensitive comparison rules used to |
michael@0 | 239 | * determine whether text in the pattern and target |
michael@0 | 240 | * matches. User is responsible for the clearing of this |
michael@0 | 241 | * object. |
michael@0 | 242 | * @param breakiter A <tt>BreakIterator</tt> object used to constrain |
michael@0 | 243 | * the matches that are found. Matches whose start and end |
michael@0 | 244 | * indices in the target text are not boundaries as |
michael@0 | 245 | * determined by the <tt>BreakIterator</tt> are |
michael@0 | 246 | * ignored. If this behavior is not desired, |
michael@0 | 247 | * <tt>NULL</tt> can be passed in instead. |
michael@0 | 248 | * @param status for errors if any. If either the length of pattern or |
michael@0 | 249 | * text is 0 then an U_ILLEGAL_ARGUMENT_ERROR is returned. |
michael@0 | 250 | * @stable ICU 2.0 |
michael@0 | 251 | */ |
michael@0 | 252 | StringSearch(const UnicodeString &pattern, CharacterIterator &text, |
michael@0 | 253 | RuleBasedCollator *coll, |
michael@0 | 254 | BreakIterator *breakiter, |
michael@0 | 255 | UErrorCode &status); |
michael@0 | 256 | |
michael@0 | 257 | /** |
michael@0 | 258 | * Copy constructor that creates a StringSearch instance with the same |
michael@0 | 259 | * behavior, and iterating over the same text. |
michael@0 | 260 | * @param that StringSearch instance to be copied. |
michael@0 | 261 | * @stable ICU 2.0 |
michael@0 | 262 | */ |
michael@0 | 263 | StringSearch(const StringSearch &that); |
michael@0 | 264 | |
michael@0 | 265 | /** |
michael@0 | 266 | * Destructor. Cleans up the search iterator data struct. |
michael@0 | 267 | * If a collator is created in the constructor, it will be destroyed here. |
michael@0 | 268 | * @stable ICU 2.0 |
michael@0 | 269 | */ |
michael@0 | 270 | virtual ~StringSearch(void); |
michael@0 | 271 | |
michael@0 | 272 | /** |
michael@0 | 273 | * Clone this object. |
michael@0 | 274 | * Clones can be used concurrently in multiple threads. |
michael@0 | 275 | * If an error occurs, then NULL is returned. |
michael@0 | 276 | * The caller must delete the clone. |
michael@0 | 277 | * |
michael@0 | 278 | * @return a clone of this object |
michael@0 | 279 | * |
michael@0 | 280 | * @see getDynamicClassID |
michael@0 | 281 | * @stable ICU 2.8 |
michael@0 | 282 | */ |
michael@0 | 283 | StringSearch *clone() const; |
michael@0 | 284 | |
michael@0 | 285 | // operator overloading --------------------------------------------- |
michael@0 | 286 | |
michael@0 | 287 | /** |
michael@0 | 288 | * Assignment operator. Sets this iterator to have the same behavior, |
michael@0 | 289 | * and iterate over the same text, as the one passed in. |
michael@0 | 290 | * @param that instance to be copied. |
michael@0 | 291 | * @stable ICU 2.0 |
michael@0 | 292 | */ |
michael@0 | 293 | StringSearch & operator=(const StringSearch &that); |
michael@0 | 294 | |
michael@0 | 295 | /** |
michael@0 | 296 | * Equality operator. |
michael@0 | 297 | * @param that instance to be compared. |
michael@0 | 298 | * @return TRUE if both instances have the same attributes, |
michael@0 | 299 | * breakiterators, collators and iterate over the same text |
michael@0 | 300 | * while looking for the same pattern. |
michael@0 | 301 | * @stable ICU 2.0 |
michael@0 | 302 | */ |
michael@0 | 303 | virtual UBool operator==(const SearchIterator &that) const; |
michael@0 | 304 | |
michael@0 | 305 | // public get and set methods ---------------------------------------- |
michael@0 | 306 | |
michael@0 | 307 | /** |
michael@0 | 308 | * Sets the index to point to the given position, and clears any state |
michael@0 | 309 | * that's affected. |
michael@0 | 310 | * <p> |
michael@0 | 311 | * This method takes the argument index and sets the position in the text |
michael@0 | 312 | * string accordingly without checking if the index is pointing to a |
michael@0 | 313 | * valid starting point to begin searching. |
michael@0 | 314 | * @param position within the text to be set. If position is less |
michael@0 | 315 | * than or greater than the text range for searching, |
michael@0 | 316 | * an U_INDEX_OUTOFBOUNDS_ERROR will be returned |
michael@0 | 317 | * @param status for errors if it occurs |
michael@0 | 318 | * @stable ICU 2.0 |
michael@0 | 319 | */ |
michael@0 | 320 | virtual void setOffset(int32_t position, UErrorCode &status); |
michael@0 | 321 | |
michael@0 | 322 | /** |
michael@0 | 323 | * Return the current index in the text being searched. |
michael@0 | 324 | * If the iteration has gone past the end of the text |
michael@0 | 325 | * (or past the beginning for a backwards search), USEARCH_DONE |
michael@0 | 326 | * is returned. |
michael@0 | 327 | * @return current index in the text being searched. |
michael@0 | 328 | * @stable ICU 2.0 |
michael@0 | 329 | */ |
michael@0 | 330 | virtual int32_t getOffset(void) const; |
michael@0 | 331 | |
michael@0 | 332 | /** |
michael@0 | 333 | * Set the target text to be searched. |
michael@0 | 334 | * Text iteration will hence begin at the start of the text string. |
michael@0 | 335 | * This method is |
michael@0 | 336 | * useful if you want to re-use an iterator to search for the same |
michael@0 | 337 | * pattern within a different body of text. |
michael@0 | 338 | * @param text text string to be searched |
michael@0 | 339 | * @param status for errors if any. If the text length is 0 then an |
michael@0 | 340 | * U_ILLEGAL_ARGUMENT_ERROR is returned. |
michael@0 | 341 | * @stable ICU 2.0 |
michael@0 | 342 | */ |
michael@0 | 343 | virtual void setText(const UnicodeString &text, UErrorCode &status); |
michael@0 | 344 | |
michael@0 | 345 | /** |
michael@0 | 346 | * Set the target text to be searched. |
michael@0 | 347 | * Text iteration will hence begin at the start of the text string. |
michael@0 | 348 | * This method is |
michael@0 | 349 | * useful if you want to re-use an iterator to search for the same |
michael@0 | 350 | * pattern within a different body of text. |
michael@0 | 351 | * Note: No parsing of the text within the <tt>CharacterIterator</tt> |
michael@0 | 352 | * will be done during searching for this version. The block of text |
michael@0 | 353 | * in <tt>CharacterIterator</tt> will be used as it is. |
michael@0 | 354 | * @param text text string to be searched |
michael@0 | 355 | * @param status for errors if any. If the text length is 0 then an |
michael@0 | 356 | * U_ILLEGAL_ARGUMENT_ERROR is returned. |
michael@0 | 357 | * @stable ICU 2.0 |
michael@0 | 358 | */ |
michael@0 | 359 | virtual void setText(CharacterIterator &text, UErrorCode &status); |
michael@0 | 360 | |
michael@0 | 361 | /** |
michael@0 | 362 | * Gets the collator used for the language rules. |
michael@0 | 363 | * <p> |
michael@0 | 364 | * Caller may modify but <b>must not</b> delete the <tt>RuleBasedCollator</tt>! |
michael@0 | 365 | * Modifications to this collator will affect the original collator passed in to |
michael@0 | 366 | * the <tt>StringSearch></tt> constructor or to setCollator, if any. |
michael@0 | 367 | * @return collator used for string search |
michael@0 | 368 | * @stable ICU 2.0 |
michael@0 | 369 | */ |
michael@0 | 370 | RuleBasedCollator * getCollator() const; |
michael@0 | 371 | |
michael@0 | 372 | /** |
michael@0 | 373 | * Sets the collator used for the language rules. User retains the |
michael@0 | 374 | * ownership of this collator, thus the responsibility of deletion lies |
michael@0 | 375 | * with the user. This method causes internal data such as Boyer-Moore |
michael@0 | 376 | * shift tables to be recalculated, but the iterator's position is |
michael@0 | 377 | * unchanged. |
michael@0 | 378 | * @param coll collator |
michael@0 | 379 | * @param status for errors if any |
michael@0 | 380 | * @stable ICU 2.0 |
michael@0 | 381 | */ |
michael@0 | 382 | void setCollator(RuleBasedCollator *coll, UErrorCode &status); |
michael@0 | 383 | |
michael@0 | 384 | /** |
michael@0 | 385 | * Sets the pattern used for matching. |
michael@0 | 386 | * Internal data like the Boyer Moore table will be recalculated, but |
michael@0 | 387 | * the iterator's position is unchanged. |
michael@0 | 388 | * @param pattern search pattern to be found |
michael@0 | 389 | * @param status for errors if any. If the pattern length is 0 then an |
michael@0 | 390 | * U_ILLEGAL_ARGUMENT_ERROR is returned. |
michael@0 | 391 | * @stable ICU 2.0 |
michael@0 | 392 | */ |
michael@0 | 393 | void setPattern(const UnicodeString &pattern, UErrorCode &status); |
michael@0 | 394 | |
michael@0 | 395 | /** |
michael@0 | 396 | * Gets the search pattern. |
michael@0 | 397 | * @return pattern used for matching |
michael@0 | 398 | * @stable ICU 2.0 |
michael@0 | 399 | */ |
michael@0 | 400 | const UnicodeString & getPattern() const; |
michael@0 | 401 | |
michael@0 | 402 | // public methods ---------------------------------------------------- |
michael@0 | 403 | |
michael@0 | 404 | /** |
michael@0 | 405 | * Reset the iteration. |
michael@0 | 406 | * Search will begin at the start of the text string if a forward |
michael@0 | 407 | * iteration is initiated before a backwards iteration. Otherwise if |
michael@0 | 408 | * a backwards iteration is initiated before a forwards iteration, the |
michael@0 | 409 | * search will begin at the end of the text string. |
michael@0 | 410 | * @stable ICU 2.0 |
michael@0 | 411 | */ |
michael@0 | 412 | virtual void reset(); |
michael@0 | 413 | |
michael@0 | 414 | /** |
michael@0 | 415 | * Returns a copy of StringSearch with the same behavior, and |
michael@0 | 416 | * iterating over the same text, as this one. Note that all data will be |
michael@0 | 417 | * replicated, except for the user-specified collator and the |
michael@0 | 418 | * breakiterator. |
michael@0 | 419 | * @return cloned object |
michael@0 | 420 | * @stable ICU 2.0 |
michael@0 | 421 | */ |
michael@0 | 422 | virtual SearchIterator * safeClone(void) const; |
michael@0 | 423 | |
michael@0 | 424 | /** |
michael@0 | 425 | * ICU "poor man's RTTI", returns a UClassID for the actual class. |
michael@0 | 426 | * |
michael@0 | 427 | * @stable ICU 2.2 |
michael@0 | 428 | */ |
michael@0 | 429 | virtual UClassID getDynamicClassID() const; |
michael@0 | 430 | |
michael@0 | 431 | /** |
michael@0 | 432 | * ICU "poor man's RTTI", returns a UClassID for this class. |
michael@0 | 433 | * |
michael@0 | 434 | * @stable ICU 2.2 |
michael@0 | 435 | */ |
michael@0 | 436 | static UClassID U_EXPORT2 getStaticClassID(); |
michael@0 | 437 | |
michael@0 | 438 | protected: |
michael@0 | 439 | |
michael@0 | 440 | // protected method ------------------------------------------------- |
michael@0 | 441 | |
michael@0 | 442 | /** |
michael@0 | 443 | * Search forward for matching text, starting at a given location. |
michael@0 | 444 | * Clients should not call this method directly; instead they should |
michael@0 | 445 | * call {@link SearchIterator#next }. |
michael@0 | 446 | * <p> |
michael@0 | 447 | * If a match is found, this method returns the index at which the match |
michael@0 | 448 | * starts and calls {@link SearchIterator#setMatchLength } with the number |
michael@0 | 449 | * of characters in the target text that make up the match. If no match |
michael@0 | 450 | * is found, the method returns <tt>USEARCH_DONE</tt>. |
michael@0 | 451 | * <p> |
michael@0 | 452 | * The <tt>StringSearch</tt> is adjusted so that its current index |
michael@0 | 453 | * (as returned by {@link #getOffset }) is the match position if one was |
michael@0 | 454 | * found. |
michael@0 | 455 | * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and |
michael@0 | 456 | * the <tt>StringSearch</tt> will be adjusted to the index USEARCH_DONE. |
michael@0 | 457 | * @param position The index in the target text at which the search |
michael@0 | 458 | * starts |
michael@0 | 459 | * @param status for errors if any occurs |
michael@0 | 460 | * @return The index at which the matched text in the target starts, or |
michael@0 | 461 | * USEARCH_DONE if no match was found. |
michael@0 | 462 | * @stable ICU 2.0 |
michael@0 | 463 | */ |
michael@0 | 464 | virtual int32_t handleNext(int32_t position, UErrorCode &status); |
michael@0 | 465 | |
michael@0 | 466 | /** |
michael@0 | 467 | * Search backward for matching text, starting at a given location. |
michael@0 | 468 | * Clients should not call this method directly; instead they should call |
michael@0 | 469 | * <tt>SearchIterator.previous()</tt>, which this method overrides. |
michael@0 | 470 | * <p> |
michael@0 | 471 | * If a match is found, this method returns the index at which the match |
michael@0 | 472 | * starts and calls {@link SearchIterator#setMatchLength } with the number |
michael@0 | 473 | * of characters in the target text that make up the match. If no match |
michael@0 | 474 | * is found, the method returns <tt>USEARCH_DONE</tt>. |
michael@0 | 475 | * <p> |
michael@0 | 476 | * The <tt>StringSearch</tt> is adjusted so that its current index |
michael@0 | 477 | * (as returned by {@link #getOffset }) is the match position if one was |
michael@0 | 478 | * found. |
michael@0 | 479 | * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and |
michael@0 | 480 | * the <tt>StringSearch</tt> will be adjusted to the index USEARCH_DONE. |
michael@0 | 481 | * @param position The index in the target text at which the search |
michael@0 | 482 | * starts. |
michael@0 | 483 | * @param status for errors if any occurs |
michael@0 | 484 | * @return The index at which the matched text in the target starts, or |
michael@0 | 485 | * USEARCH_DONE if no match was found. |
michael@0 | 486 | * @stable ICU 2.0 |
michael@0 | 487 | */ |
michael@0 | 488 | virtual int32_t handlePrev(int32_t position, UErrorCode &status); |
michael@0 | 489 | |
michael@0 | 490 | private : |
michael@0 | 491 | StringSearch(); // default constructor not implemented |
michael@0 | 492 | |
michael@0 | 493 | // private data members ---------------------------------------------- |
michael@0 | 494 | |
michael@0 | 495 | /** |
michael@0 | 496 | * RuleBasedCollator, contains exactly the same UCollator * in m_strsrch_ |
michael@0 | 497 | * @stable ICU 2.0 |
michael@0 | 498 | */ |
michael@0 | 499 | RuleBasedCollator m_collator_; |
michael@0 | 500 | /** |
michael@0 | 501 | * Pattern text |
michael@0 | 502 | * @stable ICU 2.0 |
michael@0 | 503 | */ |
michael@0 | 504 | UnicodeString m_pattern_; |
michael@0 | 505 | /** |
michael@0 | 506 | * String search struct data |
michael@0 | 507 | * @stable ICU 2.0 |
michael@0 | 508 | */ |
michael@0 | 509 | UStringSearch *m_strsrch_; |
michael@0 | 510 | |
michael@0 | 511 | }; |
michael@0 | 512 | |
michael@0 | 513 | U_NAMESPACE_END |
michael@0 | 514 | |
michael@0 | 515 | #endif /* #if !UCONFIG_NO_COLLATION */ |
michael@0 | 516 | |
michael@0 | 517 | #endif |
michael@0 | 518 |