2 **********************************************************************
3 * Copyright (C) 2001-2011,2014 IBM and others. All rights reserved.
4 **********************************************************************
5 * Date Name Description
6 * 06/28/2001 synwee Creation.
7 **********************************************************************
12 #include "unicode/utypes.h"
14 #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
16 #include "unicode/localpointer.h"
17 #include "unicode/ucol.h"
18 #include "unicode/ucoleitr.h"
19 #include "unicode/ubrk.h"
23 * \brief C API: StringSearch
25 * C Apis for an engine that provides language-sensitive text searching based
26 * on the comparison rules defined in a <tt>UCollator</tt> data struct,
27 * see <tt>ucol.h</tt>. This ensures that language eccentricity can be
28 * handled, e.g. for the German collator, characters ß and SS will be matched
29 * if case is chosen to be ignored.
30 * See the <a href="http://source.icu-project.org/repos/icu/icuhtml/trunk/design/collation/ICU_collation_design.htm">
31 * "ICU Collation Design Document"</a> for more information.
33 * The implementation may use a linear search or a modified form of the Boyer-Moore
34 * search; for more information on the latter see
35 * <a href="http://icu-project.org/docs/papers/efficient_text_searching_in_java.html">
36 * "Efficient Text Searching in Java"</a>, published in <i>Java Report</i>
39 * There are 2 match options for selection:<br>
40 * Let S' be the sub-string of a text string S between the offsets start and
43 * A pattern string P matches a text string S at the offsets <start, end>
46 * option 1. Some canonical equivalent of P matches some canonical equivalent
48 * option 2. P matches S' and if P starts or ends with a combining mark,
49 * there exists no non-ignorable combining mark before or after S'
52 * Option 2. will be the default.
54 * This search has APIs similar to that of other text iteration mechanisms
55 * such as the break iterators in <tt>ubrk.h</tt>. Using these
56 * APIs, it is easy to scan through text looking for all occurances of
57 * a given pattern. This search iterator allows changing of direction by
58 * calling a <tt>reset</tt> followed by a <tt>next</tt> or <tt>previous</tt>.
59 * Though a direction change can occur without calling <tt>reset</tt> first,
60 * this operation comes with some speed penalty.
61 * Generally, match results in the forward direction will match the result
62 * matches in the backwards direction in the reverse order
64 * <tt>usearch.h</tt> provides APIs to specify the starting position
65 * within the text string to be searched, e.g. <tt>usearch_setOffset</tt>,
66 * <tt>usearch_preceding</tt> and <tt>usearch_following</tt>. Since the
67 * starting position will be set as it is specified, please take note that
68 * there are some dangerous positions which the search may render incorrect
71 * <li> The midst of a substring that requires normalization.
72 * <li> If the following match is to be found, the position should not be the
73 * second character which requires to be swapped with the preceding
74 * character. Vice versa, if the preceding match is to be found,
75 * position to search from should not be the first character which
76 * requires to be swapped with the next character. E.g certain Thai and
77 * Lao characters require swapping.
78 * <li> If a following pattern match is to be found, any position within a
79 * contracting sequence except the first will fail. Vice versa if a
80 * preceding pattern match is to be found, a invalid starting point
81 * would be any character within a contracting sequence except the last.
84 * A breakiterator can be used if only matches at logical breaks are desired.
85 * Using a breakiterator will only give you results that exactly matches the
86 * boundaries given by the breakiterator. For instance the pattern "e" will
87 * not be found in the string "\u00e9" if a character break iterator is used.
89 * Options are provided to handle overlapping matches.
90 * E.g. In English, overlapping matches produces the result 0 and 2
91 * for the pattern "abab" in the text "ababab", where else mutually
92 * exclusive matches only produce the result of 0.
94 * Options are also provided to implement "asymmetric search" as described in
95 * <a href="http://www.unicode.org/reports/tr10/#Asymmetric_Search">
96 * UTS #10 Unicode Collation Algorithm</a>, specifically the USearchAttribute
97 * USEARCH_ELEMENT_COMPARISON and its values.
99 * E.g. In English, overlapping matches produces the result 0 and 2
100 * for the pattern "abab" in the text "ababab", where else mutually
101 * exclusive matches only produce the result of 0.
103 * Though collator attributes will be taken into consideration while
104 * performing matches, there are no APIs here for setting and getting the
105 * attributes. These attributes can be set by getting the collator
106 * from <tt>usearch_getCollator</tt> and using the APIs in <tt>ucol.h</tt>.
107 * Lastly to update String Search to the new collator attributes,
108 * usearch_reset() has to be called.
111 * Currently there are no composite characters that consists of a
112 * character with combining class > 0 before a character with combining
113 * class == 0. However, if such a character exists in the future, the
114 * search mechanism does not guarantee the results for option 1.
117 * Example of use:<br>
119 * char *tgtstr = "The quick brown fox jumped over the lazy fox";
120 * char *patstr = "fox";
123 * UErrorCode status = U_ZERO_ERROR;
124 * u_uastrcpy(target, tgtstr);
125 * u_uastrcpy(pattern, patstr);
127 * UStringSearch *search = usearch_open(pattern, -1, target, -1, "en_US",
129 * if (U_SUCCESS(status)) {
130 * for (int pos = usearch_first(search, &status);
131 * pos != USEARCH_DONE;
132 * pos = usearch_next(search, &status))
134 * printf("Found match at %d pos, length is %d\n", pos,
135 * usearch_getMatchLength(search));
139 * usearch_close(search);
145 * DONE is returned by previous() and next() after all valid matches have
146 * been returned, and by first() and last() if there are no matches at all.
149 #define USEARCH_DONE -1
152 * Data structure for searching
155 struct UStringSearch
;
157 * Data structure for searching
160 typedef struct UStringSearch UStringSearch
;
167 * Option for overlapping matches
171 #ifndef U_HIDE_DEPRECATED_API
173 * Option for canonical matches; option 1 in header documentation.
174 * The default value will be USEARCH_OFF.
175 * Note: Setting this option to USEARCH_ON currently has no effect on
176 * search behavior, and this option is deprecated. Instead, to control
177 * canonical match behavior, you must set UCOL_NORMALIZATION_MODE
178 * appropriately (to UCOL_OFF or UCOL_ON) in the UCollator used by
179 * the UStringSearch object.
180 * @see usearch_openFromCollator
181 * @see usearch_getCollator
182 * @see usearch_setCollator
183 * @see ucol_getAttribute
186 USEARCH_CANONICAL_MATCH
= 1,
187 #endif /* U_HIDE_DEPRECATED_API */
189 * Option to control how collation elements are compared.
190 * The default value will be USEARCH_STANDARD_ELEMENT_COMPARISON.
193 USEARCH_ELEMENT_COMPARISON
= 2,
196 * Count of attribute types
199 USEARCH_ATTRIBUTE_COUNT
= 3
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 * <a href="http://www.unicode.org/reports/tr10/#Asymmetric_Search">
261 * UTS #10 Unicode Collation Algorithm</a, but also allows unmarked
262 * characters in the searched text to match marked or unmarked versions of
263 * that character in the pattern.
267 USEARCH_ANY_BASE_WEIGHT_IS_WILDCARD
,
270 * Count of attribute values
273 USEARCH_ATTRIBUTE_VALUE_COUNT
274 } USearchAttributeValue
;
276 /* open and close ------------------------------------------------------ */
279 * Creating a search iterator data struct using the argument locale language
280 * rule set. A collator will be created in the process, which will be owned by
281 * this search and will be deleted in <tt>usearch_close</tt>.
282 * @param pattern for matching
283 * @param patternlength length of the pattern, -1 for null-termination
284 * @param text text string
285 * @param textlength length of the text string, -1 for null-termination
286 * @param locale name of locale for the rules to be used
287 * @param breakiter A BreakIterator that will be used to restrict the points
288 * at which matches are detected. If a match is found, but
289 * the match's start or end index is not a boundary as
290 * determined by the <tt>BreakIterator</tt>, the match will
291 * be rejected and another will be searched for.
292 * If this parameter is <tt>NULL</tt>, no break detection is
294 * @param status for errors if it occurs. If pattern or text is NULL, or if
295 * patternlength or textlength is 0 then an
296 * U_ILLEGAL_ARGUMENT_ERROR is returned.
297 * @return search iterator data structure, or NULL if there is an error.
300 U_STABLE UStringSearch
* U_EXPORT2
usearch_open(const UChar
*pattern
,
301 int32_t patternlength
,
305 UBreakIterator
*breakiter
,
309 * Creating a search iterator data struct using the argument collator language
310 * rule set. Note, user retains the ownership of this collator, thus the
311 * responsibility of deletion lies with the user.
312 * NOTE: string search cannot be instantiated from a collator that has
313 * collate digits as numbers (CODAN) turned on.
314 * @param pattern for matching
315 * @param patternlength length of the pattern, -1 for null-termination
316 * @param text text string
317 * @param textlength length of the text string, -1 for null-termination
318 * @param collator used for the language rules
319 * @param breakiter A BreakIterator that will be used to restrict the points
320 * at which matches are detected. If a match is found, but
321 * the match's start or end index is not a boundary as
322 * determined by the <tt>BreakIterator</tt>, the match will
323 * be rejected and another will be searched for.
324 * If this parameter is <tt>NULL</tt>, no break detection is
326 * @param status for errors if it occurs. If collator, pattern or text is NULL,
327 * or if patternlength or textlength is 0 then an
328 * U_ILLEGAL_ARGUMENT_ERROR is returned.
329 * @return search iterator data structure, or NULL if there is an error.
332 U_STABLE UStringSearch
* U_EXPORT2
usearch_openFromCollator(
333 const UChar
*pattern
,
334 int32_t patternlength
,
337 const UCollator
*collator
,
338 UBreakIterator
*breakiter
,
342 * Destroying and cleaning up the search iterator data struct.
343 * If a collator is created in <tt>usearch_open</tt>, it will be destroyed here.
344 * @param searchiter data struct to clean up
347 U_STABLE
void U_EXPORT2
usearch_close(UStringSearch
*searchiter
);
349 #if U_SHOW_CPLUSPLUS_API
354 * \class LocalUStringSearchPointer
355 * "Smart pointer" class, closes a UStringSearch via usearch_close().
356 * For most methods see the LocalPointerBase base class.
358 * @see LocalPointerBase
362 U_DEFINE_LOCAL_OPEN_POINTER(LocalUStringSearchPointer
, UStringSearch
, usearch_close
);
368 /* get and set methods -------------------------------------------------- */
371 * Sets the current position in the text string which the next search will
372 * start from. Clears previous states.
373 * This method takes the argument index and sets the position in the text
374 * string accordingly without checking if the index is pointing to a
375 * valid starting point to begin searching.
376 * Search positions that may render incorrect results are highlighted in the
378 * @param strsrch search iterator data struct
379 * @param position position to start next search from. If position is less
380 * than or greater than the text range for searching,
381 * an U_INDEX_OUTOFBOUNDS_ERROR will be returned
382 * @param status error status if any.
385 U_STABLE
void U_EXPORT2
usearch_setOffset(UStringSearch
*strsrch
,
390 * Return the current index in the string text being searched.
391 * If the iteration has gone past the end of the text (or past the beginning
392 * for a backwards search), <tt>USEARCH_DONE</tt> is returned.
393 * @param strsrch search iterator data struct
397 U_STABLE
int32_t U_EXPORT2
usearch_getOffset(const UStringSearch
*strsrch
);
400 * Sets the text searching attributes located in the enum USearchAttribute
401 * with values from the enum USearchAttributeValue.
402 * <tt>USEARCH_DEFAULT</tt> can be used for all attributes for resetting.
403 * @param strsrch search iterator data struct
404 * @param attribute text attribute to be set
405 * @param value text attribute value
406 * @param status for errors if it occurs
407 * @see #usearch_getAttribute
410 U_STABLE
void U_EXPORT2
usearch_setAttribute(UStringSearch
*strsrch
,
411 USearchAttribute attribute
,
412 USearchAttributeValue value
,
416 * Gets the text searching attributes.
417 * @param strsrch search iterator data struct
418 * @param attribute text attribute to be retrieve
419 * @return text attribute value
420 * @see #usearch_setAttribute
423 U_STABLE USearchAttributeValue U_EXPORT2
usearch_getAttribute(
424 const UStringSearch
*strsrch
,
425 USearchAttribute attribute
);
428 * Returns the index to the match in the text string that was searched.
429 * This call returns a valid result only after a successful call to
430 * <tt>usearch_first</tt>, <tt>usearch_next</tt>, <tt>usearch_previous</tt>,
431 * or <tt>usearch_last</tt>.
432 * Just after construction, or after a searching method returns
433 * <tt>USEARCH_DONE</tt>, this method will return <tt>USEARCH_DONE</tt>.
435 * Use <tt>usearch_getMatchedLength</tt> to get the matched string length.
436 * @param strsrch search iterator data struct
437 * @return index to a substring within the text string that is being
439 * @see #usearch_first
441 * @see #usearch_previous
446 U_STABLE
int32_t U_EXPORT2
usearch_getMatchedStart(
447 const UStringSearch
*strsrch
);
450 * Returns the length of text in the string which matches the search pattern.
451 * This call returns a valid result only after a successful call to
452 * <tt>usearch_first</tt>, <tt>usearch_next</tt>, <tt>usearch_previous</tt>,
453 * or <tt>usearch_last</tt>.
454 * Just after construction, or after a searching method returns
455 * <tt>USEARCH_DONE</tt>, this method will return 0.
456 * @param strsrch search iterator data struct
457 * @return The length of the match in the string text, or 0 if there is no
459 * @see #usearch_first
461 * @see #usearch_previous
466 U_STABLE
int32_t U_EXPORT2
usearch_getMatchedLength(
467 const UStringSearch
*strsrch
);
470 * Returns the text that was matched by the most recent call to
471 * <tt>usearch_first</tt>, <tt>usearch_next</tt>, <tt>usearch_previous</tt>,
472 * or <tt>usearch_last</tt>.
473 * If the iterator is not pointing at a valid match (e.g. just after
474 * construction or after <tt>USEARCH_DONE</tt> has been returned, returns
475 * an empty string. If result is not large enough to store the matched text,
476 * result will be filled with the partial text and an U_BUFFER_OVERFLOW_ERROR
477 * will be returned in status. result will be null-terminated whenever
478 * possible. If the buffer fits the matched text exactly, a null-termination
479 * is not possible, then a U_STRING_NOT_TERMINATED_ERROR set in status.
480 * Pre-flighting can be either done with length = 0 or the API
481 * <tt>usearch_getMatchLength</tt>.
482 * @param strsrch search iterator data struct
483 * @param result UChar buffer to store the matched string
484 * @param resultCapacity length of the result buffer
485 * @param status error returned if result is not large enough
486 * @return exact length of the matched text, not counting the null-termination
487 * @see #usearch_first
489 * @see #usearch_previous
494 U_STABLE
int32_t U_EXPORT2
usearch_getMatchedText(const UStringSearch
*strsrch
,
496 int32_t resultCapacity
,
499 #if !UCONFIG_NO_BREAK_ITERATION
502 * Set the BreakIterator that will be used to restrict the points at which
503 * matches are detected.
504 * @param strsrch search iterator data struct
505 * @param breakiter A BreakIterator that will be used to restrict the points
506 * at which matches are detected. If a match is found, but
507 * the match's start or end index is not a boundary as
508 * determined by the <tt>BreakIterator</tt>, the match will
509 * be rejected and another will be searched for.
510 * If this parameter is <tt>NULL</tt>, no break detection is
512 * @param status for errors if it occurs
513 * @see #usearch_getBreakIterator
516 U_STABLE
void U_EXPORT2
usearch_setBreakIterator(UStringSearch
*strsrch
,
517 UBreakIterator
*breakiter
,
521 * Returns the BreakIterator that is used to restrict the points at which
522 * matches are detected. This will be the same object that was passed to the
523 * constructor or to <tt>usearch_setBreakIterator</tt>. Note that
525 * is a legal value; it means that break detection should not be attempted.
526 * @param strsrch search iterator data struct
527 * @return break iterator used
528 * @see #usearch_setBreakIterator
531 U_STABLE
const UBreakIterator
* U_EXPORT2
usearch_getBreakIterator(
532 const UStringSearch
*strsrch
);
537 * Set the string text to be searched. Text iteration will hence begin at the
538 * start of the text string. This method is useful if you want to re-use an
539 * iterator to search for the same pattern within a different body of text.
540 * @param strsrch search iterator data struct
541 * @param text new string to look for match
542 * @param textlength length of the new string, -1 for null-termination
543 * @param status for errors if it occurs. If text is NULL, or textlength is 0
544 * then an U_ILLEGAL_ARGUMENT_ERROR is returned with no change
546 * @see #usearch_getText
549 U_STABLE
void U_EXPORT2
usearch_setText( UStringSearch
*strsrch
,
555 * Return the string text to be searched.
556 * @param strsrch search iterator data struct
557 * @param length returned string text length
558 * @return string text
559 * @see #usearch_setText
562 U_STABLE
const UChar
* U_EXPORT2
usearch_getText(const UStringSearch
*strsrch
,
566 * Gets the collator used for the language rules.
568 * Deleting the returned <tt>UCollator</tt> before calling
569 * <tt>usearch_close</tt> would cause the string search to fail.
570 * <tt>usearch_close</tt> will delete the collator if this search owns it.
571 * @param strsrch search iterator data struct
575 U_STABLE UCollator
* U_EXPORT2
usearch_getCollator(
576 const UStringSearch
*strsrch
);
579 * Sets the collator used for the language rules. User retains the ownership
580 * of this collator, thus the responsibility of deletion lies with the user.
581 * This method causes internal data such as Boyer-Moore shift tables to
582 * be recalculated, but the iterator's position is unchanged.
583 * @param strsrch search iterator data struct
584 * @param collator to be used
585 * @param status for errors if it occurs
588 U_STABLE
void U_EXPORT2
usearch_setCollator( UStringSearch
*strsrch
,
589 const UCollator
*collator
,
593 * Sets the pattern used for matching.
594 * Internal data like the Boyer Moore table will be recalculated, but the
595 * iterator's position is unchanged.
596 * @param strsrch search iterator data struct
597 * @param pattern string
598 * @param patternlength pattern length, -1 for null-terminated string
599 * @param status for errors if it occurs. If text is NULL, or textlength is 0
600 * then an U_ILLEGAL_ARGUMENT_ERROR is returned with no change
604 U_STABLE
void U_EXPORT2
usearch_setPattern( UStringSearch
*strsrch
,
605 const UChar
*pattern
,
606 int32_t patternlength
,
610 * Gets the search pattern
611 * @param strsrch search iterator data struct
612 * @param length return length of the pattern, -1 indicates that the pattern
614 * @return pattern string
617 U_STABLE
const UChar
* U_EXPORT2
usearch_getPattern(
618 const UStringSearch
*strsrch
,
621 /* methods ------------------------------------------------------------- */
624 * Returns the first index at which the string text matches the search
626 * The iterator is adjusted so that its current index (as returned by
627 * <tt>usearch_getOffset</tt>) is the match position if one was found.
628 * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
629 * the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>.
630 * @param strsrch search iterator data struct
631 * @param status for errors if it occurs
632 * @return The character index of the first match, or
633 * <tt>USEARCH_DONE</tt> if there are no matches.
634 * @see #usearch_getOffset
638 U_STABLE
int32_t U_EXPORT2
usearch_first(UStringSearch
*strsrch
,
642 * Returns the first index equal or greater than <tt>position</tt> at which
644 * matches the search pattern. The iterator is adjusted so that its current
645 * index (as returned by <tt>usearch_getOffset</tt>) is the match position if
647 * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
648 * the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>
650 * Search positions that may render incorrect results are highlighted in the
651 * header comments. If position is less than or greater than the text range
652 * for searching, an U_INDEX_OUTOFBOUNDS_ERROR will be returned
653 * @param strsrch search iterator data struct
654 * @param position to start the search at
655 * @param status for errors if it occurs
656 * @return The character index of the first match following <tt>pos</tt>,
657 * or <tt>USEARCH_DONE</tt> if there are no matches.
658 * @see #usearch_getOffset
662 U_STABLE
int32_t U_EXPORT2
usearch_following(UStringSearch
*strsrch
,
667 * Returns the last index in the target text at which it matches the search
668 * pattern. The iterator is adjusted so that its current
669 * index (as returned by <tt>usearch_getOffset</tt>) is the match position if
671 * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
672 * the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>.
673 * @param strsrch search iterator data struct
674 * @param status for errors if it occurs
675 * @return The index of the first match, or <tt>USEARCH_DONE</tt> if there
677 * @see #usearch_getOffset
681 U_STABLE
int32_t U_EXPORT2
usearch_last(UStringSearch
*strsrch
,
685 * Returns the first index less than <tt>position</tt> at which the string text
686 * matches the search pattern. The iterator is adjusted so that its current
687 * index (as returned by <tt>usearch_getOffset</tt>) is the match position if
689 * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
690 * the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>
692 * Search positions that may render incorrect results are highlighted in the
693 * header comments. If position is less than or greater than the text range
694 * for searching, an U_INDEX_OUTOFBOUNDS_ERROR will be returned.
696 * When <tt>USEARCH_OVERLAP</tt> option is off, the last index of the
697 * result match is always less than <tt>position</tt>.
698 * When <tt>USERARCH_OVERLAP</tt> is on, the result match may span across
700 * @param strsrch search iterator data struct
701 * @param position index position the search is to begin at
702 * @param status for errors if it occurs
703 * @return The character index of the first match preceding <tt>pos</tt>,
704 * or <tt>USEARCH_DONE</tt> if there are no matches.
705 * @see #usearch_getOffset
709 U_STABLE
int32_t U_EXPORT2
usearch_preceding(UStringSearch
*strsrch
,
714 * Returns the index of the next point at which the string text matches the
715 * search pattern, starting from the current position.
716 * The iterator is adjusted so that its current
717 * index (as returned by <tt>usearch_getOffset</tt>) is the match position if
719 * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
720 * the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>
721 * @param strsrch search iterator data struct
722 * @param status for errors if it occurs
723 * @return The index of the next match after the current position, or
724 * <tt>USEARCH_DONE</tt> if there are no more matches.
725 * @see #usearch_first
726 * @see #usearch_getOffset
730 U_STABLE
int32_t U_EXPORT2
usearch_next(UStringSearch
*strsrch
,
734 * Returns the index of the previous point at which the string text matches
735 * the search pattern, starting at the current position.
736 * The iterator is adjusted so that its current
737 * index (as returned by <tt>usearch_getOffset</tt>) is the match position if
739 * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
740 * the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>
741 * @param strsrch search iterator data struct
742 * @param status for errors if it occurs
743 * @return The index of the previous match before the current position,
744 * or <tt>USEARCH_DONE</tt> if there are no more matches.
746 * @see #usearch_getOffset
750 U_STABLE
int32_t U_EXPORT2
usearch_previous(UStringSearch
*strsrch
,
754 * Reset the iteration.
755 * Search will begin at the start of the text string if a forward iteration
756 * is initiated before a backwards iteration. Otherwise if a backwards
757 * iteration is initiated before a forwards iteration, the search will begin
758 * at the end of the text string.
759 * @param strsrch search iterator data struct
760 * @see #usearch_first
763 U_STABLE
void U_EXPORT2
usearch_reset(UStringSearch
*strsrch
);
765 #ifndef U_HIDE_INTERNAL_API
767 * Simple forward search for the pattern, starting at a specified index,
768 * and using using a default set search options.
770 * This is an experimental function, and is not an official part of the
773 * The collator options, such as UCOL_STRENGTH and UCOL_NORMALIZTION, are honored.
775 * The UStringSearch options USEARCH_CANONICAL_MATCH, USEARCH_OVERLAP and
776 * any Break Iterator are ignored.
778 * Matches obey the following constraints:
780 * Characters at the start or end positions of a match that are ignorable
781 * for collation are not included as part of the match, unless they
782 * are part of a combining sequence, as described below.
784 * A match will not include a partial combining sequence. Combining
785 * character sequences are considered to be inseperable units,
786 * and either match the pattern completely, or are considered to not match
787 * at all. Thus, for example, an A followed a combining accent mark will
788 * not be found when searching for a plain (unaccented) A. (unless
789 * the collation strength has been set to ignore all accents).
791 * When beginning a search, the initial starting position, startIdx,
792 * is assumed to be an acceptable match boundary with respect to
793 * combining characters. A combining sequence that spans across the
794 * starting point will not supress a match beginning at startIdx.
796 * Characters that expand to multiple collation elements
797 * (German sharp-S becoming 'ss', or the composed forms of accented
798 * characters, for example) also must match completely.
799 * Searching for a single 's' in a string containing only a sharp-s will
803 * @param strsrch the UStringSearch struct, which references both
804 * the text to be searched and the pattern being sought.
805 * @param startIdx The index into the text to begin the search.
806 * @param matchStart An out parameter, the starting index of the matched text.
807 * This parameter may be NULL.
808 * A value of -1 will be returned if no match was found.
809 * @param matchLimit Out parameter, the index of the first position following the matched text.
810 * The matchLimit will be at a suitable position for beginning a subsequent search
812 * This parameter may be NULL.
813 * A value of -1 will be returned if no match was found.
815 * @param status Report any errors. Note that no match found is not an error.
816 * @return TRUE if a match was found, FALSE otherwise.
820 U_INTERNAL UBool U_EXPORT2
usearch_search(UStringSearch
*strsrch
,
827 * Simple backwards search for the pattern, starting at a specified index,
828 * and using using a default set search options.
830 * This is an experimental function, and is not an official part of the
833 * The collator options, such as UCOL_STRENGTH and UCOL_NORMALIZTION, are honored.
835 * The UStringSearch options USEARCH_CANONICAL_MATCH, USEARCH_OVERLAP and
836 * any Break Iterator are ignored.
838 * Matches obey the following constraints:
840 * Characters at the start or end positions of a match that are ignorable
841 * for collation are not included as part of the match, unless they
842 * are part of a combining sequence, as described below.
844 * A match will not include a partial combining sequence. Combining
845 * character sequences are considered to be inseperable units,
846 * and either match the pattern completely, or are considered to not match
847 * at all. Thus, for example, an A followed a combining accent mark will
848 * not be found when searching for a plain (unaccented) A. (unless
849 * the collation strength has been set to ignore all accents).
851 * When beginning a search, the initial starting position, startIdx,
852 * is assumed to be an acceptable match boundary with respect to
853 * combining characters. A combining sequence that spans across the
854 * starting point will not supress a match beginning at startIdx.
856 * Characters that expand to multiple collation elements
857 * (German sharp-S becoming 'ss', or the composed forms of accented
858 * characters, for example) also must match completely.
859 * Searching for a single 's' in a string containing only a sharp-s will
863 * @param strsrch the UStringSearch struct, which references both
864 * the text to be searched and the pattern being sought.
865 * @param startIdx The index into the text to begin the search.
866 * @param matchStart An out parameter, the starting index of the matched text.
867 * This parameter may be NULL.
868 * A value of -1 will be returned if no match was found.
869 * @param matchLimit Out parameter, the index of the first position following the matched text.
870 * The matchLimit will be at a suitable position for beginning a subsequent search
872 * This parameter may be NULL.
873 * A value of -1 will be returned if no match was found.
875 * @param status Report any errors. Note that no match found is not an error.
876 * @return TRUE if a match was found, FALSE otherwise.
880 U_INTERNAL UBool U_EXPORT2
usearch_searchBackwards(UStringSearch
*strsrch
,
885 #endif /* U_HIDE_INTERNAL_API */
887 #endif /* #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION */