/*
**********************************************************************
-* Copyright (C) 2004-2008, International Business Machines
+* Copyright (C) 2004-2010, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
-* file name: regex.h
+* file name: uregex.h
* encoding: US-ASCII
* indentation:4
*
#ifndef UREGEX_H
#define UREGEX_H
+#include "unicode/utext.h"
#include "unicode/utypes.h"
#if !UCONFIG_NO_REGULAR_EXPRESSIONS
+#include "unicode/localpointer.h"
#include "unicode/parseerr.h"
struct URegularExpression;
/**
- * Structure represeting a compiled regular rexpression, plus the results
+ * Structure representing a compiled regular rexpression, plus the results
* of a match operation.
* @stable ICU 3.0
*/
/** If set, treat the entire pattern as a literal string.
* Metacharacters or escape sequences in the input sequence will be given
- * no special meaning.
+ * no special meaning. Not implemented yet as of ICU 4.4.
*
* The flags CASE_INSENSITIVE and UNICODE_CASE retain their impact
* on matching when used in conjunction with this flag.
* The other flags become superfluous.
* TODO: say which escapes are still handled; anything Java does
- * early (\u) we should still do.
- * @draft ICU 4.0
+ * early (\\u) we should still do.
+ * @stable ICU 4.0
*/
UREGEX_LITERAL = 16,
UREGEX_MULTILINE = 8,
/** Unix-only line endings.
- * When this mode is enabled, only \u000a is recognized as a line ending
+ * When this mode is enabled, only \\u000a is recognized as a line ending
* in the behavior of ., ^, and $.
- * @draft ICU 4.0
+ * @stable ICU 4.0
*/
UREGEX_UNIX_LINES = 1,
* backslash-escaped ASCII letters without a known specail
* meaning. If this flag is not set, these
* escaped letters represent themselves.
- * @draft ICU 4.0
+ * @stable ICU 4.0
*/
UREGEX_ERROR_ON_UNKNOWN_ESCAPES = 512
* string form into an internal representation using the specified match mode flags.
* The resulting regular expression handle can then be used to perform various
* matching operations.
+ *
*
* @param pattern The Regular Expression pattern to be compiled.
* @param patternLength The length of the pattern, or -1 if the pattern is
uint32_t flags,
UParseError *pe,
UErrorCode *status);
-
+
+/**
+ * Open (compile) an ICU regular expression. Compiles the regular expression in
+ * string form into an internal representation using the specified match mode flags.
+ * The resulting regular expression handle can then be used to perform various
+ * matching operations.
+ * <p>
+ * The contents of the pattern UText will be extracted and saved. Ownership of the
+ * UText struct itself remains with the caller. This is to match the behavior of
+ * uregex_open().
+ *
+ * @param pattern The Regular Expression pattern to be compiled.
+ * @param flags Flags that alter the default matching behavior for
+ * the regular expression, UREGEX_CASE_INSENSITIVE, for
+ * example. For default behavior, set this parameter to zero.
+ * See <code>enum URegexpFlag</code>. All desired flags
+ * are bitwise-ORed together.
+ * @param pe Receives the position (line and column nubers) of any syntax
+ * error within the source regular expression string. If this
+ * information is not wanted, pass NULL for this parameter.
+ * @param status Receives error detected by this function.
+ *
+ * @draft ICU 4.6
+ */
+U_DRAFT URegularExpression * U_EXPORT2
+uregex_openUText(UText *pattern,
+ uint32_t flags,
+ UParseError *pe,
+ UErrorCode *status);
+
/**
* Open (compile) an ICU regular expression. The resulting regular expression
* handle can then be used to perform various matching operations.
U_STABLE void U_EXPORT2
uregex_close(URegularExpression *regexp);
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalURegularExpressionPointer
+ * "Smart pointer" class, closes a URegularExpression via uregex_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 4.4
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalURegularExpressionPointer, URegularExpression, uregex_close);
+
+U_NAMESPACE_END
+
+#endif
+
/**
* Make a copy of a compiled regular expression. Cloning a regular
* expression is faster than opening a second instance from the source
uregex_clone(const URegularExpression *regexp, UErrorCode *status);
/**
- * Return a pointer to the source form of the pattern for this regular expression.
+ * Returns a pointer to the source form of the pattern for this regular expression.
+ * This function will work even if the pattern was originally specified as a UText.
*
* @param regexp The compiled regular expression.
* @param patLength This output parameter will be set to the length of the
* @stable ICU 3.0
*/
U_STABLE const UChar * U_EXPORT2
-uregex_pattern(const URegularExpression *regexp,
- int32_t *patLength,
- UErrorCode *status);
+uregex_pattern(const URegularExpression *regexp,
+ int32_t *patLength,
+ UErrorCode *status);
+
+/**
+ * Returns the source text of the pattern for this regular expression.
+ * This function will work even if the pattern was originally specified as a UChar string.
+ *
+ * @param regexp The compiled regular expression.
+ * @param status Receives errors detected by this function.
+ * @return the pattern text. The storage for the text is owned by the regular expression
+ * object, and must not be altered or deleted.
+ *
+ * @draft ICU 4.6
+ */
+U_DRAFT UText * U_EXPORT2
+uregex_patternUText(const URegularExpression *regexp,
+ UErrorCode *status);
/**
int32_t textLength,
UErrorCode *status);
+
+/**
+ * Set the subject text string upon which the regular expression will look for matches.
+ * This function may be called any number of times, allowing the regular
+ * expression pattern to be applied to different strings.
+ * <p>
+ * Regular expression matching operations work directly on the application's
+ * string data; only a shallow clone is made. The subject string data must not be
+ * altered after calling this function until after all regular expression
+ * operations involving this string data are completed.
+ *
+ * @param regexp The compiled regular expression.
+ * @param text The subject text string.
+ * @param status Receives errors detected by this function.
+ *
+ * @draft ICU 4.6
+ */
+U_DRAFT void U_EXPORT2
+uregex_setUText(URegularExpression *regexp,
+ UText *text,
+ UErrorCode *status);
+
/**
* Get the subject text that is currently associated with this
- * regular expression object. This simply returns whatever string
- * pointer was previously supplied via uregex_setText().
+ * regular expression object. If the input was supplied using uregex_setText(),
+ * that pointer will be returned. Otherwise, the characters in the input will
+ * be extracted to a buffer and returned. In either case, ownership remains
+ * with the regular expression object.
+ *
+ * This function will work even if the input was originally specified as a UText.
*
* @param regexp The compiled regular expression.
* @param textLength The length of the string is returned in this output parameter.
* the text is known in advance to be a NUL terminated
* string.
* @param status Receives errors detected by this function.
- * @return Poiner to the subject text string currently associated with
+ * @return Pointer to the subject text string currently associated with
* this regular expression.
* @stable ICU 3.0
*/
uregex_getText(URegularExpression *regexp,
int32_t *textLength,
UErrorCode *status);
+
+
+/**
+ * Get the subject text that is currently associated with this
+ * regular expression object.
+ *
+ * This function will work even if the input was originally specified as a UChar string.
+ *
+ * @param regexp The compiled regular expression.
+ * @param dest A mutable UText in which to store the current input.
+ * If NULL, a new UText will be created as an immutable shallow clone
+ * of the actual input string.
+ * @param status Receives errors detected by this function.
+ * @return The subject text currently associated with this regular expression.
+ * If a pre-allocated UText was provided, it will always be used and returned.
+ *
+ * @draft ICU 4.6
+ */
+U_DRAFT UText * U_EXPORT2
+uregex_getUText(URegularExpression *regexp,
+ UText *dest,
+ UErrorCode *status);
/**
* Attempts to match the input string against the pattern.
* Matcher.matches() in Java
*
* @param regexp The compiled regular expression.
- * @param startIndex The input string index at which to begin matching, or -1
+ * @param startIndex The input string (native) index at which to begin matching, or -1
* to match the input Region.
* @param status Receives errors detected by this function.
* @return TRUE if there is a match
int32_t startIndex,
UErrorCode *status);
+/**
+ * 64bit version of uregex_matches.
+ * @draft ICU 4.6
+ */
+U_DRAFT UBool U_EXPORT2
+uregex_matches64(URegularExpression *regexp,
+ int64_t startIndex,
+ UErrorCode *status);
+
/**
* Attempts to match the input string, starting from the specified index, against the pattern.
* The match may be of any length, and is not required to extend to the end
* and <code>uregexp_group()</code> functions.</p>
*
* @param regexp The compiled regular expression.
- * @param startIndex The input string index at which to begin matching, or
+ * @param startIndex The input string (native) index at which to begin matching, or
* -1 to match the Input Region
* @param status A reference to a UErrorCode to receive any errors.
* @return TRUE if there is a match.
int32_t startIndex,
UErrorCode *status);
+/**
+ * 64bit version of uregex_lookingAt.
+ * @draft ICU 4.6
+ */
+U_DRAFT UBool U_EXPORT2
+uregex_lookingAt64(URegularExpression *regexp,
+ int64_t startIndex,
+ UErrorCode *status);
+
/**
* Find the first matching substring of the input string that matches the pattern.
* If startIndex is >= zero the search for a match begins at the specified index,
* <code>uregex_group()</code> will provide more information regarding the match.
*
* @param regexp The compiled regular expression.
- * @param startIndex The position in the input string to begin the search, or
+ * @param startIndex The position (native) in the input string to begin the search, or
* -1 to search within the Input Region.
* @param status A reference to a UErrorCode to receive any errors.
* @return TRUE if a match is found.
int32_t startIndex,
UErrorCode *status);
+/**
+ * 64bit version of uregex_find.
+ * @draft ICU 4.6
+ */
+U_DRAFT UBool U_EXPORT2
+uregex_find64(URegularExpression *regexp,
+ int64_t startIndex,
+ UErrorCode *status);
+
/**
* Find the next pattern match in the input string. Begin searching
* the input at the location following the end of he previous match,
UErrorCode *status);
+/** Returns a shallow immutable clone of the entire input string. The returned UText current native index
+ * is set to the beginning of the requested capture group. The capture group length is also
+ * returned via groupLength.
+ * Group #0 is the complete string of matched text.
+ * Group #1 is the text matched by the first set of capturing parentheses.
+ *
+ * @param regexp The compiled regular expression.
+ * @param groupNum The capture group to extract. Group 0 is the complete
+ * match. The value of this parameter must be
+ * less than or equal to the number of capture groups in
+ * the pattern.
+ * @param dest A mutable UText in which to store the current input.
+ * If NULL, a new UText will be created as an immutable shallow clone
+ * of the entire input string.
+ * @param groupLength The group length of the desired capture group.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return The subject text currently associated with this regular expression.
+ * If a pre-allocated UText was provided, it will always be used and returned.
+
+ *
+ * @draft ICU 4.6
+ */
+U_DRAFT UText * U_EXPORT2
+uregex_groupUText(URegularExpression *regexp,
+ int32_t groupNum,
+ UText *dest,
+ int64_t *groupLength,
+ UErrorCode *status);
+
+
+/** Extract the string for the specified matching expression or subexpression.
+ * Group #0 is the complete string of matched text.
+ * Group #1 is the text matched by the first set of capturing parentheses.
+ *
+ * @param regexp The compiled regular expression.
+ * @param groupNum The capture group to extract. Group 0 is the complete
+ * match. The value of this parameter must be
+ * less than or equal to the number of capture groups in
+ * the pattern.
+ * @param dest Mutable UText to receive the matching string data.
+ * If NULL, a new UText will be created (which may not be mutable).
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return The matching string data. If a pre-allocated UText was provided,
+ * it will always be used and returned.
+ *
+ * @internal ICU 4.4 technology preview
+ */
+U_INTERNAL UText * U_EXPORT2
+uregex_groupUTextDeep(URegularExpression *regexp,
+ int32_t groupNum,
+ UText *dest,
+ UErrorCode *status);
+
/**
* Returns the index in the input string of the start of the text matched by the
* specified capture group during the previous match operation. Return -1 if
* @param regexp The compiled regular expression.
* @param groupNum The capture group number
* @param status A reference to a UErrorCode to receive any errors.
- * @return the starting position in the input of the text matched
+ * @return the starting (native) position in the input of the text matched
* by the specified group.
* @stable ICU 3.0
*/
int32_t groupNum,
UErrorCode *status);
+/**
+ * 64bit version of uregex_start.
+ * @draft ICU 4.6
+ */
+U_DRAFT int64_t U_EXPORT2
+uregex_start64(URegularExpression *regexp,
+ int32_t groupNum,
+ UErrorCode *status);
+
/**
* Returns the index in the input string of the position following the end
* of the text matched by the specified capture group.
* @param regexp The compiled regular expression.
* @param groupNum The capture group number
* @param status A reference to a UErrorCode to receive any errors.
- * @return the index of the position following the last matched character.
+ * @return the (native) index of the position following the last matched character.
* @stable ICU 3.0
*/
U_STABLE int32_t U_EXPORT2
int32_t groupNum,
UErrorCode *status);
+/**
+ * 64bit version of uregex_end.
+ * @draft ICU 4.6
+ */
+U_DRAFT int64_t U_EXPORT2
+uregex_end64(URegularExpression *regexp,
+ int32_t groupNum,
+ UErrorCode *status);
+
/**
* Reset any saved state from the previous match. Has the effect of
* causing uregex_findNext to begin at the specified index, and causing
* match region that may have been set.
*
* @param regexp The compiled regular expression.
- * @param index The position in the text at which a
+ * @param index The position (native) in the text at which a
* uregex_findNext() should begin searching.
* @param status A reference to a UErrorCode to receive any errors.
* @stable ICU 3.0
int32_t index,
UErrorCode *status);
-
+/**
+ * 64bit version of uregex_reset.
+ * @draft ICU 4.6
+ */
+U_DRAFT void U_EXPORT2
+uregex_reset64(URegularExpression *regexp,
+ int64_t index,
+ UErrorCode *status);
+
/** Sets the limits of the matching region for this URegularExpression.
* The region is the part of the input string that will be considered when matching.
* Invoking this method resets any saved state from the previous match,
* is less than zero or greater than the length of the string being matched.
*
* @param regexp The compiled regular expression.
- * @param regionStart The index to begin searches at.
- * @param regionLimit The index to end searches at (exclusive).
+ * @param regionStart The (native) index to begin searches at.
+ * @param regionLimit The (native) index to end searches at (exclusive).
* @param status A pointer to a UErrorCode to receive any errors.
- * @draft ICU 4.0
+ * @stable ICU 4.0
*/
-U_DRAFT void U_EXPORT2
+U_STABLE void U_EXPORT2
uregex_setRegion(URegularExpression *regexp,
int32_t regionStart,
int32_t regionLimit,
UErrorCode *status);
+/**
+ * 64bit version of uregex_setRegion.
+ * @draft ICU 4.6
+ */
+U_DRAFT void U_EXPORT2
+uregex_setRegion64(URegularExpression *regexp,
+ int64_t regionStart,
+ int64_t regionLimit,
+ UErrorCode *status);
+
+/**
+ * Variation on uregex_setRegion to set the region without resetting the start index
+ * without resetting the position for subsequent matches.
+ * @draft ICU 4.6
+ */
+U_DRAFT void U_EXPORT2
+uregex_setRegionAndStart(URegularExpression *regexp,
+ int64_t regionStart,
+ int64_t regionLimit,
+ int64_t startIndex,
+ UErrorCode *status);
+
/**
* Reports the start index of the matching region. Any matches found are limited to
* to the region bounded by regionStart (inclusive) and regionEnd (exclusive).
*
* @param regexp The compiled regular expression.
* @param status A pointer to a UErrorCode to receive any errors.
- * @return The starting index of this matcher's region.
- * @draft ICU 4.0
+ * @return The starting (native) index of this matcher's region.
+ * @stable ICU 4.0
*/
-U_DRAFT int32_t U_EXPORT2
+U_STABLE int32_t U_EXPORT2
uregex_regionStart(const URegularExpression *regexp,
UErrorCode *status);
-
+/**
+ * 64bit version of uregex_regionStart.
+ * @draft ICU 4.6
+ */
+U_DRAFT int64_t U_EXPORT2
+uregex_regionStart64(const URegularExpression *regexp,
+ UErrorCode *status);
/**
* Reports the end index (exclusive) of the matching region for this URegularExpression.
*
* @param regexp The compiled regular expression.
* @param status A pointer to a UErrorCode to receive any errors.
- * @return The ending point of this matcher's region.
- * @draft ICU 4.0
+ * @return The ending point (native) of this matcher's region.
+ * @stable ICU 4.0
*/
-U_DRAFT int32_t U_EXPORT2
+U_STABLE int32_t U_EXPORT2
uregex_regionEnd(const URegularExpression *regexp,
UErrorCode *status);
+/**
+ * 64bit version of uregex_regionEnd.
+ * @draft ICU 4.6
+ */
+U_DRAFT int64_t U_EXPORT2
+uregex_regionEnd64(const URegularExpression *regexp,
+ UErrorCode *status);
+
/**
* Queries the transparency of region bounds for this URegularExpression.
* See useTransparentBounds for a description of transparent and opaque bounds.
* @param regexp The compiled regular expression.
* @param status A pointer to a UErrorCode to receive any errors.
* @return TRUE if this matcher is using opaque bounds, false if it is not.
- * @draft ICU 4.0
+ * @stable ICU 4.0
*/
-U_DRAFT UBool U_EXPORT2
+U_STABLE UBool U_EXPORT2
uregex_hasTransparentBounds(const URegularExpression *regexp,
UErrorCode *status);
* @param regexp The compiled regular expression.
* @param b TRUE for transparent bounds; FALSE for opaque bounds
* @param status A pointer to a UErrorCode to receive any errors.
- * @draft ICU 4.0
+ * @stable ICU 4.0
**/
-U_DRAFT void U_EXPORT2
+U_STABLE void U_EXPORT2
uregex_useTransparentBounds(URegularExpression *regexp,
UBool b,
UErrorCode *status);
* @param regexp The compiled regular expression.
* @param status A pointer to a UErrorCode to receive any errors.
* @return TRUE if this matcher is using anchoring bounds.
- * @draft ICU 4.0
+ * @stable ICU 4.0
*/
-U_DRAFT UBool U_EXPORT2
+U_STABLE UBool U_EXPORT2
uregex_hasAnchoringBounds(const URegularExpression *regexp,
UErrorCode *status);
* @param regexp The compiled regular expression.
* @param b TRUE if to enable anchoring bounds; FALSE to disable them.
* @param status A pointer to a UErrorCode to receive any errors.
- * @draft ICU 4.0
+ * @stable ICU 4.0
*/
-U_DRAFT void U_EXPORT2
+U_STABLE void U_EXPORT2
uregex_useAnchoringBounds(URegularExpression *regexp,
UBool b,
UErrorCode *status);
* @param regexp The compiled regular expression.
* @param status A pointer to a UErrorCode to receive any errors.
* @return TRUE if the most recent match hit the end of input
- * @draft ICU 4.0
+ * @stable ICU 4.0
*/
-U_DRAFT UBool U_EXPORT2
+U_STABLE UBool U_EXPORT2
uregex_hitEnd(const URegularExpression *regexp,
UErrorCode *status);
* @param regexp The compiled regular expression.
* @param status A pointer to a UErrorCode to receive any errors.
* @return TRUE if more input could cause the most recent match to no longer match.
- * @draft ICU 4.0
+ * @stable ICU 4.0
*/
-U_DRAFT UBool U_EXPORT2
+U_STABLE UBool U_EXPORT2
uregex_requireEnd(const URegularExpression *regexp,
UErrorCode *status);
int32_t destCapacity,
UErrorCode *status);
+/**
+ * Replaces every substring of the input that matches the pattern
+ * with the given replacement string. This is a convenience function that
+ * provides a complete find-and-replace-all operation.
+ *
+ * This method scans the input string looking for matches of the pattern.
+ * Input that is not part of any match is copied unchanged to the
+ * destination buffer. Matched regions are replaced in the output
+ * buffer by the replacement string. The replacement string may contain
+ * references to capture groups; these take the form of $1, $2, etc.
+ *
+ * @param regexp The compiled regular expression.
+ * @param replacement A string containing the replacement text.
+ * @param dest A mutable UText that will receive the result.
+ * If NULL, a new UText will be created (which may not be mutable).
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return A UText containing the results of the find and replace.
+ * If a pre-allocated UText was provided, it will always be used and returned.
+ *
+ * @draft ICU 4.6
+ */
+U_DRAFT UText * U_EXPORT2
+uregex_replaceAllUText(URegularExpression *regexp,
+ UText *replacement,
+ UText *dest,
+ UErrorCode *status);
/**
* Replaces the first substring of the input that matches the pattern
int32_t destCapacity,
UErrorCode *status);
+/**
+ * Replaces the first substring of the input that matches the pattern
+ * with the given replacement string. This is a convenience function that
+ * provides a complete find-and-replace operation.
+ *
+ * This method scans the input string looking for a match of the pattern.
+ * All input that is not part of the match is copied unchanged to the
+ * destination buffer. The matched region is replaced in the output
+ * buffer by the replacement string. The replacement string may contain
+ * references to capture groups; these take the form of $1, $2, etc.
+ *
+ * @param regexp The compiled regular expression.
+ * @param replacement A string containing the replacement text.
+ * @param dest A mutable UText that will receive the result.
+ * If NULL, a new UText will be created (which may not be mutable).
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return A UText containing the results of the find and replace.
+ * If a pre-allocated UText was provided, it will always be used and returned.
+ *
+ * @draft ICU 4.6
+ */
+U_DRAFT UText * U_EXPORT2
+uregex_replaceFirstUText(URegularExpression *regexp,
+ UText *replacement,
+ UText *dest,
+ UErrorCode *status);
+
/**
* Implements a replace operation intended to be used as part of an
*/
U_STABLE int32_t U_EXPORT2
uregex_appendReplacement(URegularExpression *regexp,
- const UChar *replacementText,
- int32_t replacementLength,
- UChar **destBuf,
- int32_t *destCapacity,
- UErrorCode *status);
+ const UChar *replacementText,
+ int32_t replacementLength,
+ UChar **destBuf,
+ int32_t *destCapacity,
+ UErrorCode *status);
+
+
+/**
+ * Implements a replace operation intended to be used as part of an
+ * incremental find-and-replace.
+ *
+ * <p>The input string, starting from the end of the previous match and ending at
+ * the start of the current match, is appended to the destination string. Then the
+ * replacement string is appended to the output string,
+ * including handling any substitutions of captured text.</p>
+ *
+ * <p>For simple, prepackaged, non-incremental find-and-replace
+ * operations, see replaceFirst() or replaceAll().</p>
+ *
+ * @param regexp The regular expression object.
+ * @param replacementText The string that will replace the matched portion of the
+ * input string as it is copied to the destination buffer.
+ * The replacement text may contain references ($1, for
+ * example) to capture groups from the match.
+ * @param dest A mutable UText that will receive the result. Must not be NULL.
+ * @param status A reference to a UErrorCode to receive any errors.
+ *
+ * @draft ICU 4.6
+ */
+U_DRAFT void U_EXPORT2
+uregex_appendReplacementUText(URegularExpression *regexp,
+ UText *replacementText,
+ UText *dest,
+ UErrorCode *status);
/**
UChar **destBuf,
int32_t *destCapacity,
UErrorCode *status);
+
+/**
+ * As the final step in a find-and-replace operation, append the remainder
+ * of the input string, starting at the position following the last match,
+ * to the destination string. <code>uregex_appendTailUText()</code> is intended
+ * to be invoked after one or more invocations of the
+ * <code>uregex_appendReplacementUText()</code> function.
+ *
+ * @param regexp The regular expression object. This is needed to
+ * obtain the input string and with the position
+ * of the last match within it.
+ * @param dest A mutable UText that will receive the result. Must not be NULL.
+ * @return The destination UText.
+ *
+ * @draft ICU 4.6
+ */
+U_DRAFT UText * U_EXPORT2
+uregex_appendTailUText(URegularExpression *regexp,
+ UText *dest,
+ UErrorCode *status);
* fields themselves.
* <p>
* Each of the fields is copied from the input string to the destination
- * buffer, and the NUL terminated. The position of each field within
+ * buffer, and NUL terminated. The position of each field within
* the destination buffer is returned in the destFields array.
*
* Note: another choice for the design of this function would be to not
UErrorCode *status);
+ /**
+ * Split a string into fields. Somewhat like split() from Perl.
+ * The pattern matches identify delimiters that separate the input
+ * into fields. The input data between the matches becomes the
+ * fields themselves.
+ * <p>
+ * The behavior of this function is not very closely aligned with uregex_split();
+ * instead, it is based on (and implemented directly on top of) the C++ split method.
+ *
+ * @param regexp The compiled regular expression.
+ * @param destFields An array of mutable UText structs to receive the results of the split.
+ * If a field is NULL, a new UText is allocated to contain the results for
+ * that field. This new UText is not guaranteed to be mutable.
+ * @param destFieldsCapacity The number of elements in the destination array.
+ * If the number of fields found is less than destCapacity, the
+ * extra strings in the destination array are not altered.
+ * If the number of destination strings is less than the number
+ * of fields, the trailing part of the input string, including any
+ * field delimiters, is placed in the last destination string.
+ * This behavior mimics that of Perl. It is not an error condition, and no
+ * error status is returned when all destField positions are used.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return The number of fields into which the input string was split.
+ *
+ * @draft ICU 4.6
+ */
+U_DRAFT int32_t U_EXPORT2
+uregex_splitUText(URegularExpression *regexp,
+ UText *destFields[],
+ int32_t destFieldsCapacity,
+ UErrorCode *status);
+
+
/**
* @param regexp The compiled regular expression.
* @param limit The limit value, or 0 for no limit.
* @param status A reference to a UErrorCode to receive any errors.
- * @draft ICU 4.0
+ * @stable ICU 4.0
*/
-U_DRAFT void U_EXPORT2
+U_STABLE void U_EXPORT2
uregex_setTimeLimit(URegularExpression *regexp,
int32_t limit,
UErrorCode *status);
* @param regexp The compiled regular expression.
* @param status A reference to a UErrorCode to receive any errors.
* @return the maximum allowed time for a match, in units of processing steps.
- * @draft ICU 4.0
+ * @stable ICU 4.0
*/
-U_DRAFT int32_t U_EXPORT2
+U_STABLE int32_t U_EXPORT2
uregex_getTimeLimit(const URegularExpression *regexp,
UErrorCode *status);
* The limit must be greater than zero, or -1.
* @param status A reference to a UErrorCode to receive any errors.
*
- * @draft ICU 4.0
+ * @stable ICU 4.0
*/
-U_DRAFT void U_EXPORT2
+U_STABLE void U_EXPORT2
uregex_setStackLimit(URegularExpression *regexp,
int32_t limit,
UErrorCode *status);
*
* @return the maximum backtracking stack size, in bytes, or zero if the
* stack size is unlimited.
- * @draft ICU 4.0
+ * @stable ICU 4.0
*/
-U_DRAFT int32_t U_EXPORT2
+U_STABLE int32_t U_EXPORT2
uregex_getStackLimit(const URegularExpression *regexp,
UErrorCode *status);
* for this matching operation.
* @return TRUE to continue the matching operation.
* FALSE to terminate the matching operation.
- * @draft ICU 4.0
+ * @stable ICU 4.0
*/
U_CDECL_BEGIN
typedef UBool U_CALLCONV URegexMatchCallback (
* time the callback function is set will be saved
* and passed to the callback each time that it is called.
* @param status A reference to a UErrorCode to receive any errors.
- * @draft ICU 4.0
+ * @stable ICU 4.0
*/
-U_DRAFT void U_EXPORT2
+U_STABLE void U_EXPORT2
uregex_setMatchCallback(URegularExpression *regexp,
URegexMatchCallback *callback,
const void *context,
* @param context Out parameter, receives the user context pointer that
* was set when uregex_setMatchCallback() was called.
* @param status A reference to a UErrorCode to receive any errors.
- * @draft ICU 4.0
+ * @stable ICU 4.0
*/
-U_DRAFT void U_EXPORT2
+U_STABLE void U_EXPORT2
uregex_getMatchCallback(const URegularExpression *regexp,
URegexMatchCallback **callback,
const void **context,
UErrorCode *status);
+/**
+ * Function pointer for a regular expression find callback function.
+ *
+ * When set, a callback function will be called during a find operation
+ * and for operations that depend on find, such as findNext, split and some replace
+ * operations like replaceFirst.
+ * The callback will usually be called after each attempt at a match, but this is not a
+ * guarantee that the callback will be invoked at each character. For finds where the
+ * match engine is invoked at each character, this may be close to true, but less likely
+ * for more optimized loops where the pattern is known to only start, and the match
+ * engine invoked, at certain characters.
+ * When invoked, this callback will specify the index at which a match operation is about
+ * to be attempted, giving the application the opportunity to terminate a long-running
+ * find operation.
+ *
+ * If the call back function returns FALSE, the find operation will be terminated early.
+ *
+ * Note: the callback function must not call other functions on this
+ * URegularExpression
+ *
+ * @param context context pointer. The callback function will be invoked
+ * with the context specified at the time that
+ * uregex_setFindProgressCallback() is called.
+ * @param matchIndex the next index at which a match attempt will be attempted for this
+ * find operation. If this callback interrupts the search, this is the
+ * index at which a find/findNext operation may be re-initiated.
+ * @return TRUE to continue the matching operation.
+ * FALSE to terminate the matching operation.
+ * @draft ICU 4.6
+ */
+U_CDECL_BEGIN
+typedef UBool U_CALLCONV URegexFindProgressCallback (
+ const void *context,
+ int64_t matchIndex);
+U_CDECL_END
+
+/**
+ * Set the find progress callback function for this URegularExpression.
+ *
+ * @param regexp The compiled regular expression.
+ * @param callback A pointer to the user-supplied callback function.
+ * @param context User context pointer. The value supplied at the
+ * time the callback function is set will be saved
+ * and passed to the callback each time that it is called.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @draft ICU 4.6
+ */
+U_DRAFT void U_EXPORT2
+uregex_setFindProgressCallback(URegularExpression *regexp,
+ URegexFindProgressCallback *callback,
+ const void *context,
+ UErrorCode *status);
+
+
+/**
+ * Get the find progress callback function for this URegularExpression.
+ *
+ * @param regexp The compiled regular expression.
+ * @param callback Out paramater, receives a pointer to the user-supplied
+ * callback function.
+ * @param context Out parameter, receives the user context pointer that
+ * was set when uregex_setFindProgressCallback() was called.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @draft ICU 4.6
+ */
+U_DRAFT void U_EXPORT2
+uregex_getFindProgressCallback(const URegularExpression *regexp,
+ URegexFindProgressCallback **callback,
+ const void **context,
+ UErrorCode *status);
#endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */
#endif /* UREGEX_H */