michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (C) 2004-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: * file name: uregex.h michael@0: * encoding: US-ASCII michael@0: * indentation:4 michael@0: * michael@0: * created on: 2004mar09 michael@0: * created by: Andy Heninger michael@0: * michael@0: * ICU Regular Expressions, API for C michael@0: */ michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C API: Regular Expressions michael@0: * michael@0: *

This is a C wrapper around the C++ RegexPattern and RegexMatcher classes.

michael@0: */ michael@0: michael@0: #ifndef UREGEX_H michael@0: #define UREGEX_H michael@0: michael@0: #include "unicode/utext.h" michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_REGULAR_EXPRESSIONS michael@0: michael@0: #include "unicode/localpointer.h" michael@0: #include "unicode/parseerr.h" michael@0: michael@0: struct URegularExpression; michael@0: /** michael@0: * Structure representing a compiled regular expression, plus the results michael@0: * of a match operation. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: typedef struct URegularExpression URegularExpression; michael@0: michael@0: michael@0: /** michael@0: * Constants for Regular Expression Match Modes. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: typedef enum URegexpFlag{ michael@0: michael@0: #ifndef U_HIDE_DRAFT_API michael@0: /** Forces normalization of pattern and strings. michael@0: Not implemented yet, just a placeholder, hence draft. michael@0: @draft ICU 2.4 */ michael@0: UREGEX_CANON_EQ = 128, michael@0: #endif /* U_HIDE_DRAFT_API */ michael@0: /** Enable case insensitive matching. @stable ICU 2.4 */ michael@0: UREGEX_CASE_INSENSITIVE = 2, michael@0: michael@0: /** Allow white space and comments within patterns @stable ICU 2.4 */ michael@0: UREGEX_COMMENTS = 4, michael@0: michael@0: /** If set, '.' matches line terminators, otherwise '.' matching stops at line end. michael@0: * @stable ICU 2.4 */ michael@0: UREGEX_DOTALL = 32, michael@0: michael@0: /** If set, treat the entire pattern as a literal string. michael@0: * Metacharacters or escape sequences in the input sequence will be given michael@0: * no special meaning. michael@0: * michael@0: * The flag UREGEX_CASE_INSENSITIVE retains its impact michael@0: * on matching when used in conjunction with this flag. michael@0: * The other flags become superfluous. michael@0: * michael@0: * @stable ICU 4.0 michael@0: */ michael@0: UREGEX_LITERAL = 16, michael@0: michael@0: /** Control behavior of "$" and "^" michael@0: * If set, recognize line terminators within string, michael@0: * otherwise, match only at start and end of input string. michael@0: * @stable ICU 2.4 */ michael@0: UREGEX_MULTILINE = 8, michael@0: michael@0: /** Unix-only line endings. michael@0: * When this mode is enabled, only \\u000a is recognized as a line ending michael@0: * in the behavior of ., ^, and $. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: UREGEX_UNIX_LINES = 1, michael@0: michael@0: /** Unicode word boundaries. michael@0: * If set, \b uses the Unicode TR 29 definition of word boundaries. michael@0: * Warning: Unicode word boundaries are quite different from michael@0: * traditional regular expression word boundaries. See michael@0: * http://unicode.org/reports/tr29/#Word_Boundaries michael@0: * @stable ICU 2.8 michael@0: */ michael@0: UREGEX_UWORD = 256, michael@0: michael@0: /** Error on Unrecognized backslash escapes. michael@0: * If set, fail with an error on patterns that contain michael@0: * backslash-escaped ASCII letters without a known special michael@0: * meaning. If this flag is not set, these michael@0: * escaped letters represent themselves. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: UREGEX_ERROR_ON_UNKNOWN_ESCAPES = 512 michael@0: michael@0: } URegexpFlag; michael@0: michael@0: /** michael@0: * Open (compile) an ICU regular expression. Compiles the regular expression in michael@0: * string form into an internal representation using the specified match mode flags. michael@0: * The resulting regular expression handle can then be used to perform various michael@0: * matching operations. michael@0: * michael@0: * michael@0: * @param pattern The Regular Expression pattern to be compiled. michael@0: * @param patternLength The length of the pattern, or -1 if the pattern is michael@0: * NUL terminated. michael@0: * @param flags Flags that alter the default matching behavior for michael@0: * the regular expression, UREGEX_CASE_INSENSITIVE, for michael@0: * example. For default behavior, set this parameter to zero. michael@0: * See enum URegexpFlag. All desired flags michael@0: * are bitwise-ORed together. michael@0: * @param pe Receives the position (line and column numbers) of any syntax michael@0: * error within the source regular expression string. If this michael@0: * information is not wanted, pass NULL for this parameter. michael@0: * @param status Receives error detected by this function. michael@0: * @stable ICU 3.0 michael@0: * michael@0: */ michael@0: U_STABLE URegularExpression * U_EXPORT2 michael@0: uregex_open( const UChar *pattern, michael@0: int32_t patternLength, michael@0: uint32_t flags, michael@0: UParseError *pe, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Open (compile) an ICU regular expression. Compiles the regular expression in michael@0: * string form into an internal representation using the specified match mode flags. michael@0: * The resulting regular expression handle can then be used to perform various michael@0: * matching operations. michael@0: *

