ICU 71.1  71.1
usearch.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
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 **********************************************************************
10 */
11 #ifndef USEARCH_H
12 #define USEARCH_H
13 
14 #include "unicode/utypes.h"
15 
16 #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
17 
18 #include "unicode/ucol.h"
19 #include "unicode/ucoleitr.h"
20 #include "unicode/ubrk.h"
21 
22 #if U_SHOW_CPLUSPLUS_API
23 #include "unicode/localpointer.h"
24 #endif // U_SHOW_CPLUSPLUS_API
25 
151 #define USEARCH_DONE -1
152 
157 struct UStringSearch;
162 typedef struct UStringSearch UStringSearch;
163 
167 typedef enum {
173 #ifndef U_HIDE_DEPRECATED_API
189 #endif /* U_HIDE_DEPRECATED_API */
196 
197 #ifndef U_HIDE_DEPRECATED_API
203 #endif /* U_HIDE_DEPRECATED_API */
205 
209 typedef enum {
271 
272 #ifndef U_HIDE_DEPRECATED_API
278 #endif /* U_HIDE_DEPRECATED_API */
280 
281 /* open and close ------------------------------------------------------ */
282 
309 U_CAPI UStringSearch * U_EXPORT2 usearch_open(const UChar *pattern,
310  int32_t patternlength,
311  const UChar *text,
312  int32_t textlength,
313  const char *locale,
314  UBreakIterator *breakiter,
315  UErrorCode *status);
316 
347  const UChar *pattern,
348  int32_t patternlength,
349  const UChar *text,
350  int32_t textlength,
351  const UCollator *collator,
352  UBreakIterator *breakiter,
353  UErrorCode *status);
354 
361 U_CAPI void U_EXPORT2 usearch_close(UStringSearch *searchiter);
362 
363 #if U_SHOW_CPLUSPLUS_API
364 
365 U_NAMESPACE_BEGIN
366 
377 
378 U_NAMESPACE_END
379 
380 #endif
381 
382 /* get and set methods -------------------------------------------------- */
383 
399 U_CAPI void U_EXPORT2 usearch_setOffset(UStringSearch *strsrch,
400  int32_t position,
401  UErrorCode *status);
402 
411 U_CAPI int32_t U_EXPORT2 usearch_getOffset(const UStringSearch *strsrch);
412 
424 U_CAPI void U_EXPORT2 usearch_setAttribute(UStringSearch *strsrch,
425  USearchAttribute attribute,
426  USearchAttributeValue value,
427  UErrorCode *status);
428 
438  const UStringSearch *strsrch,
439  USearchAttribute attribute);
440 
460 U_CAPI int32_t U_EXPORT2 usearch_getMatchedStart(
461  const UStringSearch *strsrch);
462 
481  const UStringSearch *strsrch);
482 
508 U_CAPI int32_t U_EXPORT2 usearch_getMatchedText(const UStringSearch *strsrch,
509  UChar *result,
510  int32_t resultCapacity,
511  UErrorCode *status);
512 
513 #if !UCONFIG_NO_BREAK_ITERATION
514 
531  UBreakIterator *breakiter,
532  UErrorCode *status);
533 
546  const UStringSearch *strsrch);
547 
548 #endif
549 
567 U_CAPI void U_EXPORT2 usearch_setText( UStringSearch *strsrch,
568  const UChar *text,
569  int32_t textlength,
570  UErrorCode *status);
571 
580 U_CAPI const UChar * U_EXPORT2 usearch_getText(const UStringSearch *strsrch,
581  int32_t *length);
582 
594  const UStringSearch *strsrch);
595 
606 U_CAPI void U_EXPORT2 usearch_setCollator( UStringSearch *strsrch,
607  const UCollator *collator,
608  UErrorCode *status);
609 
626 U_CAPI void U_EXPORT2 usearch_setPattern( UStringSearch *strsrch,
627  const UChar *pattern,
628  int32_t patternlength,
629  UErrorCode *status);
630 
639 U_CAPI const UChar * U_EXPORT2 usearch_getPattern(
640  const UStringSearch *strsrch,
641  int32_t *length);
642 
643 /* methods ------------------------------------------------------------- */
644 
660 U_CAPI int32_t U_EXPORT2 usearch_first(UStringSearch *strsrch,
661  UErrorCode *status);
662 
684 U_CAPI int32_t U_EXPORT2 usearch_following(UStringSearch *strsrch,
685  int32_t position,
686  UErrorCode *status);
687 
703 U_CAPI int32_t U_EXPORT2 usearch_last(UStringSearch *strsrch,
704  UErrorCode *status);
705 
731 U_CAPI int32_t U_EXPORT2 usearch_preceding(UStringSearch *strsrch,
732  int32_t position,
733  UErrorCode *status);
734 
752 U_CAPI int32_t U_EXPORT2 usearch_next(UStringSearch *strsrch,
753  UErrorCode *status);
754 
772 U_CAPI int32_t U_EXPORT2 usearch_previous(UStringSearch *strsrch,
773  UErrorCode *status);
774 
785 U_CAPI void U_EXPORT2 usearch_reset(UStringSearch *strsrch);
786 
787 #ifndef U_HIDE_INTERNAL_API
843  int32_t startIdx,
844  int32_t *matchStart,
845  int32_t *matchLimit,
846  UErrorCode *status);
847 
903  int32_t startIdx,
904  int32_t *matchStart,
905  int32_t *matchLimit,
906  UErrorCode *status);
907 #endif /* U_HIDE_INTERNAL_API */
908 
909 #endif /* #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION */
910 
911 #endif
"Smart pointer" class, closes a UStringSearch via usearch_close().
C++ API: "Smart pointers" for use with and in ICU4C C++ code.
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
Definition: localpointer.h:550
C API: BreakIterator.
struct UBreakIterator UBreakIterator
Opaque type representing an ICU Break iterator object.
Definition: ubrk.h:31
C API: Collator.
struct UCollator UCollator
structure representing a collator object instance
Definition: ucol.h:61
C API: UCollationElements.
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
#define U_CAPI
This is used to declare a function as a public ICU C API.
Definition: umachine.h:110
char16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:418
U_CAPI int32_t usearch_getMatchedText(const UStringSearch *strsrch, UChar *result, int32_t resultCapacity, UErrorCode *status)
Returns the text that was matched by the most recent call to usearch_first, usearch_next,...
U_CAPI int32_t usearch_getMatchedLength(const UStringSearch *strsrch)
Returns the length of text in the string which matches the search pattern.
U_CAPI void usearch_setPattern(UStringSearch *strsrch, const UChar *pattern, int32_t patternlength, UErrorCode *status)
Sets the pattern used for matching.
U_CAPI int32_t usearch_following(UStringSearch *strsrch, int32_t position, UErrorCode *status)
Returns the first index equal or greater than position at which the string text matches the search pa...
U_CAPI UCollator * usearch_getCollator(const UStringSearch *strsrch)
Gets the collator used for the language rules.
U_CAPI void usearch_reset(UStringSearch *strsrch)
Reset the iteration.
U_CAPI int32_t usearch_getMatchedStart(const UStringSearch *strsrch)
Returns the index to the match in the text string that was searched.
U_CAPI void usearch_close(UStringSearch *searchiter)
Destroys and cleans up the String Search iterator data struct.
U_CAPI void usearch_setText(UStringSearch *strsrch, const UChar *text, int32_t textlength, UErrorCode *status)
Set the string text to be searched.
U_CAPI int32_t usearch_previous(UStringSearch *strsrch, UErrorCode *status)
Returns the index of the previous point at which the string text matches the search pattern,...
U_CAPI int32_t usearch_last(UStringSearch *strsrch, UErrorCode *status)
Returns the last index in the target text at which it matches the search pattern.
U_CAPI int32_t usearch_preceding(UStringSearch *strsrch, int32_t position, UErrorCode *status)
Returns the first index less than position at which the string text matches the search pattern.
U_CAPI void usearch_setBreakIterator(UStringSearch *strsrch, UBreakIterator *breakiter, UErrorCode *status)
Set the BreakIterator that will be used to restrict the points at which matches are detected.
U_CAPI void usearch_setAttribute(UStringSearch *strsrch, USearchAttribute attribute, USearchAttributeValue value, UErrorCode *status)
Sets the text searching attributes located in the enum USearchAttribute with values from the enum USe...
U_CAPI UBool usearch_searchBackwards(UStringSearch *strsrch, int32_t startIdx, int32_t *matchStart, int32_t *matchLimit, UErrorCode *status)
Simple backwards search for the pattern, starting at a specified index, and using using a default set...
USearchAttribute
Definition: usearch.h:167
@ USEARCH_CANONICAL_MATCH
Option for canonical matches; option 1 in header documentation.
Definition: usearch.h:188
@ USEARCH_ELEMENT_COMPARISON
Option to control how collation elements are compared.
Definition: usearch.h:195
@ USEARCH_OVERLAP
Option for overlapping matches.
Definition: usearch.h:172
@ USEARCH_ATTRIBUTE_COUNT
One more than the highest normal USearchAttribute value.
Definition: usearch.h:202
U_CAPI const UChar * usearch_getText(const UStringSearch *strsrch, int32_t *length)
Return the string text to be searched.
U_CAPI const UBreakIterator * usearch_getBreakIterator(const UStringSearch *strsrch)
Returns the BreakIterator that is used to restrict the points at which matches are detected.
U_CAPI USearchAttributeValue usearch_getAttribute(const UStringSearch *strsrch, USearchAttribute attribute)
Gets the text searching attributes.
struct UStringSearch UStringSearch
Data structure for searching.
Definition: usearch.h:162
U_CAPI int32_t usearch_first(UStringSearch *strsrch, UErrorCode *status)
Returns the first index at which the string text matches the search pattern.
U_CAPI UStringSearch * usearch_openFromCollator(const UChar *pattern, int32_t patternlength, const UChar *text, int32_t textlength, const UCollator *collator, UBreakIterator *breakiter, UErrorCode *status)
Creates a String Search iterator data struct using the argument collator language rule set.
U_CAPI int32_t usearch_next(UStringSearch *strsrch, UErrorCode *status)
Returns the index of the next point at which the string text matches the search pattern,...
U_CAPI void usearch_setOffset(UStringSearch *strsrch, int32_t position, UErrorCode *status)
Sets the current position in the text string which the next search will start from.
U_CAPI UStringSearch * usearch_open(const UChar *pattern, int32_t patternlength, const UChar *text, int32_t textlength, const char *locale, UBreakIterator *breakiter, UErrorCode *status)
Creates a String Search iterator data struct using the argument locale language rule set.
U_CAPI void usearch_setCollator(UStringSearch *strsrch, const UCollator *collator, UErrorCode *status)
Sets the collator used for the language rules.
U_CAPI int32_t usearch_getOffset(const UStringSearch *strsrch)
Return the current index in the string text being searched.
U_CAPI const UChar * usearch_getPattern(const UStringSearch *strsrch, int32_t *length)
Gets the search pattern.
USearchAttributeValue
Definition: usearch.h:209
@ USEARCH_ATTRIBUTE_VALUE_COUNT
One more than the highest normal USearchAttributeValue value.
Definition: usearch.h:277
@ USEARCH_DEFAULT
Default value for any USearchAttribute.
Definition: usearch.h:214
@ USEARCH_OFF
Value for USEARCH_OVERLAP and USEARCH_CANONICAL_MATCH.
Definition: usearch.h:219
@ USEARCH_ON
Value for USEARCH_OVERLAP and USEARCH_CANONICAL_MATCH.
Definition: usearch.h:224
@ USEARCH_STANDARD_ELEMENT_COMPARISON
Value (default) for USEARCH_ELEMENT_COMPARISON; standard collation element comparison at the specifie...
Definition: usearch.h:231
@ USEARCH_PATTERN_BASE_WEIGHT_IS_WILDCARD
Value for USEARCH_ELEMENT_COMPARISON; collation element comparison is modified to effectively provide...
Definition: usearch.h:250
@ USEARCH_ANY_BASE_WEIGHT_IS_WILDCARD
Value for USEARCH_ELEMENT_COMPARISON.
Definition: usearch.h:270
U_CAPI UBool usearch_search(UStringSearch *strsrch, int32_t startIdx, int32_t *matchStart, int32_t *matchLimit, UErrorCode *status)
Simple forward search for the pattern, starting at a specified index, and using a default set search ...
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415