ICU 65.1  65.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/localpointer.h"
19 #include "unicode/ucol.h"
20 #include "unicode/ucoleitr.h"
21 #include "unicode/ubrk.h"
22 
147 #define USEARCH_DONE -1
148 
153 struct UStringSearch;
159 
163 typedef enum {
169 #ifndef U_HIDE_DEPRECATED_API
170 
185 #endif /* U_HIDE_DEPRECATED_API */
186 
192 
193 #ifndef U_HIDE_DEPRECATED_API
194 
199 #endif /* U_HIDE_DEPRECATED_API */
201 
205 typedef enum {
267 
268 #ifndef U_HIDE_DEPRECATED_API
269 
274 #endif /* U_HIDE_DEPRECATED_API */
276 
277 /* open and close ------------------------------------------------------ */
278 
301 U_STABLE UStringSearch * U_EXPORT2 usearch_open(const UChar *pattern,
302  int32_t patternlength,
303  const UChar *text,
304  int32_t textlength,
305  const char *locale,
306  UBreakIterator *breakiter,
307  UErrorCode *status);
308 
334  const UChar *pattern,
335  int32_t patternlength,
336  const UChar *text,
337  int32_t textlength,
338  const UCollator *collator,
339  UBreakIterator *breakiter,
340  UErrorCode *status);
341 
348 U_STABLE void U_EXPORT2 usearch_close(UStringSearch *searchiter);
349 
350 #if U_SHOW_CPLUSPLUS_API
351 
352 U_NAMESPACE_BEGIN
353 
364 
365 U_NAMESPACE_END
366 
367 #endif
368 
369 /* get and set methods -------------------------------------------------- */
370 
386 U_STABLE void U_EXPORT2 usearch_setOffset(UStringSearch *strsrch,
387  int32_t position,
388  UErrorCode *status);
389 
398 U_STABLE int32_t U_EXPORT2 usearch_getOffset(const UStringSearch *strsrch);
399 
411 U_STABLE void U_EXPORT2 usearch_setAttribute(UStringSearch *strsrch,
412  USearchAttribute attribute,
413  USearchAttributeValue value,
414  UErrorCode *status);
415 
425  const UStringSearch *strsrch,
426  USearchAttribute attribute);
427 
447 U_STABLE int32_t U_EXPORT2 usearch_getMatchedStart(
448  const UStringSearch *strsrch);
449 
467 U_STABLE int32_t U_EXPORT2 usearch_getMatchedLength(
468  const UStringSearch *strsrch);
469 
495 U_STABLE int32_t U_EXPORT2 usearch_getMatchedText(const UStringSearch *strsrch,
496  UChar *result,
497  int32_t resultCapacity,
498  UErrorCode *status);
499 
500 #if !UCONFIG_NO_BREAK_ITERATION
501 
517 U_STABLE void U_EXPORT2 usearch_setBreakIterator(UStringSearch *strsrch,
518  UBreakIterator *breakiter,
519  UErrorCode *status);
520 
533  const UStringSearch *strsrch);
534 
535 #endif
536 
550 U_STABLE void U_EXPORT2 usearch_setText( UStringSearch *strsrch,
551  const UChar *text,
552  int32_t textlength,
553  UErrorCode *status);
554 
563 U_STABLE const UChar * U_EXPORT2 usearch_getText(const UStringSearch *strsrch,
564  int32_t *length);
565 
577  const UStringSearch *strsrch);
578 
589 U_STABLE void U_EXPORT2 usearch_setCollator( UStringSearch *strsrch,
590  const UCollator *collator,
591  UErrorCode *status);
592 
605 U_STABLE void U_EXPORT2 usearch_setPattern( UStringSearch *strsrch,
606  const UChar *pattern,
607  int32_t patternlength,
608  UErrorCode *status);
609 
618 U_STABLE const UChar * U_EXPORT2 usearch_getPattern(
619  const UStringSearch *strsrch,
620  int32_t *length);
621 
622 /* methods ------------------------------------------------------------- */
623 
639 U_STABLE int32_t U_EXPORT2 usearch_first(UStringSearch *strsrch,
640  UErrorCode *status);
641 
663 U_STABLE int32_t U_EXPORT2 usearch_following(UStringSearch *strsrch,
664  int32_t position,
665  UErrorCode *status);
666 
682 U_STABLE int32_t U_EXPORT2 usearch_last(UStringSearch *strsrch,
683  UErrorCode *status);
684 
710 U_STABLE int32_t U_EXPORT2 usearch_preceding(UStringSearch *strsrch,
711  int32_t position,
712  UErrorCode *status);
713 
731 U_STABLE int32_t U_EXPORT2 usearch_next(UStringSearch *strsrch,
732  UErrorCode *status);
733 
751 U_STABLE int32_t U_EXPORT2 usearch_previous(UStringSearch *strsrch,
752  UErrorCode *status);
753 
764 U_STABLE void U_EXPORT2 usearch_reset(UStringSearch *strsrch);
765 
766 #ifndef U_HIDE_INTERNAL_API
767 
821 U_INTERNAL UBool U_EXPORT2 usearch_search(UStringSearch *strsrch,
822  int32_t startIdx,
823  int32_t *matchStart,
824  int32_t *matchLimit,
825  UErrorCode *status);
826 
882  int32_t startIdx,
883  int32_t *matchStart,
884  int32_t *matchLimit,
885  UErrorCode *status);
886 #endif /* U_HIDE_INTERNAL_API */
887 
888 #endif /* #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION */
889 
890 #endif
struct UBreakIterator UBreakIterator
Opaque type representing an ICU Break iterator object.
Definition: ubrk.h:28
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...
Value for USEARCH_OVERLAP and USEARCH_CANONICAL_MATCH.
Definition: usearch.h:220
One more than the highest normal USearchAttribute value.
Definition: usearch.h:198
void usearch_close(UStringSearch *searchiter)
Destroying and cleaning up the search iterator data struct.
"Smart pointer" class, closes a UStringSearch via usearch_close().
UStringSearch * usearch_openFromCollator(const UChar *pattern, int32_t patternlength, const UChar *text, int32_t textlength, const UCollator *collator, UBreakIterator *breakiter, UErrorCode *status)
Creating a search iterator data struct using the argument collator language rule set.
int32_t usearch_getMatchedStart(const UStringSearch *strsrch)
Returns the index to the match in the text string that was searched.
const UBreakIterator * usearch_getBreakIterator(const UStringSearch *strsrch)
Returns the BreakIterator that is used to restrict the points at which matches are detected...
void usearch_setCollator(UStringSearch *strsrch, const UCollator *collator, UErrorCode *status)
Sets the collator used for the language rules.
void usearch_reset(UStringSearch *strsrch)
Reset the iteration.
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...
int32_t usearch_first(UStringSearch *strsrch, UErrorCode *status)
Returns the first index at which the string text matches the search pattern.
#define U_INTERNAL
This is used to declare a function as an internal ICU C API.
Definition: umachine.h:119
USearchAttribute
Definition: usearch.h:163
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...
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...
UCollator * usearch_getCollator(const UStringSearch *strsrch)
Gets the collator used for the language rules.
Option for overlapping matches.
Definition: usearch.h:168
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 ...
Value for USEARCH_OVERLAP and USEARCH_CANONICAL_MATCH.
Definition: usearch.h:215
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, usearch_previous, or usearch_last.
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.
int32_t usearch_getMatchedLength(const UStringSearch *strsrch)
Returns the length of text in the string which matches the search pattern.
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
Definition: localpointer.h:562
Option for canonical matches; option 1 in header documentation.
Definition: usearch.h:184
C++ API: "Smart pointers" for use with and in ICU4C C++ code.
Default value for any USearchAttribute.
Definition: usearch.h:210
C API: UCollationElements.
Value for USEARCH_ELEMENT_COMPARISON; collation element comparison is modified to effectively provide...
Definition: usearch.h:246
USearchAttributeValue
Definition: usearch.h:205
C API: Collator.
One more than the highest normal USearchAttributeValue value.
Definition: usearch.h:273
Value for USEARCH_ELEMENT_COMPARISON.
Definition: usearch.h:266
uint16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:378
void usearch_setPattern(UStringSearch *strsrch, const UChar *pattern, int32_t patternlength, UErrorCode *status)
Sets the pattern used for matching.
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...
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
C API: BreakIterator.
Value (default) for USEARCH_ELEMENT_COMPARISON; standard collation element comparison at the specifie...
Definition: usearch.h:227
Option to control how collation elements are compared.
Definition: usearch.h:191
struct UCollator UCollator
structure representing a collator object instance
Definition: ucol.h:58
Basic definitions for ICU, for both C and C++ APIs.
const UChar * usearch_getText(const UStringSearch *strsrch, int32_t *length)
Return the string text to be searched.
int32_t usearch_getOffset(const UStringSearch *strsrch)
Return the current index in the string text being searched.
int32_t usearch_next(UStringSearch *strsrch, UErrorCode *status)
Returns the index of the next point at which the string text matches the search pattern, starting from the current position.
UStringSearch * usearch_open(const UChar *pattern, int32_t patternlength, const UChar *text, int32_t textlength, const char *locale, UBreakIterator *breakiter, UErrorCode *status)
Creating a search iterator data struct using the argument locale language rule set.
void usearch_setText(UStringSearch *strsrch, const UChar *text, int32_t textlength, UErrorCode *status)
Set the string text to be searched.
struct UStringSearch UStringSearch
Data structure for searching.
Definition: usearch.h:158
int32_t usearch_previous(UStringSearch *strsrch, UErrorCode *status)
Returns the index of the previous point at which the string text matches the search pattern...
const UChar * usearch_getPattern(const UStringSearch *strsrch, int32_t *length)
Gets the search pattern.
USearchAttributeValue usearch_getAttribute(const UStringSearch *strsrch, USearchAttribute attribute)
Gets the text searching attributes.
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition: umachine.h:111
int8_t UBool
The ICU boolean type.
Definition: umachine.h:261
int32_t usearch_last(UStringSearch *strsrch, UErrorCode *status)
Returns the last index in the target text at which it matches the search pattern. ...