/*
**********************************************************************
-* Copyright (C) 2004-2006, International Business Machines
+* Copyright (C) 2004-2008, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* file name: regex.h
/** If set, '.' matches line terminators, otherwise '.' matching stops at line end.
* @stable ICU 2.4 */
UREGEX_DOTALL = 32,
+
+ /** If set, treat the entire pattern as a literal string.
+ * Metacharacters or escape sequences in the input sequence will be given
+ * no special meaning.
+ *
+ * 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
+ */
+ UREGEX_LITERAL = 16,
/** Control behavior of "$" and "^"
* If set, recognize line terminators within string,
* otherwise, match only at start and end of input string.
* @stable ICU 2.4 */
UREGEX_MULTILINE = 8,
+
+ /** Unix-only line endings.
+ * When this mode is enabled, only \u000a is recognized as a line ending
+ * in the behavior of ., ^, and $.
+ * @draft ICU 4.0
+ */
+ UREGEX_UNIX_LINES = 1,
/** Unicode word boundaries.
* If set, \b uses the Unicode TR 29 definition of word boundaries.
* http://unicode.org/reports/tr29/#Word_Boundaries
* @stable ICU 2.8
*/
- UREGEX_UWORD = 256
+ UREGEX_UWORD = 256,
+
+ /** Error on Unrecognized backslash escapes.
+ * If set, fail with an error on patterns that contain
+ * backslash-escaped ASCII letters without a known specail
+ * meaning. If this flag is not set, these
+ * escaped letters represent themselves.
+ * @draft ICU 4.0
+ */
+ UREGEX_ERROR_ON_UNKNOWN_ESCAPES = 512
+
} URegexpFlag;
/**
UErrorCode *status);
/**
- * Attempts to match the input string, beginning at startIndex, against the pattern.
- * To succeed, the match must extend to the end of the input string.
+ * Attempts to match the input string against the pattern.
+ * To succeed, the match must extend to the end of the string,
+ * or cover the complete match region.
+ *
+ * If startIndex >= zero the match operation starts at the specified
+ * index and must extend to the end of the input string. Any region
+ * that has been specified is reset.
+ *
+ * If startIndex == -1 the match must cover the input region, or the entire
+ * input string if no region has been set. This directly corresponds to
+ * Matcher.matches() in Java
*
* @param regexp The compiled regular expression.
- * @param startIndex The input string index at which to begin matching.
+ * @param startIndex The input string 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
* @stable ICU 3.0
* The match may be of any length, and is not required to extend to the end
* of the input string. Contrast with uregex_matches().
*
+ * <p>If startIndex is >= 0 any input region that was set for this
+ * URegularExpression is reset before the operation begins.
+ *
+ * <p>If the specified starting index == -1 the match begins at the start of the input
+ * region, or at the start of the full string if no region has been specified.
+ * This corresponds directly with Matcher.lookingAt() in Java.
+ *
* <p>If the match succeeds then more information can be obtained via the
* <code>uregexp_start()</code>, <code>uregexp_end()</code>,
* and <code>uregexp_group()</code> functions.</p>
*
* @param regexp The compiled regular expression.
- * @param startIndex The input string index at which to begin matching.
+ * @param startIndex The input string 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.
* @stable ICU 3.0
/**
* Find the first matching substring of the input string that matches the pattern.
- * The search for a match begins at the specified index.
+ * If startIndex is >= zero the search for a match begins at the specified index,
+ * and any match region is reset. This corresponds directly with
+ * Matcher.find(startIndex) in Java.
+ *
+ * If startIndex == -1 the search begins at the start of the input region,
+ * or at the start of the full string if no region has been specified.
+ *
* If a match is found, <code>uregex_start(), uregex_end()</code>, and
* <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
+ * @param startIndex The position 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.
* @stable ICU 3.0
UErrorCode *status);
/**
- * Find the next pattern match in the input string.
- * Begin searching the input at the location following the end of
- * the previous match, or at the start of the string if there is no previous match.
- * If a match is found, <code>uregex_start(), uregex_end()</code>, and
+ * Find the next pattern match in the input string. Begin searching
+ * the input at the location following the end of he previous match,
+ * or at the start of the string (or region) if there is no
+ * previous match. If a match is found, <code>uregex_start(), uregex_end()</code>, and
* <code>uregex_group()</code> will provide more information regarding the match.
*
* @param regexp The compiled regular expression.
* Reset any saved state from the previous match. Has the effect of
* causing uregex_findNext to begin at the specified index, and causing
* uregex_start(), uregex_end() and uregex_group() to return an error
- * indicating that there is no match information available.
+ * indicating that there is no match information available. Clears any
+ * match region that may have been set.
*
* @param regexp The compiled regular expression.
* @param index The position in the text at which a
uregex_reset(URegularExpression *regexp,
int32_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,
+ * then sets the region to start at the index specified by the start parameter
+ * and end at the index specified by the end parameter.
+ *
+ * Depending on the transparency and anchoring being used (see useTransparentBounds
+ * and useAnchoringBounds), certain constructs such as anchors may behave differently
+ * at or around the boundaries of the region
+ *
+ * The function will fail if start is greater than limit, or if either index
+ * 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 status A pointer to a UErrorCode to receive any errors.
+ * @draft ICU 4.0
+ */
+U_DRAFT void U_EXPORT2
+uregex_setRegion(URegularExpression *regexp,
+ int32_t regionStart,
+ int32_t regionLimit,
+ 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
+ */
+U_DRAFT int32_t U_EXPORT2
+uregex_regionStart(const URegularExpression *regexp,
+ UErrorCode *status);
+
+
+
+/**
+ * Reports the end index (exclusive) of the matching region for this URegularExpression.
+ * 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 ending point of this matcher's region.
+ * @draft ICU 4.0
+ */
+U_DRAFT int32_t U_EXPORT2
+uregex_regionEnd(const URegularExpression *regexp,
+ UErrorCode *status);
+
+/**
+ * Queries the transparency of region bounds for this URegularExpression.
+ * See useTransparentBounds for a description of transparent and opaque bounds.
+ * By default, matching boundaries are opaque.
+ *
+ * @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
+ */
+U_DRAFT UBool U_EXPORT2
+uregex_hasTransparentBounds(const URegularExpression *regexp,
+ UErrorCode *status);
+
+
+/**
+ * Sets the transparency of region bounds for this URegularExpression.
+ * Invoking this function with an argument of TRUE will set matches to use transparent bounds.
+ * If the boolean argument is FALSE, then opaque bounds will be used.
+ *
+ * Using transparent bounds, the boundaries of the matching region are transparent
+ * to lookahead, lookbehind, and boundary matching constructs. Those constructs can
+ * see text beyond the boundaries of the region while checking for a match.
+ *
+ * With opaque bounds, no text outside of the matching region is visible to lookahead,
+ * lookbehind, and boundary matching constructs.
+ *
+ * By default, opaque bounds are used.
+ *
+ * @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
+ **/
+U_DRAFT void U_EXPORT2
+uregex_useTransparentBounds(URegularExpression *regexp,
+ UBool b,
+ UErrorCode *status);
+
+
+/**
+ * Return true if this URegularExpression is using anchoring bounds.
+ * By default, anchoring region bounds are used.
+ *
+ * @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
+ */
+U_DRAFT UBool U_EXPORT2
+uregex_hasAnchoringBounds(const URegularExpression *regexp,
+ UErrorCode *status);
+
+
+/**
+ * Set whether this URegularExpression is using Anchoring Bounds for its region.
+ * With anchoring bounds, pattern anchors such as ^ and $ will match at the start
+ * and end of the region. Without Anchoring Bounds, anchors will only match at
+ * the positions they would in the complete text.
+ *
+ * Anchoring Bounds are the default for regions.
+ *
+ * @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
+ */
+U_DRAFT void U_EXPORT2
+uregex_useAnchoringBounds(URegularExpression *regexp,
+ UBool b,
+ UErrorCode *status);
+
+/**
+ * Return TRUE if the most recent matching operation touched the
+ * end of the text being processed. In this case, additional input text could
+ * change the results of that match.
+ *
+ * @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
+ */
+U_DRAFT UBool U_EXPORT2
+uregex_hitEnd(const URegularExpression *regexp,
+ UErrorCode *status);
+
+/**
+ * Return TRUE the most recent match succeeded and additional input could cause
+ * it to fail. If this function returns false and a match was found, then more input
+ * might change the match but the match won't be lost. If a match was not found,
+ * then requireEnd has no meaning.
+ *
+ * @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
+ */
+U_DRAFT UBool U_EXPORT2
+uregex_requireEnd(const URegularExpression *regexp,
+ UErrorCode *status);
+
+
+
+
/**
* Replaces every substring of the input that matches the pattern
+
+/**
+ * Set a processing time limit for match operations with this URegularExpression.
+ *
+ * Some patterns, when matching certain strings, can run in exponential time.
+ * For practical purposes, the match operation may appear to be in an
+ * infinite loop.
+ * When a limit is set a match operation will fail with an error if the
+ * limit is exceeded.
+ * <p>
+ * The units of the limit are steps of the match engine.
+ * Correspondence with actual processor time will depend on the speed
+ * of the processor and the details of the specific pattern, but will
+ * typically be on the order of milliseconds.
+ * <p>
+ * By default, the matching time is not limited.
+ * <p>
+ *
+ * @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
+ */
+U_DRAFT void U_EXPORT2
+uregex_setTimeLimit(URegularExpression *regexp,
+ int32_t limit,
+ UErrorCode *status);
+
+/**
+ * Get the time limit for for matches with this URegularExpression.
+ * A return value of zero indicates that there is no limit.
+ *
+ * @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
+ */
+U_DRAFT int32_t U_EXPORT2
+uregex_getTimeLimit(const URegularExpression *regexp,
+ UErrorCode *status);
+
+/**
+ * Set the amount of heap storage avaliable for use by the match backtracking stack.
+ * <p>
+ * ICU uses a backtracking regular expression engine, with the backtrack stack
+ * maintained on the heap. This function sets the limit to the amount of memory
+ * that can be used for this purpose. A backtracking stack overflow will
+ * result in an error from the match operation that caused it.
+ * <p>
+ * A limit is desirable because a malicious or poorly designed pattern can use
+ * excessive memory, potentially crashing the process. A limit is enabled
+ * by default.
+ * <p>
+ * @param regexp The compiled regular expression.
+ * @param limit The maximum size, in bytes, of the matching backtrack stack.
+ * A value of -1 means no limit.
+ * The limit must be greater than zero, or -1.
+ * @param status A reference to a UErrorCode to receive any errors.
+ *
+ * @draft ICU 4.0
+ */
+U_DRAFT void U_EXPORT2
+uregex_setStackLimit(URegularExpression *regexp,
+ int32_t limit,
+ UErrorCode *status);
+
+/**
+ * Get the size of the heap storage available for use by the back tracking stack.
+ *
+ * @return the maximum backtracking stack size, in bytes, or zero if the
+ * stack size is unlimited.
+ * @draft ICU 4.0
+ */
+U_DRAFT int32_t U_EXPORT2
+uregex_getStackLimit(const URegularExpression *regexp,
+ UErrorCode *status);
+
+
+/**
+ * Function pointer for a regular expression matching callback function.
+ * When set, a callback function will be called periodically during matching
+ * operations. If the call back function returns FALSE, the matching
+ * 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_setMatchCallback() is called.
+ * @param steps the accumulated processing time, in match steps,
+ * for this matching operation.
+ * @return TRUE to continue the matching operation.
+ * FALSE to terminate the matching operation.
+ * @draft ICU 4.0
+ */
+U_CDECL_BEGIN
+typedef UBool U_CALLCONV URegexMatchCallback (
+ const void *context,
+ int32_t steps);
+U_CDECL_END
+
+/**
+ * Set a callback function for this URegularExpression.
+ * During matching operations the function will be called periodically,
+ * giving the application the opportunity to terminate a long-running
+ * match.
+ *
+ * @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.0
+ */
+U_DRAFT void U_EXPORT2
+uregex_setMatchCallback(URegularExpression *regexp,
+ URegexMatchCallback *callback,
+ const void *context,
+ UErrorCode *status);
+
+
+/**
+ * Get the 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_setMatchCallback() was called.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @draft ICU 4.0
+ */
+U_DRAFT void U_EXPORT2
+uregex_getMatchCallback(const URegularExpression *regexp,
+ URegexMatchCallback **callback,
+ const void **context,
+ UErrorCode *status);
+
+
+
#endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */
#endif /* UREGEX_H */