michael@0: * The contents of the pattern UText will be extracted and saved. Ownership of the michael@0: * UText struct itself remains with the caller. This is to match the behavior of michael@0: * uregex_open(). michael@0: * michael@0: * @param pattern The Regular Expression pattern to be compiled. michael@0: * @param flags Flags that alter the default matching behavior for michael@0: * the regular expression, UREGEX_CASE_INSENSITIVE, for michael@0: * example. For default behavior, set this parameter to zero. michael@0: * See enum URegexpFlag. All desired flags michael@0: * are bitwise-ORed together. michael@0: * @param pe Receives the position (line and column numbers) of any syntax michael@0: * error within the source regular expression string. If this michael@0: * information is not wanted, pass NULL for this parameter. michael@0: * @param status Receives error detected by this function. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE URegularExpression * U_EXPORT2 michael@0: uregex_openUText(UText *pattern, michael@0: uint32_t flags, michael@0: UParseError *pe, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Open (compile) an ICU regular expression. The resulting regular expression michael@0: * handle can then be used to perform various matching operations. michael@0: *

michael@0: * This function is the same as uregex_open, except that the pattern michael@0: * is supplied as an 8 bit char * string in the default code page. michael@0: * michael@0: * @param pattern The Regular Expression pattern to be compiled, michael@0: * NUL terminated. michael@0: * @param flags Flags that alter the default matching behavior for michael@0: * the regular expression, UREGEX_CASE_INSENSITIVE, for michael@0: * example. For default behavior, set this parameter to zero. michael@0: * See enum URegexpFlag. All desired flags michael@0: * are bitwise-ORed together. michael@0: * @param pe Receives the position (line and column numbers) of any syntax michael@0: * error within the source regular expression string. If this michael@0: * information is not wanted, pass NULL for this parameter. michael@0: * @param status Receives errors detected by this function. michael@0: * @return The URegularExpression object representing the compiled michael@0: * pattern. michael@0: * michael@0: * @stable ICU 3.0 michael@0: */ michael@0: #if !UCONFIG_NO_CONVERSION michael@0: U_STABLE URegularExpression * U_EXPORT2 michael@0: uregex_openC( const char *pattern, michael@0: uint32_t flags, michael@0: UParseError *pe, michael@0: UErrorCode *status); michael@0: #endif michael@0: michael@0: michael@0: michael@0: /** michael@0: * Close the regular expression, recovering all resources (memory) it michael@0: * was holding. michael@0: * michael@0: * @param regexp The regular expression to be closed. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_close(URegularExpression *regexp); michael@0: michael@0: #if U_SHOW_CPLUSPLUS_API michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: /** michael@0: * \class LocalURegularExpressionPointer michael@0: * "Smart pointer" class, closes a URegularExpression via uregex_close(). michael@0: * For most methods see the LocalPointerBase base class. michael@0: * michael@0: * @see LocalPointerBase michael@0: * @see LocalPointer michael@0: * @stable ICU 4.4 michael@0: */ michael@0: U_DEFINE_LOCAL_OPEN_POINTER(LocalURegularExpressionPointer, URegularExpression, uregex_close); michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif michael@0: michael@0: /** michael@0: * Make a copy of a compiled regular expression. Cloning a regular michael@0: * expression is faster than opening a second instance from the source michael@0: * form of the expression, and requires less memory. michael@0: *

michael@0: * Note that the current input string and the position of any matched text michael@0: * within it are not cloned; only the pattern itself and the michael@0: * match mode flags are copied. michael@0: *

michael@0: * Cloning can be particularly useful to threaded applications that perform michael@0: * multiple match operations in parallel. Each concurrent RE michael@0: * operation requires its own instance of a URegularExpression. michael@0: * michael@0: * @param regexp The compiled regular expression to be cloned. michael@0: * @param status Receives indication of any errors encountered michael@0: * @return the cloned copy of the compiled regular expression. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE URegularExpression * U_EXPORT2 michael@0: uregex_clone(const URegularExpression *regexp, UErrorCode *status); michael@0: michael@0: /** michael@0: * Returns a pointer to the source form of the pattern for this regular expression. michael@0: * This function will work even if the pattern was originally specified as a UText. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param patLength This output parameter will be set to the length of the michael@0: * pattern string. A NULL pointer may be used here if the michael@0: * pattern length is not needed, as would be the case if michael@0: * the pattern is known in advance to be a NUL terminated michael@0: * string. michael@0: * @param status Receives errors detected by this function. michael@0: * @return a pointer to the pattern string. The storage for the string is michael@0: * owned by the regular expression object, and must not be michael@0: * altered or deleted by the application. The returned string michael@0: * will remain valid until the regular expression is closed. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE const UChar * U_EXPORT2 michael@0: uregex_pattern(const URegularExpression *regexp, michael@0: int32_t *patLength, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Returns the source text of the pattern for this regular expression. michael@0: * This function will work even if the pattern was originally specified as a UChar string. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param status Receives errors detected by this function. michael@0: * @return the pattern text. The storage for the text is owned by the regular expression michael@0: * object, and must not be altered or deleted. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE UText * U_EXPORT2 michael@0: uregex_patternUText(const URegularExpression *regexp, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Get the match mode flags that were specified when compiling this regular expression. michael@0: * @param status Receives errors detected by this function. michael@0: * @param regexp The compiled regular expression. michael@0: * @return The match mode flags michael@0: * @see URegexpFlag michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uregex_flags(const URegularExpression *regexp, michael@0: UErrorCode *status); michael@0: michael@0: michael@0: /** michael@0: * Set the subject text string upon which the regular expression will look for matches. michael@0: * This function may be called any number of times, allowing the regular michael@0: * expression pattern to be applied to different strings. michael@0: *

michael@0: * Regular expression matching operations work directly on the application's michael@0: * string data. No copy is made. The subject string data must not be michael@0: * altered after calling this function until after all regular expression michael@0: * operations involving this string data are completed. michael@0: *

michael@0: * Zero length strings are permitted. In this case, no subsequent match michael@0: * operation will dereference the text string pointer. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param text The subject text string. michael@0: * @param textLength The length of the subject text, or -1 if the string michael@0: * is NUL terminated. michael@0: * @param status Receives errors detected by this function. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_setText(URegularExpression *regexp, michael@0: const UChar *text, michael@0: int32_t textLength, michael@0: UErrorCode *status); michael@0: michael@0: michael@0: /** michael@0: * Set the subject text string upon which the regular expression will look for matches. michael@0: * This function may be called any number of times, allowing the regular michael@0: * expression pattern to be applied to different strings. michael@0: *

michael@0: * Regular expression matching operations work directly on the application's michael@0: * string data; only a shallow clone is made. The subject string data must not be michael@0: * altered after calling this function until after all regular expression michael@0: * operations involving this string data are completed. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param text The subject text string. michael@0: * @param status Receives errors detected by this function. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_setUText(URegularExpression *regexp, michael@0: UText *text, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Get the subject text that is currently associated with this michael@0: * regular expression object. If the input was supplied using uregex_setText(), michael@0: * that pointer will be returned. Otherwise, the characters in the input will michael@0: * be extracted to a buffer and returned. In either case, ownership remains michael@0: * with the regular expression object. michael@0: * michael@0: * This function will work even if the input was originally specified as a UText. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param textLength The length of the string is returned in this output parameter. michael@0: * A NULL pointer may be used here if the michael@0: * text length is not needed, as would be the case if michael@0: * the text is known in advance to be a NUL terminated michael@0: * string. michael@0: * @param status Receives errors detected by this function. michael@0: * @return Pointer to the subject text string currently associated with michael@0: * this regular expression. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE const UChar * U_EXPORT2 michael@0: uregex_getText(URegularExpression *regexp, michael@0: int32_t *textLength, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Get the subject text that is currently associated with this michael@0: * regular expression object. michael@0: * michael@0: * This function will work even if the input was originally specified as a UChar string. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param dest A mutable UText in which to store the current input. michael@0: * If NULL, a new UText will be created as an immutable shallow clone michael@0: * of the actual input string. michael@0: * @param status Receives errors detected by this function. michael@0: * @return The subject text currently associated with this regular expression. michael@0: * If a pre-allocated UText was provided, it will always be used and returned. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE UText * U_EXPORT2 michael@0: uregex_getUText(URegularExpression *regexp, michael@0: UText *dest, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Set the subject text string upon which the regular expression is looking for matches michael@0: * without changing any other aspect of the matching state. michael@0: * The new and previous text strings must have the same content. michael@0: * michael@0: * This function is intended for use in environments where ICU is operating on michael@0: * strings that may move around in memory. It provides a mechanism for notifying michael@0: * ICU that the string has been relocated, and providing a new UText to access the michael@0: * string in its new position. michael@0: * michael@0: * Note that the regular expression implementation never copies the underlying text michael@0: * of a string being matched, but always operates directly on the original text michael@0: * provided by the user. Refreshing simply drops the references to the old text michael@0: * and replaces them with references to the new. michael@0: * michael@0: * Caution: this function is normally used only by very specialized michael@0: * system-level code. One example use case is with garbage collection michael@0: * that moves the text in memory. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param text The new (moved) text string. michael@0: * @param status Receives errors detected by this function. michael@0: * michael@0: * @stable ICU 4.8 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_refreshUText(URegularExpression *regexp, michael@0: UText *text, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Attempts to match the input string against the pattern. michael@0: * To succeed, the match must extend to the end of the string, michael@0: * or cover the complete match region. michael@0: * michael@0: * If startIndex >= zero the match operation starts at the specified michael@0: * index and must extend to the end of the input string. Any region michael@0: * that has been specified is reset. michael@0: * michael@0: * If startIndex == -1 the match must cover the input region, or the entire michael@0: * input string if no region has been set. This directly corresponds to michael@0: * Matcher.matches() in Java michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param startIndex The input string (native) index at which to begin matching, or -1 michael@0: * to match the input Region. michael@0: * @param status Receives errors detected by this function. michael@0: * @return TRUE if there is a match michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uregex_matches(URegularExpression *regexp, michael@0: int32_t startIndex, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * 64bit version of uregex_matches. michael@0: * Attempts to match the input string against the pattern. michael@0: * To succeed, the match must extend to the end of the string, michael@0: * or cover the complete match region. michael@0: * michael@0: * If startIndex >= zero the match operation starts at the specified michael@0: * index and must extend to the end of the input string. Any region michael@0: * that has been specified is reset. michael@0: * michael@0: * If startIndex == -1 the match must cover the input region, or the entire michael@0: * input string if no region has been set. This directly corresponds to michael@0: * Matcher.matches() in Java michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param startIndex The input string (native) index at which to begin matching, or -1 michael@0: * to match the input Region. michael@0: * @param status Receives errors detected by this function. michael@0: * @return TRUE if there is a match michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uregex_matches64(URegularExpression *regexp, michael@0: int64_t startIndex, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Attempts to match the input string, starting from the specified index, against the pattern. michael@0: * The match may be of any length, and is not required to extend to the end michael@0: * of the input string. Contrast with uregex_matches(). michael@0: * michael@0: *

If startIndex is >= 0 any input region that was set for this michael@0: * URegularExpression is reset before the operation begins. michael@0: * michael@0: *

If the specified starting index == -1 the match begins at the start of the input michael@0: * region, or at the start of the full string if no region has been specified. michael@0: * This corresponds directly with Matcher.lookingAt() in Java. michael@0: * michael@0: *

If the match succeeds then more information can be obtained via the michael@0: * uregexp_start(), uregexp_end(), michael@0: * and uregexp_group() functions.

michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param startIndex The input string (native) index at which to begin matching, or michael@0: * -1 to match the Input Region michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return TRUE if there is a match. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uregex_lookingAt(URegularExpression *regexp, michael@0: int32_t startIndex, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * 64bit version of uregex_lookingAt. michael@0: * Attempts to match the input string, starting from the specified index, against the pattern. michael@0: * The match may be of any length, and is not required to extend to the end michael@0: * of the input string. Contrast with uregex_matches(). michael@0: * michael@0: *

If startIndex is >= 0 any input region that was set for this michael@0: * URegularExpression is reset before the operation begins. michael@0: * michael@0: *

If the specified starting index == -1 the match begins at the start of the input michael@0: * region, or at the start of the full string if no region has been specified. michael@0: * This corresponds directly with Matcher.lookingAt() in Java. michael@0: * michael@0: *

If the match succeeds then more information can be obtained via the michael@0: * uregexp_start(), uregexp_end(), michael@0: * and uregexp_group() functions.

michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param startIndex The input string (native) index at which to begin matching, or michael@0: * -1 to match the Input Region michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return TRUE if there is a match. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uregex_lookingAt64(URegularExpression *regexp, michael@0: int64_t startIndex, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Find the first matching substring of the input string that matches the pattern. michael@0: * If startIndex is >= zero the search for a match begins at the specified index, michael@0: * and any match region is reset. This corresponds directly with michael@0: * Matcher.find(startIndex) in Java. michael@0: * michael@0: * If startIndex == -1 the search begins at the start of the input region, michael@0: * or at the start of the full string if no region has been specified. michael@0: * michael@0: * If a match is found, uregex_start(), uregex_end(), and michael@0: * uregex_group() will provide more information regarding the match. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param startIndex The position (native) in the input string to begin the search, or michael@0: * -1 to search within the Input Region. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return TRUE if a match is found. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uregex_find(URegularExpression *regexp, michael@0: int32_t startIndex, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * 64bit version of uregex_find. michael@0: * Find the first matching substring of the input string that matches the pattern. michael@0: * If startIndex is >= zero the search for a match begins at the specified index, michael@0: * and any match region is reset. This corresponds directly with michael@0: * Matcher.find(startIndex) in Java. michael@0: * michael@0: * If startIndex == -1 the search begins at the start of the input region, michael@0: * or at the start of the full string if no region has been specified. michael@0: * michael@0: * If a match is found, uregex_start(), uregex_end(), and michael@0: * uregex_group() will provide more information regarding the match. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param startIndex The position (native) in the input string to begin the search, or michael@0: * -1 to search within the Input Region. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return TRUE if a match is found. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uregex_find64(URegularExpression *regexp, michael@0: int64_t startIndex, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Find the next pattern match in the input string. Begin searching michael@0: * the input at the location following the end of he previous match, michael@0: * or at the start of the string (or region) if there is no michael@0: * previous match. If a match is found, uregex_start(), uregex_end(), and michael@0: * uregex_group() will provide more information regarding the match. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return TRUE if a match is found. michael@0: * @see uregex_reset michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uregex_findNext(URegularExpression *regexp, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Get the number of capturing groups in this regular expression's pattern. michael@0: * @param regexp The compiled regular expression. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return the number of capture groups michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uregex_groupCount(URegularExpression *regexp, michael@0: UErrorCode *status); michael@0: michael@0: /** Extract the string for the specified matching expression or subexpression. michael@0: * Group #0 is the complete string of matched text. michael@0: * Group #1 is the text matched by the first set of capturing parentheses. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param groupNum The capture group to extract. Group 0 is the complete michael@0: * match. The value of this parameter must be michael@0: * less than or equal to the number of capture groups in michael@0: * the pattern. michael@0: * @param dest Buffer to receive the matching string data michael@0: * @param destCapacity Capacity of the dest buffer. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return Length of matching data, michael@0: * or -1 if no applicable match. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uregex_group(URegularExpression *regexp, michael@0: int32_t groupNum, michael@0: UChar *dest, michael@0: int32_t destCapacity, michael@0: UErrorCode *status); michael@0: michael@0: /** Returns a shallow immutable clone of the entire input string. The returned UText current native index michael@0: * is set to the beginning of the requested capture group. The capture group length is also michael@0: * returned via groupLength. michael@0: * Group #0 is the complete string of matched text. michael@0: * Group #1 is the text matched by the first set of capturing parentheses. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param groupNum The capture group to extract. Group 0 is the complete michael@0: * match. The value of this parameter must be michael@0: * less than or equal to the number of capture groups in michael@0: * the pattern. michael@0: * @param dest A mutable UText in which to store the current input. michael@0: * If NULL, a new UText will be created as an immutable shallow clone michael@0: * of the entire input string. michael@0: * @param groupLength The group length of the desired capture group. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return The subject text currently associated with this regular expression. michael@0: * If a pre-allocated UText was provided, it will always be used and returned. michael@0: michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE UText * U_EXPORT2 michael@0: uregex_groupUText(URegularExpression *regexp, michael@0: int32_t groupNum, michael@0: UText *dest, michael@0: int64_t *groupLength, michael@0: UErrorCode *status); michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** Extract the string for the specified matching expression or subexpression. michael@0: * Group #0 is the complete string of matched text. michael@0: * Group #1 is the text matched by the first set of capturing parentheses. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param groupNum The capture group to extract. Group 0 is the complete michael@0: * match. The value of this parameter must be michael@0: * less than or equal to the number of capture groups in michael@0: * the pattern. michael@0: * @param dest Mutable UText to receive the matching string data. michael@0: * If NULL, a new UText will be created (which may not be mutable). michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return The matching string data. If a pre-allocated UText was provided, michael@0: * it will always be used and returned. michael@0: * michael@0: * @internal ICU 4.4 technology preview michael@0: */ michael@0: U_INTERNAL UText * U_EXPORT2 michael@0: uregex_groupUTextDeep(URegularExpression *regexp, michael@0: int32_t groupNum, michael@0: UText *dest, michael@0: UErrorCode *status); michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: /** michael@0: * Returns the index in the input string of the start of the text matched by the michael@0: * specified capture group during the previous match operation. Return -1 if michael@0: * the capture group was not part of the last match. michael@0: * Group #0 refers to the complete range of matched text. michael@0: * Group #1 refers to the text matched by the first set of capturing parentheses. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param groupNum The capture group number michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return the starting (native) position in the input of the text matched michael@0: * by the specified group. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uregex_start(URegularExpression *regexp, michael@0: int32_t groupNum, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * 64bit version of uregex_start. michael@0: * Returns the index in the input string of the start of the text matched by the michael@0: * specified capture group during the previous match operation. Return -1 if michael@0: * the capture group was not part of the last match. michael@0: * Group #0 refers to the complete range of matched text. michael@0: * Group #1 refers to the text matched by the first set of capturing parentheses. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param groupNum The capture group number michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return the starting (native) position in the input of the text matched michael@0: * by the specified group. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE int64_t U_EXPORT2 michael@0: uregex_start64(URegularExpression *regexp, michael@0: int32_t groupNum, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Returns the index in the input string of the position following the end michael@0: * of the text matched by the specified capture group. michael@0: * Return -1 if the capture group was not part of the last match. michael@0: * Group #0 refers to the complete range of matched text. michael@0: * Group #1 refers to the text matched by the first set of capturing parentheses. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param groupNum The capture group number michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return the (native) index of the position following the last matched character. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uregex_end(URegularExpression *regexp, michael@0: int32_t groupNum, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * 64bit version of uregex_end. michael@0: * Returns the index in the input string of the position following the end michael@0: * of the text matched by the specified capture group. michael@0: * Return -1 if the capture group was not part of the last match. michael@0: * Group #0 refers to the complete range of matched text. michael@0: * Group #1 refers to the text matched by the first set of capturing parentheses. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param groupNum The capture group number michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return the (native) index of the position following the last matched character. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE int64_t U_EXPORT2 michael@0: uregex_end64(URegularExpression *regexp, michael@0: int32_t groupNum, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Reset any saved state from the previous match. Has the effect of michael@0: * causing uregex_findNext to begin at the specified index, and causing michael@0: * uregex_start(), uregex_end() and uregex_group() to return an error michael@0: * indicating that there is no match information available. Clears any michael@0: * match region that may have been set. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param index The position (native) in the text at which a michael@0: * uregex_findNext() should begin searching. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_reset(URegularExpression *regexp, michael@0: int32_t index, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * 64bit version of uregex_reset. michael@0: * Reset any saved state from the previous match. Has the effect of michael@0: * causing uregex_findNext to begin at the specified index, and causing michael@0: * uregex_start(), uregex_end() and uregex_group() to return an error michael@0: * indicating that there is no match information available. Clears any michael@0: * match region that may have been set. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param index The position (native) in the text at which a michael@0: * uregex_findNext() should begin searching. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_reset64(URegularExpression *regexp, michael@0: int64_t index, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Sets the limits of the matching region for this URegularExpression. michael@0: * The region is the part of the input string that will be considered when matching. michael@0: * Invoking this method resets any saved state from the previous match, michael@0: * then sets the region to start at the index specified by the start parameter michael@0: * and end at the index specified by the end parameter. michael@0: * michael@0: * Depending on the transparency and anchoring being used (see useTransparentBounds michael@0: * and useAnchoringBounds), certain constructs such as anchors may behave differently michael@0: * at or around the boundaries of the region michael@0: * michael@0: * The function will fail if start is greater than limit, or if either index michael@0: * is less than zero or greater than the length of the string being matched. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param regionStart The (native) index to begin searches at. michael@0: * @param regionLimit The (native) index to end searches at (exclusive). michael@0: * @param status A pointer to a UErrorCode to receive any errors. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_setRegion(URegularExpression *regexp, michael@0: int32_t regionStart, michael@0: int32_t regionLimit, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * 64bit version of uregex_setRegion. michael@0: * Sets the limits of the matching region for this URegularExpression. michael@0: * The region is the part of the input string that will be considered when matching. michael@0: * Invoking this method resets any saved state from the previous match, michael@0: * then sets the region to start at the index specified by the start parameter michael@0: * and end at the index specified by the end parameter. michael@0: * michael@0: * Depending on the transparency and anchoring being used (see useTransparentBounds michael@0: * and useAnchoringBounds), certain constructs such as anchors may behave differently michael@0: * at or around the boundaries of the region michael@0: * michael@0: * The function will fail if start is greater than limit, or if either index michael@0: * is less than zero or greater than the length of the string being matched. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param regionStart The (native) index to begin searches at. michael@0: * @param regionLimit The (native) index to end searches at (exclusive). michael@0: * @param status A pointer to a UErrorCode to receive any errors. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_setRegion64(URegularExpression *regexp, michael@0: int64_t regionStart, michael@0: int64_t regionLimit, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Set the matching region and the starting index for subsequent matches michael@0: * in a single operation. michael@0: * This is useful because the usual function for setting the starting michael@0: * index, urgex_reset(), also resets any region limits. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param regionStart The (native) index to begin searches at. michael@0: * @param regionLimit The (native) index to end searches at (exclusive). michael@0: * @param startIndex The index in the input text at which the next michael@0: * match operation should begin. michael@0: * @param status A pointer to a UErrorCode to receive any errors. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_setRegionAndStart(URegularExpression *regexp, michael@0: int64_t regionStart, michael@0: int64_t regionLimit, michael@0: int64_t startIndex, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Reports the start index of the matching region. Any matches found are limited to michael@0: * to the region bounded by regionStart (inclusive) and regionEnd (exclusive). michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param status A pointer to a UErrorCode to receive any errors. michael@0: * @return The starting (native) index of this matcher's region. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uregex_regionStart(const URegularExpression *regexp, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * 64bit version of uregex_regionStart. michael@0: * Reports the start index of the matching region. Any matches found are limited to michael@0: * to the region bounded by regionStart (inclusive) and regionEnd (exclusive). michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param status A pointer to a UErrorCode to receive any errors. michael@0: * @return The starting (native) index of this matcher's region. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE int64_t U_EXPORT2 michael@0: uregex_regionStart64(const URegularExpression *regexp, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Reports the end index (exclusive) of the matching region for this URegularExpression. michael@0: * Any matches found are limited to to the region bounded by regionStart (inclusive) michael@0: * and regionEnd (exclusive). michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param status A pointer to a UErrorCode to receive any errors. michael@0: * @return The ending point (native) of this matcher's region. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uregex_regionEnd(const URegularExpression *regexp, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * 64bit version of uregex_regionEnd. michael@0: * Reports the end index (exclusive) of the matching region for this URegularExpression. michael@0: * Any matches found are limited to to the region bounded by regionStart (inclusive) michael@0: * and regionEnd (exclusive). michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param status A pointer to a UErrorCode to receive any errors. michael@0: * @return The ending point (native) of this matcher's region. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE int64_t U_EXPORT2 michael@0: uregex_regionEnd64(const URegularExpression *regexp, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Queries the transparency of region bounds for this URegularExpression. michael@0: * See useTransparentBounds for a description of transparent and opaque bounds. michael@0: * By default, matching boundaries are opaque. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param status A pointer to a UErrorCode to receive any errors. michael@0: * @return TRUE if this matcher is using opaque bounds, false if it is not. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uregex_hasTransparentBounds(const URegularExpression *regexp, michael@0: UErrorCode *status); michael@0: michael@0: michael@0: /** michael@0: * Sets the transparency of region bounds for this URegularExpression. michael@0: * Invoking this function with an argument of TRUE will set matches to use transparent bounds. michael@0: * If the boolean argument is FALSE, then opaque bounds will be used. michael@0: * michael@0: * Using transparent bounds, the boundaries of the matching region are transparent michael@0: * to lookahead, lookbehind, and boundary matching constructs. Those constructs can michael@0: * see text beyond the boundaries of the region while checking for a match. michael@0: * michael@0: * With opaque bounds, no text outside of the matching region is visible to lookahead, michael@0: * lookbehind, and boundary matching constructs. michael@0: * michael@0: * By default, opaque bounds are used. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param b TRUE for transparent bounds; FALSE for opaque bounds michael@0: * @param status A pointer to a UErrorCode to receive any errors. michael@0: * @stable ICU 4.0 michael@0: **/ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_useTransparentBounds(URegularExpression *regexp, michael@0: UBool b, michael@0: UErrorCode *status); michael@0: michael@0: michael@0: /** michael@0: * Return true if this URegularExpression is using anchoring bounds. michael@0: * By default, anchoring region bounds are used. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param status A pointer to a UErrorCode to receive any errors. michael@0: * @return TRUE if this matcher is using anchoring bounds. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uregex_hasAnchoringBounds(const URegularExpression *regexp, michael@0: UErrorCode *status); michael@0: michael@0: michael@0: /** michael@0: * Set whether this URegularExpression is using Anchoring Bounds for its region. michael@0: * With anchoring bounds, pattern anchors such as ^ and $ will match at the start michael@0: * and end of the region. Without Anchoring Bounds, anchors will only match at michael@0: * the positions they would in the complete text. michael@0: * michael@0: * Anchoring Bounds are the default for regions. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param b TRUE if to enable anchoring bounds; FALSE to disable them. michael@0: * @param status A pointer to a UErrorCode to receive any errors. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_useAnchoringBounds(URegularExpression *regexp, michael@0: UBool b, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Return TRUE if the most recent matching operation touched the michael@0: * end of the text being processed. In this case, additional input text could michael@0: * change the results of that match. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param status A pointer to a UErrorCode to receive any errors. michael@0: * @return TRUE if the most recent match hit the end of input michael@0: * @stable ICU 4.0 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uregex_hitEnd(const URegularExpression *regexp, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Return TRUE the most recent match succeeded and additional input could cause michael@0: * it to fail. If this function returns false and a match was found, then more input michael@0: * might change the match but the match won't be lost. If a match was not found, michael@0: * then requireEnd has no meaning. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param status A pointer to a UErrorCode to receive any errors. michael@0: * @return TRUE if more input could cause the most recent match to no longer match. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uregex_requireEnd(const URegularExpression *regexp, michael@0: UErrorCode *status); michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: /** michael@0: * Replaces every substring of the input that matches the pattern michael@0: * with the given replacement string. This is a convenience function that michael@0: * provides a complete find-and-replace-all operation. michael@0: * michael@0: * This method scans the input string looking for matches of the pattern. michael@0: * Input that is not part of any match is copied unchanged to the michael@0: * destination buffer. Matched regions are replaced in the output michael@0: * buffer by the replacement string. The replacement string may contain michael@0: * references to capture groups; these take the form of $1, $2, etc. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param replacementText A string containing the replacement text. michael@0: * @param replacementLength The length of the replacement string, or michael@0: * -1 if it is NUL terminated. michael@0: * @param destBuf A (UChar *) buffer that will receive the result. michael@0: * @param destCapacity The capacity of the destination buffer. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return The length of the string resulting from the find michael@0: * and replace operation. In the event that the michael@0: * destination capacity is inadequate, the return value michael@0: * is still the full length of the untruncated string. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uregex_replaceAll(URegularExpression *regexp, michael@0: const UChar *replacementText, michael@0: int32_t replacementLength, michael@0: UChar *destBuf, michael@0: int32_t destCapacity, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Replaces every substring of the input that matches the pattern michael@0: * with the given replacement string. This is a convenience function that michael@0: * provides a complete find-and-replace-all operation. michael@0: * michael@0: * This method scans the input string looking for matches of the pattern. michael@0: * Input that is not part of any match is copied unchanged to the michael@0: * destination buffer. Matched regions are replaced in the output michael@0: * buffer by the replacement string. The replacement string may contain michael@0: * references to capture groups; these take the form of $1, $2, etc. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param replacement A string containing the replacement text. michael@0: * @param dest A mutable UText that will receive the result. michael@0: * If NULL, a new UText will be created (which may not be mutable). michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return A UText containing the results of the find and replace. michael@0: * If a pre-allocated UText was provided, it will always be used and returned. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE UText * U_EXPORT2 michael@0: uregex_replaceAllUText(URegularExpression *regexp, michael@0: UText *replacement, michael@0: UText *dest, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Replaces the first substring of the input that matches the pattern michael@0: * with the given replacement string. This is a convenience function that michael@0: * provides a complete find-and-replace operation. michael@0: * michael@0: * This method scans the input string looking for a match of the pattern. michael@0: * All input that is not part of the match is copied unchanged to the michael@0: * destination buffer. The matched region is replaced in the output michael@0: * buffer by the replacement string. The replacement string may contain michael@0: * references to capture groups; these take the form of $1, $2, etc. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param replacementText A string containing the replacement text. michael@0: * @param replacementLength The length of the replacement string, or michael@0: * -1 if it is NUL terminated. michael@0: * @param destBuf A (UChar *) buffer that will receive the result. michael@0: * @param destCapacity The capacity of the destination buffer. michael@0: * @param status a reference to a UErrorCode to receive any errors. michael@0: * @return The length of the string resulting from the find michael@0: * and replace operation. In the event that the michael@0: * destination capacity is inadequate, the return value michael@0: * is still the full length of the untruncated string. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uregex_replaceFirst(URegularExpression *regexp, michael@0: const UChar *replacementText, michael@0: int32_t replacementLength, michael@0: UChar *destBuf, michael@0: int32_t destCapacity, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Replaces the first substring of the input that matches the pattern michael@0: * with the given replacement string. This is a convenience function that michael@0: * provides a complete find-and-replace operation. michael@0: * michael@0: * This method scans the input string looking for a match of the pattern. michael@0: * All input that is not part of the match is copied unchanged to the michael@0: * destination buffer. The matched region is replaced in the output michael@0: * buffer by the replacement string. The replacement string may contain michael@0: * references to capture groups; these take the form of $1, $2, etc. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param replacement A string containing the replacement text. michael@0: * @param dest A mutable UText that will receive the result. michael@0: * If NULL, a new UText will be created (which may not be mutable). michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return A UText containing the results of the find and replace. michael@0: * If a pre-allocated UText was provided, it will always be used and returned. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE UText * U_EXPORT2 michael@0: uregex_replaceFirstUText(URegularExpression *regexp, michael@0: UText *replacement, michael@0: UText *dest, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Implements a replace operation intended to be used as part of an michael@0: * incremental find-and-replace. michael@0: * michael@0: *

The input string, starting from the end of the previous match and ending at michael@0: * the start of the current match, is appended to the destination string. Then the michael@0: * replacement string is appended to the output string, michael@0: * including handling any substitutions of captured text.

michael@0: * michael@0: *

A note on preflight computation of buffersize and error handling: michael@0: * Calls to uregex_appendReplacement() and uregex_appendTail() are michael@0: * designed to be chained, one after another, with the destination michael@0: * buffer pointer and buffer capacity updated after each in preparation michael@0: * to for the next. If the destination buffer is exhausted partway through such a michael@0: * sequence, a U_BUFFER_OVERFLOW_ERROR status will be returned. Normal michael@0: * ICU conventions are for a function to perform no action if it is michael@0: * called with an error status, but for this one case, uregex_appendRepacement() michael@0: * will operate normally so that buffer size computations will complete michael@0: * correctly. michael@0: * michael@0: *

For simple, prepackaged, non-incremental find-and-replace michael@0: * operations, see replaceFirst() or replaceAll().

michael@0: * michael@0: * @param regexp The regular expression object. michael@0: * @param replacementText The string that will replace the matched portion of the michael@0: * input string as it is copied to the destination buffer. michael@0: * The replacement text may contain references ($1, for michael@0: * example) to capture groups from the match. michael@0: * @param replacementLength The length of the replacement text string, michael@0: * or -1 if the string is NUL terminated. michael@0: * @param destBuf The buffer into which the results of the michael@0: * find-and-replace are placed. On return, this pointer michael@0: * will be updated to refer to the beginning of the michael@0: * unused portion of buffer, leaving it in position for michael@0: * a subsequent call to this function. michael@0: * @param destCapacity The size of the output buffer, On return, this michael@0: * parameter will be updated to reflect the space remaining michael@0: * unused in the output buffer. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return The length of the result string. In the event that michael@0: * destCapacity is inadequate, the full length of the michael@0: * untruncated output string is returned. michael@0: * michael@0: * @stable ICU 3.0 michael@0: * michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uregex_appendReplacement(URegularExpression *regexp, michael@0: const UChar *replacementText, michael@0: int32_t replacementLength, michael@0: UChar **destBuf, michael@0: int32_t *destCapacity, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Implements a replace operation intended to be used as part of an michael@0: * incremental find-and-replace. michael@0: * michael@0: *

The input string, starting from the end of the previous match and ending at michael@0: * the start of the current match, is appended to the destination string. Then the michael@0: * replacement string is appended to the output string, michael@0: * including handling any substitutions of captured text.

michael@0: * michael@0: *

For simple, prepackaged, non-incremental find-and-replace michael@0: * operations, see replaceFirst() or replaceAll().

michael@0: * michael@0: * @param regexp The regular expression object. michael@0: * @param replacementText The string that will replace the matched portion of the michael@0: * input string as it is copied to the destination buffer. michael@0: * The replacement text may contain references ($1, for michael@0: * example) to capture groups from the match. michael@0: * @param dest A mutable UText that will receive the result. Must not be NULL. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_appendReplacementUText(URegularExpression *regexp, michael@0: UText *replacementText, michael@0: UText *dest, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * As the final step in a find-and-replace operation, append the remainder michael@0: * of the input string, starting at the position following the last match, michael@0: * to the destination string. uregex_appendTail() is intended michael@0: * to be invoked after one or more invocations of the michael@0: * uregex_appendReplacement() function. michael@0: * michael@0: * @param regexp The regular expression object. This is needed to michael@0: * obtain the input string and with the position michael@0: * of the last match within it. michael@0: * @param destBuf The buffer in which the results of the michael@0: * find-and-replace are placed. On return, the pointer michael@0: * will be updated to refer to the beginning of the michael@0: * unused portion of buffer. michael@0: * @param destCapacity The size of the output buffer, On return, this michael@0: * value will be updated to reflect the space remaining michael@0: * unused in the output buffer. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return The length of the result string. In the event that michael@0: * destCapacity is inadequate, the full length of the michael@0: * untruncated output string is returned. michael@0: * michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uregex_appendTail(URegularExpression *regexp, michael@0: UChar **destBuf, michael@0: int32_t *destCapacity, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * As the final step in a find-and-replace operation, append the remainder michael@0: * of the input string, starting at the position following the last match, michael@0: * to the destination string. uregex_appendTailUText() is intended michael@0: * to be invoked after one or more invocations of the michael@0: * uregex_appendReplacementUText() function. michael@0: * michael@0: * @param regexp The regular expression object. This is needed to michael@0: * obtain the input string and with the position michael@0: * of the last match within it. michael@0: * @param dest A mutable UText that will receive the result. Must not be NULL. michael@0: * michael@0: * @param status Error code michael@0: * michael@0: * @return The destination UText. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE UText * U_EXPORT2 michael@0: uregex_appendTailUText(URegularExpression *regexp, michael@0: UText *dest, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Split a string into fields. Somewhat like split() from Perl. michael@0: * The pattern matches identify delimiters that separate the input michael@0: * into fields. The input data between the matches becomes the michael@0: * fields themselves. michael@0: * michael@0: * Each of the fields is copied from the input string to the destination michael@0: * buffer, and NUL terminated. The position of each field within michael@0: * the destination buffer is returned in the destFields array. michael@0: * michael@0: * If the delimiter pattern includes capture groups, the captured text will michael@0: * also appear in the destination array of output strings, interspersed michael@0: * with the fields. This is similar to Perl, but differs from Java, michael@0: * which ignores the presence of capture groups in the pattern. michael@0: * michael@0: * Trailing empty fields will always be returned, assuming sufficient michael@0: * destination capacity. This differs from the default behavior for Java michael@0: * and Perl where trailing empty fields are not returned. michael@0: * michael@0: * The number of strings produced by the split operation is returned. michael@0: * This count includes the strings from capture groups in the delimiter pattern. michael@0: * This behavior differs from Java, which ignores capture groups. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param destBuf A (UChar *) buffer to receive the fields that michael@0: * are extracted from the input string. These michael@0: * field pointers will refer to positions within the michael@0: * destination buffer supplied by the caller. Any michael@0: * extra positions within the destFields array will be michael@0: * set to NULL. michael@0: * @param destCapacity The capacity of the destBuf. michael@0: * @param requiredCapacity The actual capacity required of the destBuf. michael@0: * If destCapacity is too small, requiredCapacity will return michael@0: * the total capacity required to hold all of the output, and michael@0: * a U_BUFFER_OVERFLOW_ERROR will be returned. michael@0: * @param destFields An array to be filled with the position of each michael@0: * of the extracted fields within destBuf. michael@0: * @param destFieldsCapacity The number of elements in the destFields array. michael@0: * If the number of fields found is less than destFieldsCapacity, michael@0: * the extra destFields elements are set to zero. michael@0: * If destFieldsCapacity is too small, the trailing part of the michael@0: * input, including any field delimiters, is treated as if it michael@0: * were the last field - it is copied to the destBuf, and michael@0: * its position is in the destBuf is stored in the last element michael@0: * of destFields. This behavior mimics that of Perl. It is not michael@0: * an error condition, and no error status is returned when all destField michael@0: * positions are used. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return The number of fields into which the input string was split. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uregex_split( URegularExpression *regexp, michael@0: UChar *destBuf, michael@0: int32_t destCapacity, michael@0: int32_t *requiredCapacity, michael@0: UChar *destFields[], michael@0: int32_t destFieldsCapacity, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Split a string into fields. Somewhat like split() from Perl. michael@0: * The pattern matches identify delimiters that separate the input michael@0: * into fields. The input data between the matches becomes the michael@0: * fields themselves. michael@0: *

michael@0: * The behavior of this function is not very closely aligned with uregex_split(); michael@0: * instead, it is based on (and implemented directly on top of) the C++ split method. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param destFields An array of mutable UText structs to receive the results of the split. michael@0: * If a field is NULL, a new UText is allocated to contain the results for michael@0: * that field. This new UText is not guaranteed to be mutable. michael@0: * @param destFieldsCapacity The number of elements in the destination array. michael@0: * If the number of fields found is less than destCapacity, the michael@0: * extra strings in the destination array are not altered. michael@0: * If the number of destination strings is less than the number michael@0: * of fields, the trailing part of the input string, including any michael@0: * field delimiters, is placed in the last destination string. michael@0: * This behavior mimics that of Perl. It is not an error condition, and no michael@0: * error status is returned when all destField positions are used. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return The number of fields into which the input string was split. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uregex_splitUText(URegularExpression *regexp, michael@0: UText *destFields[], michael@0: int32_t destFieldsCapacity, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Set a processing time limit for match operations with this URegularExpression. michael@0: * michael@0: * Some patterns, when matching certain strings, can run in exponential time. michael@0: * For practical purposes, the match operation may appear to be in an michael@0: * infinite loop. michael@0: * When a limit is set a match operation will fail with an error if the michael@0: * limit is exceeded. michael@0: *

michael@0: * The units of the limit are steps of the match engine. michael@0: * Correspondence with actual processor time will depend on the speed michael@0: * of the processor and the details of the specific pattern, but will michael@0: * typically be on the order of milliseconds. michael@0: *

michael@0: * By default, the matching time is not limited. michael@0: *

michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param limit The limit value, or 0 for no limit. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_setTimeLimit(URegularExpression *regexp, michael@0: int32_t limit, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Get the time limit for for matches with this URegularExpression. michael@0: * A return value of zero indicates that there is no limit. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return the maximum allowed time for a match, in units of processing steps. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uregex_getTimeLimit(const URegularExpression *regexp, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Set the amount of heap storage available for use by the match backtracking stack. michael@0: *

michael@0: * ICU uses a backtracking regular expression engine, with the backtrack stack michael@0: * maintained on the heap. This function sets the limit to the amount of memory michael@0: * that can be used for this purpose. A backtracking stack overflow will michael@0: * result in an error from the match operation that caused it. michael@0: *

michael@0: * A limit is desirable because a malicious or poorly designed pattern can use michael@0: * excessive memory, potentially crashing the process. A limit is enabled michael@0: * by default. michael@0: *

michael@0: * @param regexp The compiled regular expression. michael@0: * @param limit The maximum size, in bytes, of the matching backtrack stack. michael@0: * A value of zero means no limit. michael@0: * The limit must be greater than or equal to zero. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * michael@0: * @stable ICU 4.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_setStackLimit(URegularExpression *regexp, michael@0: int32_t limit, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Get the size of the heap storage available for use by the back tracking stack. michael@0: * michael@0: * @return the maximum backtracking stack size, in bytes, or zero if the michael@0: * stack size is unlimited. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uregex_getStackLimit(const URegularExpression *regexp, michael@0: UErrorCode *status); michael@0: michael@0: michael@0: /** michael@0: * Function pointer for a regular expression matching callback function. michael@0: * When set, a callback function will be called periodically during matching michael@0: * operations. If the call back function returns FALSE, the matching michael@0: * operation will be terminated early. michael@0: * michael@0: * Note: the callback function must not call other functions on this michael@0: * URegularExpression. michael@0: * michael@0: * @param context context pointer. The callback function will be invoked michael@0: * with the context specified at the time that michael@0: * uregex_setMatchCallback() is called. michael@0: * @param steps the accumulated processing time, in match steps, michael@0: * for this matching operation. michael@0: * @return TRUE to continue the matching operation. michael@0: * FALSE to terminate the matching operation. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: U_CDECL_BEGIN michael@0: typedef UBool U_CALLCONV URegexMatchCallback ( michael@0: const void *context, michael@0: int32_t steps); michael@0: U_CDECL_END michael@0: michael@0: /** michael@0: * Set a callback function for this URegularExpression. michael@0: * During matching operations the function will be called periodically, michael@0: * giving the application the opportunity to terminate a long-running michael@0: * match. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param callback A pointer to the user-supplied callback function. michael@0: * @param context User context pointer. The value supplied at the michael@0: * time the callback function is set will be saved michael@0: * and passed to the callback each time that it is called. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_setMatchCallback(URegularExpression *regexp, michael@0: URegexMatchCallback *callback, michael@0: const void *context, michael@0: UErrorCode *status); michael@0: michael@0: michael@0: /** michael@0: * Get the callback function for this URegularExpression. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param callback Out parameter, receives a pointer to the user-supplied michael@0: * callback function. michael@0: * @param context Out parameter, receives the user context pointer that michael@0: * was set when uregex_setMatchCallback() was called. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_getMatchCallback(const URegularExpression *regexp, michael@0: URegexMatchCallback **callback, michael@0: const void **context, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Function pointer for a regular expression find callback function. michael@0: * michael@0: * When set, a callback function will be called during a find operation michael@0: * and for operations that depend on find, such as findNext, split and some replace michael@0: * operations like replaceFirst. michael@0: * The callback will usually be called after each attempt at a match, but this is not a michael@0: * guarantee that the callback will be invoked at each character. For finds where the michael@0: * match engine is invoked at each character, this may be close to true, but less likely michael@0: * for more optimized loops where the pattern is known to only start, and the match michael@0: * engine invoked, at certain characters. michael@0: * When invoked, this callback will specify the index at which a match operation is about michael@0: * to be attempted, giving the application the opportunity to terminate a long-running michael@0: * find operation. michael@0: * michael@0: * If the call back function returns FALSE, the find operation will be terminated early. michael@0: * michael@0: * Note: the callback function must not call other functions on this michael@0: * URegularExpression michael@0: * michael@0: * @param context context pointer. The callback function will be invoked michael@0: * with the context specified at the time that michael@0: * uregex_setFindProgressCallback() is called. michael@0: * @param matchIndex the next index at which a match attempt will be attempted for this michael@0: * find operation. If this callback interrupts the search, this is the michael@0: * index at which a find/findNext operation may be re-initiated. michael@0: * @return TRUE to continue the matching operation. michael@0: * FALSE to terminate the matching operation. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_CDECL_BEGIN michael@0: typedef UBool U_CALLCONV URegexFindProgressCallback ( michael@0: const void *context, michael@0: int64_t matchIndex); michael@0: U_CDECL_END michael@0: michael@0: michael@0: /** michael@0: * Set the find progress callback function for this URegularExpression. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param callback A pointer to the user-supplied callback function. michael@0: * @param context User context pointer. The value supplied at the michael@0: * time the callback function is set will be saved michael@0: * and passed to the callback each time that it is called. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_setFindProgressCallback(URegularExpression *regexp, michael@0: URegexFindProgressCallback *callback, michael@0: const void *context, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Get the find progress callback function for this URegularExpression. michael@0: * michael@0: * @param regexp The compiled regular expression. michael@0: * @param callback Out parameter, receives a pointer to the user-supplied michael@0: * callback function. michael@0: * @param context Out parameter, receives the user context pointer that michael@0: * was set when uregex_setFindProgressCallback() was called. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uregex_getFindProgressCallback(const URegularExpression *regexp, michael@0: URegexFindProgressCallback **callback, michael@0: const void **context, michael@0: UErrorCode *status); michael@0: michael@0: #endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */ michael@0: #endif /* UREGEX_H */