1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 **********************************************************************
5 * Copyright (C) 2001-2011,2014 IBM and others. All rights reserved.
6 **********************************************************************
7 * Date Name Description
8 * 06/28/2001 synwee Creation.
9 **********************************************************************
14 #include "unicode/utypes.h"
16 #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
18 #include "unicode/localpointer.h"
19 #include "unicode/ucol.h"
20 #include "unicode/ucoleitr.h"
21 #include "unicode/ubrk.h"
25 * \brief C API: StringSearch
27 * C APIs for an engine that provides language-sensitive text searching based
28 * on the comparison rules defined in a <tt>UCollator</tt> data struct,
29 * see <tt>ucol.h</tt>. This ensures that language eccentricity can be
30 * handled, e.g. for the German collator, characters ß and SS will be matched
31 * if case is chosen to be ignored.
32 * See the <a href="http://source.icu-project.org/repos/icu/icuhtml/trunk/design/collation/ICU_collation_design.htm">
33 * "ICU Collation Design Document"</a> for more information.
35 * The implementation may use a linear search or a modified form of the Boyer-Moore
36 * search; for more information on the latter see
37 * <a href="http://icu-project.org/docs/papers/efficient_text_searching_in_java.html">
38 * "Efficient Text Searching in Java"</a>, published in <i>Java Report</i>
41 * There are 2 match options for selection:<br>
42 * Let S' be the sub-string of a text string S between the offsets start and
45 * A pattern string P matches a text string S at the offsets <start, end>
48 * option 1. Some canonical equivalent of P matches some canonical equivalent
50 * option 2. P matches S' and if P starts or ends with a combining mark,
51 * there exists no non-ignorable combining mark before or after S'
54 * Option 2. will be the default.
56 * This search has APIs similar to that of other text iteration mechanisms
57 * such as the break iterators in <tt>ubrk.h</tt>. Using these
58 * APIs, it is easy to scan through text looking for all occurrences of
59 * a given pattern. This search iterator allows changing of direction by
60 * calling a <tt>reset</tt> followed by a <tt>next</tt> or <tt>previous</tt>.
61 * Though a direction change can occur without calling <tt>reset</tt> first,
62 * this operation comes with some speed penalty.
63 * Generally, match results in the forward direction will match the result
64 * matches in the backwards direction in the reverse order
66 * <tt>usearch.h</tt> provides APIs to specify the starting position
67 * within the text string to be searched, e.g. <tt>usearch_setOffset</tt>,
68 * <tt>usearch_preceding</tt> and <tt>usearch_following</tt>. Since the
69 * starting position will be set as it is specified, please take note that
70 * there are some dangerous positions which the search may render incorrect
73 * <li> The midst of a substring that requires normalization.
74 * <li> If the following match is to be found, the position should not be the
75 * second character which requires to be swapped with the preceding
76 * character. Vice versa, if the preceding match is to be found,
77 * position to search from should not be the first character which
78 * requires to be swapped with the next character. E.g certain Thai and
79 * Lao characters require swapping.
80 * <li> If a following pattern match is to be found, any position within a
81 * contracting sequence except the first will fail. Vice versa if a
82 * preceding pattern match is to be found, a invalid starting point
83 * would be any character within a contracting sequence except the last.
86 * A breakiterator can be used if only matches at logical breaks are desired.
87 * Using a breakiterator will only give you results that exactly matches the
88 * boundaries given by the breakiterator. For instance the pattern "e" will
89 * not be found in the string "\u00e9" if a character break iterator is used.
91 * Options are provided to handle overlapping matches.
92 * E.g. In English, overlapping matches produces the result 0 and 2
93 * for the pattern "abab" in the text "ababab", where else mutually
94 * exclusive matches only produce the result of 0.
96 * Options are also provided to implement "asymmetric search" as described in
97 * <a href="http://www.unicode.org/reports/tr10/#Asymmetric_Search">
98 * UTS #10 Unicode Collation Algorithm</a>, specifically the USearchAttribute
99 * USEARCH_ELEMENT_COMPARISON and its values.
101 * Though collator attributes will be taken into consideration while
102 * performing matches, there are no APIs here for setting and getting the
103 * attributes. These attributes can be set by getting the collator
104 * from <tt>usearch_getCollator</tt> and using the APIs in <tt>ucol.h</tt>.
105 * Lastly to update String Search to the new collator attributes,
106 * usearch_reset() has to be called.
109 * Currently there are no composite characters that consists of a
110 * character with combining class > 0 before a character with combining
111 * class == 0. However, if such a character exists in the future, the
112 * search mechanism does not guarantee the results for option 1.
115 * Example of use:<br>
117 * char *tgtstr = "The quick brown fox jumped over the lazy fox";
118 * char *patstr = "fox";
121 * UErrorCode status = U_ZERO_ERROR;
122 * u_uastrcpy(target, tgtstr);
123 * u_uastrcpy(pattern, patstr);
125 * UStringSearch *search = usearch_open(pattern, -1, target, -1, "en_US",
127 * if (U_SUCCESS(status)) {
128 * for (int pos = usearch_first(search, &status);
129 * pos != USEARCH_DONE;
130 * pos = usearch_next(search, &status))
132 * printf("Found match at %d pos, length is %d\n", pos,
133 * usearch_getMatchedLength(search));
137 * usearch_close(search);
143 * DONE is returned by previous() and next() after all valid matches have
144 * been returned, and by first() and last() if there are no matches at all.
147 #define USEARCH_DONE -1
150 * Data structure for searching
153 struct UStringSearch
;
155 * Data structure for searching
158 typedef struct UStringSearch UStringSearch
;
165 * Option for overlapping matches
169 #ifndef U_HIDE_DEPRECATED_API
171 * Option for canonical matches; option 1 in header documentation.
172 * The default value will be USEARCH_OFF.
173 * Note: Setting this option to USEARCH_ON currently has no effect on
174 * search behavior, and this option is deprecated. Instead, to control
175 * canonical match behavior, you must set UCOL_NORMALIZATION_MODE
176 * appropriately (to UCOL_OFF or UCOL_ON) in the UCollator used by
177 * the UStringSearch object.
178 * @see usearch_openFromCollator
179 * @see usearch_getCollator
180 * @see usearch_setCollator
181 * @see ucol_getAttribute
184 USEARCH_CANONICAL_MATCH
= 1,
185 #endif /* U_HIDE_DEPRECATED_API */
187 * Option to control how collation elements are compared.
188 * The default value will be USEARCH_STANDARD_ELEMENT_COMPARISON.
191 USEARCH_ELEMENT_COMPARISON
= 2,
193 #ifndef U_HIDE_DEPRECATED_API
195 * One more than the highest normal USearchAttribute value.
196 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
198 USEARCH_ATTRIBUTE_COUNT
= 3
199 #endif /* U_HIDE_DEPRECATED_API */
207 * Default value for any USearchAttribute
210 USEARCH_DEFAULT
= -1,
212 * Value for USEARCH_OVERLAP and USEARCH_CANONICAL_MATCH
217 * Value for USEARCH_OVERLAP and USEARCH_CANONICAL_MATCH
222 * Value (default) for USEARCH_ELEMENT_COMPARISON;
223 * standard collation element comparison at the specified collator
227 USEARCH_STANDARD_ELEMENT_COMPARISON
,
229 * Value for USEARCH_ELEMENT_COMPARISON;
230 * collation element comparison is modified to effectively provide
231 * behavior between the specified strength and strength - 1. Collation
232 * elements in the pattern that have the base weight for the specified
233 * strength are treated as "wildcards" that match an element with any
234 * other weight at that collation level in the searched text. For
235 * example, with a secondary-strength English collator, a plain 'e' in
236 * the pattern will match a plain e or an e with any diacritic in the
237 * searched text, but an e with diacritic in the pattern will only
238 * match an e with the same diacritic in the searched text.
240 * This supports "asymmetric search" as described in
241 * <a href="http://www.unicode.org/reports/tr10/#Asymmetric_Search">
242 * UTS #10 Unicode Collation Algorithm</a>.
246 USEARCH_PATTERN_BASE_WEIGHT_IS_WILDCARD
,
248 * Value for USEARCH_ELEMENT_COMPARISON.
249 * collation element comparison is modified to effectively provide
250 * behavior between the specified strength and strength - 1. Collation
251 * elements in either the pattern or the searched text that have the
252 * base weight for the specified strength are treated as "wildcards"
253 * that match an element with any other weight at that collation level.
254 * For example, with a secondary-strength English collator, a plain 'e'
255 * in the pattern will match a plain e or an e with any diacritic in the
256 * searched text, but an e with diacritic in the pattern will only
257 * match an e with the same diacritic or a plain e in the searched text.
259 * This option is similar to "asymmetric search" as described in
260 * [UTS #10 Unicode Collation Algorithm](http://www.unicode.org/reports/tr10/#Asymmetric_Search),
261 * but also allows unmarked characters in the searched text to match
262 * marked or unmarked versions of that character in the pattern.
266 USEARCH_ANY_BASE_WEIGHT_IS_WILDCARD
,
268 #ifndef U_HIDE_DEPRECATED_API
270 * One more than the highest normal USearchAttributeValue value.
271 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
273 USEARCH_ATTRIBUTE_VALUE_COUNT
274 #endif /* U_HIDE_DEPRECATED_API */
275 } USearchAttributeValue
;
277 /* open and close ------------------------------------------------------ */
280 * Creating a search iterator data struct using the argument locale language
281 * rule set. A collator will be created in the process, which will be owned by
282 * this search and will be deleted in <tt>usearch_close</tt>.
283 * @param pattern for matching
284 * @param patternlength length of the pattern, -1 for null-termination
285 * @param text text string
286 * @param textlength length of the text string, -1 for null-termination
287 * @param locale name of locale for the rules to be used
288 * @param breakiter A BreakIterator that will be used to restrict the points
289 * at which matches are detected. If a match is found, but
290 * the match's start or end index is not a boundary as
291 * determined by the <tt>BreakIterator</tt>, the match will
292 * be rejected and another will be searched for.
293 * If this parameter is <tt>NULL</tt>, no break detection is
295 * @param status for errors if it occurs. If pattern or text is NULL, or if
296 * patternlength or textlength is 0 then an
297 * U_ILLEGAL_ARGUMENT_ERROR is returned.
298 * @return search iterator data structure, or NULL if there is an error.
301 U_STABLE UStringSearch
* U_EXPORT2
usearch_open(const UChar
*pattern
,
302 int32_t patternlength
,
306 UBreakIterator
*breakiter
,
310 * Creating a search iterator data struct using the argument collator language
311 * rule set. Note, user retains the ownership of this collator, thus the
312 * responsibility of deletion lies with the user.
313 * NOTE: string search cannot be instantiated from a collator that has
314 * collate digits as numbers (CODAN) turned on.
315 * @param pattern for matching
316 * @param patternlength length of the pattern, -1 for null-termination
317 * @param text text string
318 * @param textlength length of the text string, -1 for null-termination
319 * @param collator used for the language rules
320 * @param breakiter A BreakIterator that will be used to restrict the points
321 * at which matches are detected. If a match is found, but
322 * the match's start or end index is not a boundary as
323 * determined by the <tt>BreakIterator</tt>, the match will
324 * be rejected and another will be searched for.
325 * If this parameter is <tt>NULL</tt>, no break detection is
327 * @param status for errors if it occurs. If collator, pattern or text is NULL,
328 * or if patternlength or textlength is 0 then an
329 * U_ILLEGAL_ARGUMENT_ERROR is returned.
330 * @return search iterator data structure, or NULL if there is an error.
333 U_STABLE UStringSearch
* U_EXPORT2
usearch_openFromCollator(
334 const UChar
*pattern
,
335 int32_t patternlength
,
338 const UCollator
*collator
,
339 UBreakIterator
*breakiter
,
343 * Destroying and cleaning up the search iterator data struct.
344 * If a collator is created in <tt>usearch_open</tt>, it will be destroyed here.
345 * @param searchiter data struct to clean up
348 U_STABLE
void U_EXPORT2
usearch_close(UStringSearch
*searchiter
);
350 #if U_SHOW_CPLUSPLUS_API
355 * \class LocalUStringSearchPointer
356 * "Smart pointer" class, closes a UStringSearch via usearch_close().
357 * For most methods see the LocalPointerBase base class.
359 * @see LocalPointerBase
363 U_DEFINE_LOCAL_OPEN_POINTER(LocalUStringSearchPointer
, UStringSearch
, usearch_close
);
369 /* get and set methods -------------------------------------------------- */
372 * Sets the current position in the text string which the next search will
373 * start from. Clears previous states.
374 * This method takes the argument index and sets the position in the text
375 * string accordingly without checking if the index is pointing to a
376 * valid starting point to begin searching.
377 * Search positions that may render incorrect results are highlighted in the
379 * @param strsrch search iterator data struct
380 * @param position position to start next search from. If position is less
381 * than or greater than the text range for searching,
382 * an U_INDEX_OUTOFBOUNDS_ERROR will be returned
383 * @param status error status if any.
386 U_STABLE
void U_EXPORT2
usearch_setOffset(UStringSearch
*strsrch
,
391 * Return the current index in the string text being searched.
392 * If the iteration has gone past the end of the text (or past the beginning
393 * for a backwards search), <tt>USEARCH_DONE</tt> is returned.
394 * @param strsrch search iterator data struct
398 U_STABLE
int32_t U_EXPORT2
usearch_getOffset(const UStringSearch
*strsrch
);
401 * Sets the text searching attributes located in the enum USearchAttribute
402 * with values from the enum USearchAttributeValue.
403 * <tt>USEARCH_DEFAULT</tt> can be used for all attributes for resetting.
404 * @param strsrch search iterator data struct
405 * @param attribute text attribute to be set
406 * @param value text attribute value
407 * @param status for errors if it occurs
408 * @see #usearch_getAttribute
411 U_STABLE
void U_EXPORT2
usearch_setAttribute(UStringSearch
*strsrch
,
412 USearchAttribute attribute
,
413 USearchAttributeValue value
,
417 * Gets the text searching attributes.
418 * @param strsrch search iterator data struct
419 * @param attribute text attribute to be retrieve
420 * @return text attribute value
421 * @see #usearch_setAttribute
424 U_STABLE USearchAttributeValue U_EXPORT2
usearch_getAttribute(
425 const UStringSearch
*strsrch
,
426 USearchAttribute attribute
);
429 * Returns the index to the match in the text string that was searched.
430 * This call returns a valid result only after a successful call to
431 * <tt>usearch_first</tt>, <tt>usearch_next</tt>, <tt>usearch_previous</tt>,
432 * or <tt>usearch_last</tt>.
433 * Just after construction, or after a searching method returns
434 * <tt>USEARCH_DONE</tt>, this method will return <tt>USEARCH_DONE</tt>.
436 * Use <tt>usearch_getMatchedLength</tt> to get the matched string length.
437 * @param strsrch search iterator data struct
438 * @return index to a substring within the text string that is being
440 * @see #usearch_first
442 * @see #usearch_previous
447 U_STABLE
int32_t U_EXPORT2
usearch_getMatchedStart(
448 const UStringSearch
*strsrch
);
451 * Returns the length of text in the string which matches the search pattern.
452 * This call returns a valid result only after a successful call to
453 * <tt>usearch_first</tt>, <tt>usearch_next</tt>, <tt>usearch_previous</tt>,
454 * or <tt>usearch_last</tt>.
455 * Just after construction, or after a searching method returns
456 * <tt>USEARCH_DONE</tt>, this method will return 0.
457 * @param strsrch search iterator data struct
458 * @return The length of the match in the string text, or 0 if there is no
460 * @see #usearch_first
462 * @see #usearch_previous
467 U_STABLE
int32_t U_EXPORT2
usearch_getMatchedLength(
468 const UStringSearch
*strsrch
);
471 * Returns the text that was matched by the most recent call to
472 * <tt>usearch_first</tt>, <tt>usearch_next</tt>, <tt>usearch_previous</tt>,
473 * or <tt>usearch_last</tt>.
474 * If the iterator is not pointing at a valid match (e.g. just after
475 * construction or after <tt>USEARCH_DONE</tt> has been returned, returns
476 * an empty string. If result is not large enough to store the matched text,
477 * result will be filled with the partial text and an U_BUFFER_OVERFLOW_ERROR
478 * will be returned in status. result will be null-terminated whenever
479 * possible. If the buffer fits the matched text exactly, a null-termination
480 * is not possible, then a U_STRING_NOT_TERMINATED_ERROR set in status.
481 * Pre-flighting can be either done with length = 0 or the API
482 * <tt>usearch_getMatchedLength</tt>.
483 * @param strsrch search iterator data struct
484 * @param result UChar buffer to store the matched string
485 * @param resultCapacity length of the result buffer
486 * @param status error returned if result is not large enough
487 * @return exact length of the matched text, not counting the null-termination
488 * @see #usearch_first
490 * @see #usearch_previous
495 U_STABLE
int32_t U_EXPORT2
usearch_getMatchedText(const UStringSearch
*strsrch
,
497 int32_t resultCapacity
,
500 #if !UCONFIG_NO_BREAK_ITERATION
503 * Set the BreakIterator that will be used to restrict the points at which
504 * matches are detected.
505 * @param strsrch search iterator data struct
506 * @param breakiter A BreakIterator that will be used to restrict the points
507 * at which matches are detected. If a match is found, but
508 * the match's start or end index is not a boundary as
509 * determined by the <tt>BreakIterator</tt>, the match will
510 * be rejected and another will be searched for.
511 * If this parameter is <tt>NULL</tt>, no break detection is
513 * @param status for errors if it occurs
514 * @see #usearch_getBreakIterator
517 U_STABLE
void U_EXPORT2
usearch_setBreakIterator(UStringSearch
*strsrch
,
518 UBreakIterator
*breakiter
,
522 * Returns the BreakIterator that is used to restrict the points at which
523 * matches are detected. This will be the same object that was passed to the
524 * constructor or to <tt>usearch_setBreakIterator</tt>. Note that
526 * is a legal value; it means that break detection should not be attempted.
527 * @param strsrch search iterator data struct
528 * @return break iterator used
529 * @see #usearch_setBreakIterator
532 U_STABLE
const UBreakIterator
* U_EXPORT2
usearch_getBreakIterator(
533 const UStringSearch
*strsrch
);
538 * Set the string text to be searched. Text iteration will hence begin at the
539 * start of the text string. This method is useful if you want to re-use an
540 * iterator to search for the same pattern within a different body of text.
541 * @param strsrch search iterator data struct
542 * @param text new string to look for match
543 * @param textlength length of the new string, -1 for null-termination
544 * @param status for errors if it occurs. If text is NULL, or textlength is 0
545 * then an U_ILLEGAL_ARGUMENT_ERROR is returned with no change
547 * @see #usearch_getText
550 U_STABLE
void U_EXPORT2
usearch_setText( UStringSearch
*strsrch
,
556 * Return the string text to be searched.
557 * @param strsrch search iterator data struct
558 * @param length returned string text length
559 * @return string text
560 * @see #usearch_setText
563 U_STABLE
const UChar
* U_EXPORT2
usearch_getText(const UStringSearch
*strsrch
,
567 * Gets the collator used for the language rules.
569 * Deleting the returned <tt>UCollator</tt> before calling
570 * <tt>usearch_close</tt> would cause the string search to fail.
571 * <tt>usearch_close</tt> will delete the collator if this search owns it.
572 * @param strsrch search iterator data struct
576 U_STABLE UCollator
* U_EXPORT2
usearch_getCollator(
577 const UStringSearch
*strsrch
);
580 * Sets the collator used for the language rules. User retains the ownership
581 * of this collator, thus the responsibility of deletion lies with the user.
582 * This method causes internal data such as Boyer-Moore shift tables to
583 * be recalculated, but the iterator's position is unchanged.
584 * @param strsrch search iterator data struct
585 * @param collator to be used
586 * @param status for errors if it occurs
589 U_STABLE
void U_EXPORT2
usearch_setCollator( UStringSearch
*strsrch
,
590 const UCollator
*collator
,
594 * Sets the pattern used for matching.
595 * Internal data like the Boyer Moore table will be recalculated, but the
596 * iterator's position is unchanged.
597 * @param strsrch search iterator data struct
598 * @param pattern string
599 * @param patternlength pattern length, -1 for null-terminated string
600 * @param status for errors if it occurs. If text is NULL, or textlength is 0
601 * then an U_ILLEGAL_ARGUMENT_ERROR is returned with no change
605 U_STABLE
void U_EXPORT2
usearch_setPattern( UStringSearch
*strsrch
,
606 const UChar
*pattern
,
607 int32_t patternlength
,
611 * Gets the search pattern
612 * @param strsrch search iterator data struct
613 * @param length return length of the pattern, -1 indicates that the pattern
615 * @return pattern string
618 U_STABLE
const UChar
* U_EXPORT2
usearch_getPattern(
619 const UStringSearch
*strsrch
,
622 /* methods ------------------------------------------------------------- */
625 * Returns the first index at which the string text matches the search
627 * The iterator is adjusted so that its current index (as returned by
628 * <tt>usearch_getOffset</tt>) is the match position if one was found.
629 * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
630 * the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>.
631 * @param strsrch search iterator data struct
632 * @param status for errors if it occurs
633 * @return The character index of the first match, or
634 * <tt>USEARCH_DONE</tt> if there are no matches.
635 * @see #usearch_getOffset
639 U_STABLE
int32_t U_EXPORT2
usearch_first(UStringSearch
*strsrch
,
643 * Returns the first index equal or greater than <tt>position</tt> at which
645 * matches the search pattern. The iterator is adjusted so that its current
646 * index (as returned by <tt>usearch_getOffset</tt>) is the match position if
648 * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
649 * the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>
651 * Search positions that may render incorrect results are highlighted in the
652 * header comments. If position is less than or greater than the text range
653 * for searching, an U_INDEX_OUTOFBOUNDS_ERROR will be returned
654 * @param strsrch search iterator data struct
655 * @param position to start the search at
656 * @param status for errors if it occurs
657 * @return The character index of the first match following <tt>pos</tt>,
658 * or <tt>USEARCH_DONE</tt> if there are no matches.
659 * @see #usearch_getOffset
663 U_STABLE
int32_t U_EXPORT2
usearch_following(UStringSearch
*strsrch
,
668 * Returns the last index in the target text at which it matches the search
669 * pattern. The iterator is adjusted so that its current
670 * index (as returned by <tt>usearch_getOffset</tt>) is the match position if
672 * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
673 * the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>.
674 * @param strsrch search iterator data struct
675 * @param status for errors if it occurs
676 * @return The index of the first match, or <tt>USEARCH_DONE</tt> if there
678 * @see #usearch_getOffset
682 U_STABLE
int32_t U_EXPORT2
usearch_last(UStringSearch
*strsrch
,
686 * Returns the first index less than <tt>position</tt> at which the string text
687 * matches the search pattern. The iterator is adjusted so that its current
688 * index (as returned by <tt>usearch_getOffset</tt>) is the match position if
690 * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
691 * the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>
693 * Search positions that may render incorrect results are highlighted in the
694 * header comments. If position is less than or greater than the text range
695 * for searching, an U_INDEX_OUTOFBOUNDS_ERROR will be returned.
697 * When <tt>USEARCH_OVERLAP</tt> option is off, the last index of the
698 * result match is always less than <tt>position</tt>.
699 * When <tt>USERARCH_OVERLAP</tt> is on, the result match may span across
701 * @param strsrch search iterator data struct
702 * @param position index position the search is to begin at
703 * @param status for errors if it occurs
704 * @return The character index of the first match preceding <tt>pos</tt>,
705 * or <tt>USEARCH_DONE</tt> if there are no matches.
706 * @see #usearch_getOffset
710 U_STABLE
int32_t U_EXPORT2
usearch_preceding(UStringSearch
*strsrch
,
715 * Returns the index of the next point at which the string text matches the
716 * search pattern, starting from the current position.
717 * The iterator is adjusted so that its current
718 * index (as returned by <tt>usearch_getOffset</tt>) is the match position if
720 * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
721 * the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>
722 * @param strsrch search iterator data struct
723 * @param status for errors if it occurs
724 * @return The index of the next match after the current position, or
725 * <tt>USEARCH_DONE</tt> if there are no more matches.
726 * @see #usearch_first
727 * @see #usearch_getOffset
731 U_STABLE
int32_t U_EXPORT2
usearch_next(UStringSearch
*strsrch
,
735 * Returns the index of the previous point at which the string text matches
736 * the search pattern, starting at the current position.
737 * The iterator is adjusted so that its current
738 * index (as returned by <tt>usearch_getOffset</tt>) is the match position if
740 * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
741 * the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>
742 * @param strsrch search iterator data struct
743 * @param status for errors if it occurs
744 * @return The index of the previous match before the current position,
745 * or <tt>USEARCH_DONE</tt> if there are no more matches.
747 * @see #usearch_getOffset
751 U_STABLE
int32_t U_EXPORT2
usearch_previous(UStringSearch
*strsrch
,
755 * Reset the iteration.
756 * Search will begin at the start of the text string if a forward iteration
757 * is initiated before a backwards iteration. Otherwise if a backwards
758 * iteration is initiated before a forwards iteration, the search will begin
759 * at the end of the text string.
760 * @param strsrch search iterator data struct
761 * @see #usearch_first
764 U_STABLE
void U_EXPORT2
usearch_reset(UStringSearch
*strsrch
);
766 #ifndef U_HIDE_INTERNAL_API
768 * Simple forward search for the pattern, starting at a specified index,
769 * and using a default set search options.
771 * This is an experimental function, and is not an official part of the
774 * The collator options, such as UCOL_STRENGTH and UCOL_NORMALIZTION, are honored.
776 * The UStringSearch options USEARCH_CANONICAL_MATCH, USEARCH_OVERLAP and
777 * any Break Iterator are ignored.
779 * Matches obey the following constraints:
781 * Characters at the start or end positions of a match that are ignorable
782 * for collation are not included as part of the match, unless they
783 * are part of a combining sequence, as described below.
785 * A match will not include a partial combining sequence. Combining
786 * character sequences are considered to be inseparable units,
787 * and either match the pattern completely, or are considered to not match
788 * at all. Thus, for example, an A followed a combining accent mark will
789 * not be found when searching for a plain (unaccented) A. (unless
790 * the collation strength has been set to ignore all accents).
792 * When beginning a search, the initial starting position, startIdx,
793 * is assumed to be an acceptable match boundary with respect to
794 * combining characters. A combining sequence that spans across the
795 * starting point will not suppress a match beginning at startIdx.
797 * Characters that expand to multiple collation elements
798 * (German sharp-S becoming 'ss', or the composed forms of accented
799 * characters, for example) also must match completely.
800 * Searching for a single 's' in a string containing only a sharp-s will
804 * @param strsrch the UStringSearch struct, which references both
805 * the text to be searched and the pattern being sought.
806 * @param startIdx The index into the text to begin the search.
807 * @param matchStart An out parameter, the starting index of the matched text.
808 * This parameter may be NULL.
809 * A value of -1 will be returned if no match was found.
810 * @param matchLimit Out parameter, the index of the first position following the matched text.
811 * The matchLimit will be at a suitable position for beginning a subsequent search
813 * This parameter may be NULL.
814 * A value of -1 will be returned if no match was found.
816 * @param status Report any errors. Note that no match found is not an error.
817 * @return TRUE if a match was found, FALSE otherwise.
821 U_INTERNAL UBool U_EXPORT2
usearch_search(UStringSearch
*strsrch
,
828 * Simple backwards search for the pattern, starting at a specified index,
829 * and using using a default set search options.
831 * This is an experimental function, and is not an official part of the
834 * The collator options, such as UCOL_STRENGTH and UCOL_NORMALIZTION, are honored.
836 * The UStringSearch options USEARCH_CANONICAL_MATCH, USEARCH_OVERLAP and
837 * any Break Iterator are ignored.
839 * Matches obey the following constraints:
841 * Characters at the start or end positions of a match that are ignorable
842 * for collation are not included as part of the match, unless they
843 * are part of a combining sequence, as described below.
845 * A match will not include a partial combining sequence. Combining
846 * character sequences are considered to be inseparable units,
847 * and either match the pattern completely, or are considered to not match
848 * at all. Thus, for example, an A followed a combining accent mark will
849 * not be found when searching for a plain (unaccented) A. (unless
850 * the collation strength has been set to ignore all accents).
852 * When beginning a search, the initial starting position, startIdx,
853 * is assumed to be an acceptable match boundary with respect to
854 * combining characters. A combining sequence that spans across the
855 * starting point will not suppress a match beginning at startIdx.
857 * Characters that expand to multiple collation elements
858 * (German sharp-S becoming 'ss', or the composed forms of accented
859 * characters, for example) also must match completely.
860 * Searching for a single 's' in a string containing only a sharp-s will
864 * @param strsrch the UStringSearch struct, which references both
865 * the text to be searched and the pattern being sought.
866 * @param startIdx The index into the text to begin the search.
867 * @param matchStart An out parameter, the starting index of the matched text.
868 * This parameter may be NULL.
869 * A value of -1 will be returned if no match was found.
870 * @param matchLimit Out parameter, the index of the first position following the matched text.
871 * The matchLimit will be at a suitable position for beginning a subsequent search
873 * This parameter may be NULL.
874 * A value of -1 will be returned if no match was found.
876 * @param status Report any errors. Note that no match found is not an error.
877 * @return TRUE if a match was found, FALSE otherwise.
881 U_INTERNAL UBool U_EXPORT2
usearch_searchBackwards(UStringSearch
*strsrch
,
886 #endif /* U_HIDE_INTERNAL_API */
888 #endif /* #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION */