Loading...
Searching...
No Matches
usearch.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
* Copyright (C) 2001-2011,2014 IBM and others. All rights reserved.
**********************************************************************
* Date Name Description
* 06/28/2001 synwee Creation.
**********************************************************************
*/
#ifndef USEARCH_H
#define USEARCH_H
#include "unicode/utypes.h"
#if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
#include "unicode/ucol.h"
#include "unicode/ucoleitr.h"
#include "unicode/ubrk.h"
#if U_SHOW_CPLUSPLUS_API
#include "unicode/localpointer.h"
#endif // U_SHOW_CPLUSPLUS_API
#define USEARCH_DONE -1
struct UStringSearch;
typedef struct UStringSearch UStringSearch;
typedef enum {
USEARCH_OVERLAP = 0,
#ifndef U_HIDE_DEPRECATED_API
USEARCH_CANONICAL_MATCH = 1,
#endif /* U_HIDE_DEPRECATED_API */
USEARCH_ELEMENT_COMPARISON = 2,
#ifndef U_HIDE_DEPRECATED_API
USEARCH_ATTRIBUTE_COUNT = 3
#endif /* U_HIDE_DEPRECATED_API */
} USearchAttribute;
typedef enum {
USEARCH_DEFAULT = -1,
USEARCH_OFF,
USEARCH_ON,
USEARCH_STANDARD_ELEMENT_COMPARISON,
USEARCH_PATTERN_BASE_WEIGHT_IS_WILDCARD,
USEARCH_ANY_BASE_WEIGHT_IS_WILDCARD,
#ifndef U_HIDE_DEPRECATED_API
USEARCH_ATTRIBUTE_VALUE_COUNT
#endif /* U_HIDE_DEPRECATED_API */
} USearchAttributeValue;
/* open and close ------------------------------------------------------ */
U_CAPI UStringSearch * U_EXPORT2 usearch_open(const UChar *pattern,
int32_t patternlength,
const UChar *text,
int32_t textlength,
const char *locale,
UBreakIterator *breakiter,
UErrorCode *status);
U_CAPI UStringSearch * U_EXPORT2 usearch_openFromCollator(
const UChar *pattern,
int32_t patternlength,
const UChar *text,
int32_t textlength,
const UCollator *collator,
UBreakIterator *breakiter,
UErrorCode *status);
U_CAPI void U_EXPORT2 usearch_close(UStringSearch *searchiter);
#if U_SHOW_CPLUSPLUS_API
U_NAMESPACE_BEGIN
U_DEFINE_LOCAL_OPEN_POINTER(LocalUStringSearchPointer, UStringSearch, usearch_close);
U_NAMESPACE_END
#endif
/* get and set methods -------------------------------------------------- */
U_CAPI void U_EXPORT2 usearch_setOffset(UStringSearch *strsrch,
int32_t position,
UErrorCode *status);
U_CAPI int32_t U_EXPORT2 usearch_getOffset(const UStringSearch *strsrch);
U_CAPI void U_EXPORT2 usearch_setAttribute(UStringSearch *strsrch,
USearchAttribute attribute,
USearchAttributeValue value,
UErrorCode *status);
U_CAPI USearchAttributeValue U_EXPORT2 usearch_getAttribute(
const UStringSearch *strsrch,
USearchAttribute attribute);
U_CAPI int32_t U_EXPORT2 usearch_getMatchedStart(
const UStringSearch *strsrch);
U_CAPI int32_t U_EXPORT2 usearch_getMatchedLength(
const UStringSearch *strsrch);
U_CAPI int32_t U_EXPORT2 usearch_getMatchedText(const UStringSearch *strsrch,
UChar *result,
int32_t resultCapacity,
UErrorCode *status);
#if !UCONFIG_NO_BREAK_ITERATION
U_CAPI void U_EXPORT2 usearch_setBreakIterator(UStringSearch *strsrch,
UBreakIterator *breakiter,
UErrorCode *status);
U_CAPI const UBreakIterator * U_EXPORT2 usearch_getBreakIterator(
const UStringSearch *strsrch);
#endif
U_CAPI void U_EXPORT2 usearch_setText( UStringSearch *strsrch,
const UChar *text,
int32_t textlength,
UErrorCode *status);
U_CAPI const UChar * U_EXPORT2 usearch_getText(const UStringSearch *strsrch,
int32_t *length);
U_CAPI UCollator * U_EXPORT2 usearch_getCollator(
const UStringSearch *strsrch);
U_CAPI void U_EXPORT2 usearch_setCollator( UStringSearch *strsrch,
const UCollator *collator,
UErrorCode *status);
U_CAPI void U_EXPORT2 usearch_setPattern( UStringSearch *strsrch,
const UChar *pattern,
int32_t patternlength,
UErrorCode *status);
U_CAPI const UChar * U_EXPORT2 usearch_getPattern(
const UStringSearch *strsrch,
int32_t *length);
/* methods ------------------------------------------------------------- */
U_CAPI int32_t U_EXPORT2 usearch_first(UStringSearch *strsrch,
UErrorCode *status);
U_CAPI int32_t U_EXPORT2 usearch_following(UStringSearch *strsrch,
int32_t position,
UErrorCode *status);
U_CAPI int32_t U_EXPORT2 usearch_last(UStringSearch *strsrch,
UErrorCode *status);
U_CAPI int32_t U_EXPORT2 usearch_preceding(UStringSearch *strsrch,
int32_t position,
UErrorCode *status);
U_CAPI int32_t U_EXPORT2 usearch_next(UStringSearch *strsrch,
UErrorCode *status);
U_CAPI int32_t U_EXPORT2 usearch_previous(UStringSearch *strsrch,
UErrorCode *status);
U_CAPI void U_EXPORT2 usearch_reset(UStringSearch *strsrch);
#ifndef U_HIDE_INTERNAL_API
U_CAPI UBool U_EXPORT2 usearch_search(UStringSearch *strsrch,
int32_t startIdx,
int32_t *matchStart,
int32_t *matchLimit,
UErrorCode *status);
U_CAPI UBool U_EXPORT2 usearch_searchBackwards(UStringSearch *strsrch,
int32_t startIdx,
int32_t *matchStart,
int32_t *matchLimit,
UErrorCode *status);
#endif /* U_HIDE_INTERNAL_API */
#endif /* #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION */
#endif
LocalUStringSearchPointer
"Smart pointer" class, closes a UStringSearch via usearch_close().
localpointer.h
C++ API: "Smart pointers" for use with and in ICU4C C++ code.
U_DEFINE_LOCAL_OPEN_POINTER
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
Definition localpointer.h:548
ubrk.h
C API: BreakIterator.
UBreakIterator
struct UBreakIterator UBreakIterator
Opaque type representing an ICU Break iterator object.
Definition ubrk.h:31
ucol.h
C API: Collator.
UCollator
struct UCollator UCollator
structure representing a collator object instance
Definition ucol.h:61
ucoleitr.h
C API: UCollationElements.
UChar
char16_t UChar
The base type for UTF-16 code units and pointers.
Definition umachine.h:400
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
U_CAPI
#define U_CAPI
This is used to declare a function as a public ICU C API.
Definition umachine.h:110
usearch_getMatchedText
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,...
usearch_getMatchedLength
U_CAPI int32_t usearch_getMatchedLength(const UStringSearch *strsrch)
Returns the length of text in the string which matches the search pattern.
usearch_open
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.
usearch_setPattern
U_CAPI void usearch_setPattern(UStringSearch *strsrch, const UChar *pattern, int32_t patternlength, UErrorCode *status)
Sets the pattern used for matching.
usearch_openFromCollator
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.
usearch_getCollator
U_CAPI UCollator * usearch_getCollator(const UStringSearch *strsrch)
Gets the collator used for the language rules.
usearch_following
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...
usearch_reset
U_CAPI void usearch_reset(UStringSearch *strsrch)
Reset the iteration.
usearch_getMatchedStart
U_CAPI int32_t usearch_getMatchedStart(const UStringSearch *strsrch)
Returns the index to the match in the text string that was searched.
usearch_close
U_CAPI void usearch_close(UStringSearch *searchiter)
Destroys and cleans up the String Search iterator data struct.
usearch_setText
U_CAPI void usearch_setText(UStringSearch *strsrch, const UChar *text, int32_t textlength, UErrorCode *status)
Set the string text to be searched.
usearch_previous
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,...
usearch_getPattern
U_CAPI const UChar * usearch_getPattern(const UStringSearch *strsrch, int32_t *length)
Gets the search pattern.
usearch_last
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.
usearch_getBreakIterator
U_CAPI const UBreakIterator * usearch_getBreakIterator(const UStringSearch *strsrch)
Returns the BreakIterator that is used to restrict the points at which matches are detected.
usearch_preceding
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.
usearch_setBreakIterator
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.
usearch_setAttribute
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...
usearch_searchBackwards
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
USearchAttribute
Definition usearch.h:167
USEARCH_CANONICAL_MATCH
@ USEARCH_CANONICAL_MATCH
Option for canonical matches; option 1 in header documentation.
Definition usearch.h:188
USEARCH_ELEMENT_COMPARISON
@ USEARCH_ELEMENT_COMPARISON
Option to control how collation elements are compared.
Definition usearch.h:195
USEARCH_OVERLAP
@ USEARCH_OVERLAP
Option for overlapping matches.
Definition usearch.h:172
USEARCH_ATTRIBUTE_COUNT
@ USEARCH_ATTRIBUTE_COUNT
One more than the highest normal USearchAttribute value.
Definition usearch.h:202
usearch_getText
U_CAPI const UChar * usearch_getText(const UStringSearch *strsrch, int32_t *length)
Return the string text to be searched.
usearch_getAttribute
U_CAPI USearchAttributeValue usearch_getAttribute(const UStringSearch *strsrch, USearchAttribute attribute)
Gets the text searching attributes.
UStringSearch
struct UStringSearch UStringSearch
Data structure for searching.
Definition usearch.h:162
usearch_first
U_CAPI int32_t usearch_first(UStringSearch *strsrch, UErrorCode *status)
Returns the first index at which the string text matches the search pattern.
usearch_next
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,...
usearch_setOffset
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.
usearch_setCollator
U_CAPI void usearch_setCollator(UStringSearch *strsrch, const UCollator *collator, UErrorCode *status)
Sets the collator used for the language rules.
usearch_getOffset
U_CAPI int32_t usearch_getOffset(const UStringSearch *strsrch)
Return the current index in the string text being searched.
USearchAttributeValue
USearchAttributeValue
Definition usearch.h:209
USEARCH_ATTRIBUTE_VALUE_COUNT
@ USEARCH_ATTRIBUTE_VALUE_COUNT
One more than the highest normal USearchAttributeValue value.
Definition usearch.h:277
USEARCH_DEFAULT
@ USEARCH_DEFAULT
Default value for any USearchAttribute.
Definition usearch.h:214
USEARCH_OFF
@ USEARCH_OFF
Value for USEARCH_OVERLAP and USEARCH_CANONICAL_MATCH.
Definition usearch.h:219
USEARCH_ON
@ USEARCH_ON
Value for USEARCH_OVERLAP and USEARCH_CANONICAL_MATCH.
Definition usearch.h:224
USEARCH_STANDARD_ELEMENT_COMPARISON
@ 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
@ 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
@ USEARCH_ANY_BASE_WEIGHT_IS_WILDCARD
Value for USEARCH_ELEMENT_COMPARISON.
Definition usearch.h:270
usearch_search
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 ...
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509