michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (C) 2002-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: * file name: regex.h michael@0: * encoding: US-ASCII michael@0: * indentation:4 michael@0: * michael@0: * created on: 2002oct22 michael@0: * created by: Andy Heninger michael@0: * michael@0: * ICU Regular Expressions, API for C++ michael@0: */ michael@0: michael@0: #ifndef REGEX_H michael@0: #define REGEX_H michael@0: michael@0: //#define REGEX_DEBUG michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: Regular Expressions michael@0: * michael@0: *

Regular Expression API

michael@0: * michael@0: *

The ICU API for processing regular expressions consists of two classes, michael@0: * RegexPattern and RegexMatcher. michael@0: * RegexPattern objects represent a pre-processed, or compiled michael@0: * regular expression. They are created from a regular expression pattern string, michael@0: * and can be used to create RegexMatcher objects for the pattern.

michael@0: * michael@0: *

Class RegexMatcher bundles together a regular expression michael@0: * pattern and a target string to which the search pattern will be applied. michael@0: * RegexMatcher includes API for doing plain find or search michael@0: * operations, for search and replace operations, and for obtaining detailed michael@0: * information about bounds of a match.

michael@0: * michael@0: *

Note that by constructing RegexMatcher objects directly from regular michael@0: * expression pattern strings application code can be simplified and the explicit michael@0: * need for RegexPattern objects can usually be eliminated. michael@0: *

michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_REGULAR_EXPRESSIONS michael@0: michael@0: #include "unicode/uobject.h" michael@0: #include "unicode/unistr.h" michael@0: #include "unicode/utext.h" michael@0: #include "unicode/parseerr.h" michael@0: michael@0: #include "unicode/uregex.h" michael@0: michael@0: // Forward Declarations michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: struct Regex8BitSet; michael@0: class RegexCImpl; michael@0: class RegexMatcher; michael@0: class RegexPattern; michael@0: struct REStackFrame; michael@0: class RuleBasedBreakIterator; michael@0: class UnicodeSet; michael@0: class UVector; michael@0: class UVector32; michael@0: class UVector64; michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * RBBIPatternDump Debug function, displays the compiled form of a pattern. michael@0: * @internal michael@0: */ michael@0: #ifdef REGEX_DEBUG michael@0: U_INTERNAL void U_EXPORT2 michael@0: RegexPatternDump(const RegexPattern *pat); michael@0: #else michael@0: #undef RegexPatternDump michael@0: #define RegexPatternDump(pat) michael@0: #endif michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: michael@0: michael@0: /** michael@0: * Class RegexPattern represents a compiled regular expression. It includes michael@0: * factory methods for creating a RegexPattern object from the source (string) form michael@0: * of a regular expression, methods for creating RegexMatchers that allow the pattern michael@0: * to be applied to input text, and a few convenience methods for simple common michael@0: * uses of regular expressions. michael@0: * michael@0: *

Class RegexPattern is not intended to be subclassed.

michael@0: * michael@0: * @stable ICU 2.4 michael@0: */ michael@0: class U_I18N_API RegexPattern: public UObject { michael@0: public: michael@0: michael@0: /** michael@0: * default constructor. Create a RegexPattern object that refers to no actual michael@0: * pattern. Not normally needed; RegexPattern objects are usually michael@0: * created using the factory method compile(). michael@0: * michael@0: * @stable ICU 2.4 michael@0: */ michael@0: RegexPattern(); michael@0: michael@0: /** michael@0: * Copy Constructor. Create a new RegexPattern object that is equivalent michael@0: * to the source object. michael@0: * @param source the pattern object to be copied. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: RegexPattern(const RegexPattern &source); michael@0: michael@0: /** michael@0: * Destructor. Note that a RegexPattern object must persist so long as any michael@0: * RegexMatcher objects that were created from the RegexPattern are active. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual ~RegexPattern(); michael@0: michael@0: /** michael@0: * Comparison operator. Two RegexPattern objects are considered equal if they michael@0: * were constructed from identical source patterns using the same match flag michael@0: * settings. michael@0: * @param that a RegexPattern object to compare with "this". michael@0: * @return TRUE if the objects are equivalent. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UBool operator==(const RegexPattern& that) const; michael@0: michael@0: /** michael@0: * Comparison operator. Two RegexPattern objects are considered equal if they michael@0: * were constructed from identical source patterns using the same match flag michael@0: * settings. michael@0: * @param that a RegexPattern object to compare with "this". michael@0: * @return TRUE if the objects are different. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: inline UBool operator!=(const RegexPattern& that) const {return ! operator ==(that);} michael@0: michael@0: /** michael@0: * Assignment operator. After assignment, this RegexPattern will behave identically michael@0: * to the source object. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: RegexPattern &operator =(const RegexPattern &source); michael@0: michael@0: /** michael@0: * Create an exact copy of this RegexPattern object. Since RegexPattern is not michael@0: * intended to be subclasses, clone() and the copy construction are michael@0: * equivalent operations. michael@0: * @return the copy of this RegexPattern michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual RegexPattern *clone() const; michael@0: michael@0: michael@0: /** michael@0: * Compiles the regular expression in string form into a RegexPattern michael@0: * object. These compile methods, rather than the constructors, are the usual michael@0: * way that RegexPattern objects are created. michael@0: * michael@0: *

Note that RegexPattern objects must not be deleted while RegexMatcher michael@0: * objects created from the pattern are active. RegexMatchers keep a pointer michael@0: * back to their pattern, so premature deletion of the pattern is a michael@0: * catastrophic error.

michael@0: * michael@0: *

All pattern match mode flags are set to their default values.

michael@0: * michael@0: *

Note that it is often more convenient to construct a RegexMatcher directly michael@0: * from a pattern string rather than separately compiling the pattern and michael@0: * then creating a RegexMatcher object from the pattern.

michael@0: * michael@0: * @param regex The regular expression to be compiled. michael@0: * @param pe Receives the position (line and column nubers) of any error michael@0: * within the regular expression.) michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return A regexPattern object for the compiled pattern. michael@0: * michael@0: * @stable ICU 2.4 michael@0: */ michael@0: static RegexPattern * U_EXPORT2 compile( const UnicodeString ®ex, michael@0: UParseError &pe, michael@0: UErrorCode &status); michael@0: michael@0: /** michael@0: * Compiles the regular expression in string form into a RegexPattern michael@0: * object. These compile methods, rather than the constructors, are the usual michael@0: * way that RegexPattern objects are created. michael@0: * michael@0: *

Note that RegexPattern objects must not be deleted while RegexMatcher michael@0: * objects created from the pattern are active. RegexMatchers keep a pointer michael@0: * back to their pattern, so premature deletion of the pattern is a michael@0: * catastrophic error.

michael@0: * michael@0: *

All pattern match mode flags are set to their default values.

michael@0: * michael@0: *

Note that it is often more convenient to construct a RegexMatcher directly michael@0: * from a pattern string rather than separately compiling the pattern and michael@0: * then creating a RegexMatcher object from the pattern.

michael@0: * michael@0: * @param regex The regular expression to be compiled. Note, the text referred michael@0: * to by this UText must not be deleted during the lifetime of the michael@0: * RegexPattern object or any RegexMatcher object created from it. michael@0: * @param pe Receives the position (line and column nubers) of any error michael@0: * within the regular expression.) michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return A regexPattern object for the compiled pattern. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: static RegexPattern * U_EXPORT2 compile( UText *regex, michael@0: UParseError &pe, michael@0: UErrorCode &status); michael@0: michael@0: /** michael@0: * Compiles the regular expression in string form into a RegexPattern michael@0: * object using the specified match mode flags. These compile methods, michael@0: * rather than the constructors, are the usual way that RegexPattern objects michael@0: * are created. michael@0: * michael@0: *

Note that RegexPattern objects must not be deleted while RegexMatcher michael@0: * objects created from the pattern are active. RegexMatchers keep a pointer michael@0: * back to their pattern, so premature deletion of the pattern is a michael@0: * catastrophic error.

michael@0: * michael@0: *

Note that it is often more convenient to construct a RegexMatcher directly michael@0: * from a pattern string instead of than separately compiling the pattern and michael@0: * then creating a RegexMatcher object from the pattern.

michael@0: * michael@0: * @param regex The regular expression to be compiled. michael@0: * @param flags The match mode flags to be used. michael@0: * @param pe Receives the position (line and column numbers) of any error michael@0: * within the regular expression.) michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return A regexPattern object for the compiled pattern. michael@0: * michael@0: * @stable ICU 2.4 michael@0: */ michael@0: static RegexPattern * U_EXPORT2 compile( const UnicodeString ®ex, michael@0: uint32_t flags, michael@0: UParseError &pe, michael@0: UErrorCode &status); michael@0: michael@0: /** michael@0: * Compiles the regular expression in string form into a RegexPattern michael@0: * object using the specified match mode flags. These compile methods, michael@0: * rather than the constructors, are the usual way that RegexPattern objects michael@0: * are created. michael@0: * michael@0: *

Note that RegexPattern objects must not be deleted while RegexMatcher michael@0: * objects created from the pattern are active. RegexMatchers keep a pointer michael@0: * back to their pattern, so premature deletion of the pattern is a michael@0: * catastrophic error.

michael@0: * michael@0: *

Note that it is often more convenient to construct a RegexMatcher directly michael@0: * from a pattern string instead of than separately compiling the pattern and michael@0: * then creating a RegexMatcher object from the pattern.

michael@0: * michael@0: * @param regex The regular expression to be compiled. Note, the text referred michael@0: * to by this UText must not be deleted during the lifetime of the michael@0: * RegexPattern object or any RegexMatcher object created from it. michael@0: * @param flags The match mode flags to be used. michael@0: * @param pe Receives the position (line and column numbers) of any error michael@0: * within the regular expression.) michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return A regexPattern object for the compiled pattern. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: static RegexPattern * U_EXPORT2 compile( UText *regex, michael@0: uint32_t flags, michael@0: UParseError &pe, michael@0: UErrorCode &status); michael@0: michael@0: /** michael@0: * Compiles the regular expression in string form into a RegexPattern michael@0: * object using the specified match mode flags. These compile methods, michael@0: * rather than the constructors, are the usual way that RegexPattern objects michael@0: * are created. michael@0: * michael@0: *

Note that RegexPattern objects must not be deleted while RegexMatcher michael@0: * objects created from the pattern are active. RegexMatchers keep a pointer michael@0: * back to their pattern, so premature deletion of the pattern is a michael@0: * catastrophic error.

michael@0: * michael@0: *

Note that it is often more convenient to construct a RegexMatcher directly michael@0: * from a pattern string instead of than separately compiling the pattern and michael@0: * then creating a RegexMatcher object from the pattern.

michael@0: * michael@0: * @param regex The regular expression to be compiled. michael@0: * @param flags The match mode flags to be used. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return A regexPattern object for the compiled pattern. michael@0: * michael@0: * @stable ICU 2.6 michael@0: */ michael@0: static RegexPattern * U_EXPORT2 compile( const UnicodeString ®ex, michael@0: uint32_t flags, michael@0: UErrorCode &status); michael@0: michael@0: /** michael@0: * Compiles the regular expression in string form into a RegexPattern michael@0: * object using the specified match mode flags. These compile methods, michael@0: * rather than the constructors, are the usual way that RegexPattern objects michael@0: * are created. michael@0: * michael@0: *

Note that RegexPattern objects must not be deleted while RegexMatcher michael@0: * objects created from the pattern are active. RegexMatchers keep a pointer michael@0: * back to their pattern, so premature deletion of the pattern is a michael@0: * catastrophic error.

michael@0: * michael@0: *

Note that it is often more convenient to construct a RegexMatcher directly michael@0: * from a pattern string instead of than separately compiling the pattern and michael@0: * then creating a RegexMatcher object from the pattern.

michael@0: * michael@0: * @param regex The regular expression to be compiled. Note, the text referred michael@0: * to by this UText must not be deleted during the lifetime of the michael@0: * RegexPattern object or any RegexMatcher object created from it. michael@0: * @param flags The match mode flags to be used. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return A regexPattern object for the compiled pattern. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: static RegexPattern * U_EXPORT2 compile( UText *regex, michael@0: uint32_t flags, michael@0: UErrorCode &status); michael@0: michael@0: /** michael@0: * Get the match mode flags that were used when compiling this pattern. michael@0: * @return the match mode flags michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual uint32_t flags() const; michael@0: michael@0: /** michael@0: * Creates a RegexMatcher that will match the given input against this pattern. The michael@0: * RegexMatcher can then be used to perform match, find or replace operations michael@0: * on the input. Note that a RegexPattern object must not be deleted while michael@0: * RegexMatchers created from it still exist and might possibly be used again. michael@0: *

michael@0: * The matcher will retain a reference to the supplied input string, and all regexp michael@0: * pattern matching operations happen directly on this original string. It is michael@0: * critical that the string not be altered or deleted before use by the regular michael@0: * expression operations is complete. michael@0: * michael@0: * @param input The input string to which the regular expression will be applied. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return A RegexMatcher object for this pattern and input. michael@0: * michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual RegexMatcher *matcher(const UnicodeString &input, michael@0: UErrorCode &status) const; michael@0: michael@0: private: michael@0: /** michael@0: * Cause a compilation error if an application accidentally attempts to michael@0: * create a matcher with a (UChar *) string as input rather than michael@0: * a UnicodeString. Avoids a dangling reference to a temporary string. michael@0: *

michael@0: * To efficiently work with UChar *strings, wrap the data in a UnicodeString michael@0: * using one of the aliasing constructors, such as michael@0: * UnicodeString(UBool isTerminated, const UChar *text, int32_t textLength); michael@0: * or in a UText, using michael@0: * utext_openUChars(UText *ut, const UChar *text, int64_t textLength, UErrorCode *status); michael@0: * michael@0: */ michael@0: RegexMatcher *matcher(const UChar *input, michael@0: UErrorCode &status) const; michael@0: public: michael@0: michael@0: michael@0: /** michael@0: * Creates a RegexMatcher that will match against this pattern. The michael@0: * RegexMatcher can be used to perform match, find or replace operations. michael@0: * Note that a RegexPattern object must not be deleted while michael@0: * RegexMatchers created from it still exist and might possibly be used again. michael@0: * michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return A RegexMatcher object for this pattern and input. michael@0: * michael@0: * @stable ICU 2.6 michael@0: */ michael@0: virtual RegexMatcher *matcher(UErrorCode &status) const; michael@0: michael@0: michael@0: /** michael@0: * Test whether a string matches a regular expression. This convenience function michael@0: * both compiles the regular expression and applies it in a single operation. michael@0: * Note that if the same pattern needs to be applied repeatedly, this method will be michael@0: * less efficient than creating and reusing a RegexMatcher object. michael@0: * michael@0: * @param regex The regular expression michael@0: * @param input The string data to be matched michael@0: * @param pe Receives the position of any syntax errors within the regular expression michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return True if the regular expression exactly matches the full input string. michael@0: * michael@0: * @stable ICU 2.4 michael@0: */ michael@0: static UBool U_EXPORT2 matches(const UnicodeString ®ex, michael@0: const UnicodeString &input, michael@0: UParseError &pe, michael@0: UErrorCode &status); michael@0: michael@0: /** michael@0: * Test whether a string matches a regular expression. This convenience function michael@0: * both compiles the regular expression and applies it in a single operation. michael@0: * Note that if the same pattern needs to be applied repeatedly, this method will be michael@0: * less efficient than creating and reusing a RegexMatcher object. michael@0: * michael@0: * @param regex The regular expression michael@0: * @param input The string data to be matched michael@0: * @param pe Receives the position of any syntax errors within the regular expression michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return True if the regular expression exactly matches the full input string. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: static UBool U_EXPORT2 matches(UText *regex, michael@0: UText *input, michael@0: UParseError &pe, michael@0: UErrorCode &status); michael@0: michael@0: /** michael@0: * Returns the regular expression from which this pattern was compiled. This method will work michael@0: * even if the pattern was compiled from a UText. michael@0: * michael@0: * Note: If the pattern was originally compiled from a UText, and that UText was modified, michael@0: * the returned string may no longer reflect the RegexPattern object. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UnicodeString pattern() const; michael@0: michael@0: michael@0: /** michael@0: * Returns the regular expression from which this pattern was compiled. This method will work michael@0: * even if the pattern was compiled from a UnicodeString. michael@0: * michael@0: * Note: This is the original input, not a clone. If the pattern was originally compiled from a michael@0: * UText, and that UText was modified, the returned UText may no longer reflect the RegexPattern michael@0: * object. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: virtual UText *patternText(UErrorCode &status) const; michael@0: michael@0: michael@0: /** michael@0: * Split a string into fields. Somewhat like split() from Perl or Java. michael@0: * Pattern matches identify delimiters that separate the input michael@0: * into fields. The input data between the delimiters becomes the michael@0: * fields themselves. 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: * For the best performance on split() operations, michael@0: * RegexMatcher::split is preferable to this function michael@0: * michael@0: * @param input The string to be split into fields. The field delimiters michael@0: * match the pattern (in the "this" object) michael@0: * @param dest An array of UnicodeStrings to receive the results of the split. michael@0: * This is an array of actual UnicodeString objects, not an michael@0: * array of pointers to strings. Local (stack based) arrays can michael@0: * work well here. michael@0: * @param destCapacity 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: * @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 2.4 michael@0: */ michael@0: virtual int32_t split(const UnicodeString &input, michael@0: UnicodeString dest[], michael@0: int32_t destCapacity, michael@0: UErrorCode &status) const; michael@0: michael@0: michael@0: /** michael@0: * Split a string into fields. Somewhat like split() from Perl or Java. michael@0: * Pattern matches identify delimiters that separate the input michael@0: * into fields. The input data between the delimiters becomes the michael@0: * fields themselves. 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: * For the best performance on split() operations, michael@0: * RegexMatcher::split is preferable to this function michael@0: * michael@0: * @param input The string to be split into fields. The field delimiters michael@0: * match the pattern (in the "this" object) michael@0: * @param dest 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 destCapacity 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: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return The number of destination strings used. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: virtual int32_t split(UText *input, michael@0: UText *dest[], michael@0: int32_t destCapacity, michael@0: UErrorCode &status) const; michael@0: michael@0: michael@0: /** michael@0: * ICU "poor man's RTTI", returns a UClassID for the actual class. michael@0: * michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UClassID getDynamicClassID() const; michael@0: michael@0: /** michael@0: * ICU "poor man's RTTI", returns a UClassID for this class. michael@0: * michael@0: * @stable ICU 2.4 michael@0: */ michael@0: static UClassID U_EXPORT2 getStaticClassID(); michael@0: michael@0: private: michael@0: // michael@0: // Implementation Data michael@0: // michael@0: UText *fPattern; // The original pattern string. michael@0: UnicodeString *fPatternString; // The original pattern UncodeString if relevant michael@0: uint32_t fFlags; // The flags used when compiling the pattern. michael@0: // michael@0: UVector64 *fCompiledPat; // The compiled pattern p-code. michael@0: UnicodeString fLiteralText; // Any literal string data from the pattern, michael@0: // after un-escaping, for use during the match. michael@0: michael@0: UVector *fSets; // Any UnicodeSets referenced from the pattern. michael@0: Regex8BitSet *fSets8; // (and fast sets for latin-1 range.) michael@0: michael@0: michael@0: UErrorCode fDeferredStatus; // status if some prior error has left this michael@0: // RegexPattern in an unusable state. michael@0: michael@0: int32_t fMinMatchLen; // Minimum Match Length. All matches will have length michael@0: // >= this value. For some patterns, this calculated michael@0: // value may be less than the true shortest michael@0: // possible match. michael@0: michael@0: int32_t fFrameSize; // Size of a state stack frame in the michael@0: // execution engine. michael@0: michael@0: int32_t fDataSize; // The size of the data needed by the pattern that michael@0: // does not go on the state stack, but has just michael@0: // a single copy per matcher. michael@0: michael@0: UVector32 *fGroupMap; // Map from capture group number to position of michael@0: // the group's variables in the matcher stack frame. michael@0: michael@0: int32_t fMaxCaptureDigits; michael@0: michael@0: UnicodeSet **fStaticSets; // Ptr to static (shared) sets for predefined michael@0: // regex character classes, e.g. Word. michael@0: michael@0: Regex8BitSet *fStaticSets8; // Ptr to the static (shared) latin-1 only michael@0: // sets for predefined regex classes. michael@0: michael@0: int32_t fStartType; // Info on how a match must start. michael@0: int32_t fInitialStringIdx; // michael@0: int32_t fInitialStringLen; michael@0: UnicodeSet *fInitialChars; michael@0: UChar32 fInitialChar; michael@0: Regex8BitSet *fInitialChars8; michael@0: UBool fNeedsAltInput; michael@0: michael@0: friend class RegexCompile; michael@0: friend class RegexMatcher; michael@0: friend class RegexCImpl; michael@0: michael@0: // michael@0: // Implementation Methods michael@0: // michael@0: void init(); // Common initialization, for use by constructors. michael@0: void zap(); // Common cleanup michael@0: #ifdef REGEX_DEBUG michael@0: void dumpOp(int32_t index) const; michael@0: friend void U_EXPORT2 RegexPatternDump(const RegexPattern *); michael@0: #endif michael@0: michael@0: }; michael@0: michael@0: michael@0: michael@0: /** michael@0: * class RegexMatcher bundles together a regular expression pattern and michael@0: * input text to which the expression can be applied. It includes methods michael@0: * for testing for matches, and for find and replace operations. michael@0: * michael@0: *

Class RegexMatcher is not intended to be subclassed.

michael@0: * michael@0: * @stable ICU 2.4 michael@0: */ michael@0: class U_I18N_API RegexMatcher: public UObject { michael@0: public: michael@0: michael@0: /** michael@0: * Construct a RegexMatcher for a regular expression. michael@0: * This is a convenience method that avoids the need to explicitly create michael@0: * a RegexPattern object. Note that if several RegexMatchers need to be michael@0: * created for the same expression, it will be more efficient to michael@0: * separately create and cache a RegexPattern object, and use michael@0: * its matcher() method to create the RegexMatcher objects. michael@0: * michael@0: * @param regexp The Regular Expression to be compiled. michael@0: * @param flags Regular expression options, such as case insensitive matching. michael@0: * @see UREGEX_CASE_INSENSITIVE michael@0: * @param status Any errors are reported by setting this UErrorCode variable. michael@0: * @stable ICU 2.6 michael@0: */ michael@0: RegexMatcher(const UnicodeString ®exp, uint32_t flags, UErrorCode &status); michael@0: michael@0: /** michael@0: * Construct a RegexMatcher for a regular expression. michael@0: * This is a convenience method that avoids the need to explicitly create michael@0: * a RegexPattern object. Note that if several RegexMatchers need to be michael@0: * created for the same expression, it will be more efficient to michael@0: * separately create and cache a RegexPattern object, and use michael@0: * its matcher() method to create the RegexMatcher objects. michael@0: * michael@0: * @param regexp The regular expression to be compiled. michael@0: * @param flags Regular expression options, such as case insensitive matching. michael@0: * @see UREGEX_CASE_INSENSITIVE michael@0: * @param status Any errors are reported by setting this UErrorCode variable. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: RegexMatcher(UText *regexp, uint32_t flags, UErrorCode &status); michael@0: michael@0: /** michael@0: * Construct a RegexMatcher for a regular expression. michael@0: * This is a convenience method that avoids the need to explicitly create michael@0: * a RegexPattern object. Note that if several RegexMatchers need to be michael@0: * created for the same expression, it will be more efficient to michael@0: * separately create and cache a RegexPattern object, and use michael@0: * its matcher() method to create the RegexMatcher objects. michael@0: *

michael@0: * The matcher will retain a reference to the supplied input string, and all regexp michael@0: * pattern matching operations happen directly on the original string. It is michael@0: * critical that the string not be altered or deleted before use by the regular michael@0: * expression operations is complete. michael@0: * michael@0: * @param regexp The Regular Expression to be compiled. michael@0: * @param input The string to match. The matcher retains a reference to the michael@0: * caller's string; mo copy is made. michael@0: * @param flags Regular expression options, such as case insensitive matching. michael@0: * @see UREGEX_CASE_INSENSITIVE michael@0: * @param status Any errors are reported by setting this UErrorCode variable. michael@0: * @stable ICU 2.6 michael@0: */ michael@0: RegexMatcher(const UnicodeString ®exp, const UnicodeString &input, michael@0: uint32_t flags, UErrorCode &status); michael@0: michael@0: /** michael@0: * Construct a RegexMatcher for a regular expression. michael@0: * This is a convenience method that avoids the need to explicitly create michael@0: * a RegexPattern object. Note that if several RegexMatchers need to be michael@0: * created for the same expression, it will be more efficient to michael@0: * separately create and cache a RegexPattern object, and use michael@0: * its matcher() method to create the RegexMatcher objects. michael@0: *

michael@0: * The matcher will make a shallow clone of the supplied input text, and all regexp michael@0: * pattern matching operations happen on this clone. While read-only operations on michael@0: * the supplied text are permitted, it is critical that the underlying string not be michael@0: * altered or deleted before use by the regular expression operations is complete. michael@0: * michael@0: * @param regexp The Regular Expression to be compiled. michael@0: * @param input The string to match. The matcher retains a shallow clone of the text. michael@0: * @param flags Regular expression options, such as case insensitive matching. michael@0: * @see UREGEX_CASE_INSENSITIVE michael@0: * @param status Any errors are reported by setting this UErrorCode variable. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: RegexMatcher(UText *regexp, UText *input, michael@0: uint32_t flags, UErrorCode &status); michael@0: michael@0: private: michael@0: /** michael@0: * Cause a compilation error if an application accidentally attempts to michael@0: * create a matcher with a (UChar *) string as input rather than michael@0: * a UnicodeString. Avoids a dangling reference to a temporary string. michael@0: *

michael@0: * To efficiently work with UChar *strings, wrap the data in a UnicodeString michael@0: * using one of the aliasing constructors, such as michael@0: * UnicodeString(UBool isTerminated, const UChar *text, int32_t textLength); michael@0: * or in a UText, using michael@0: * utext_openUChars(UText *ut, const UChar *text, int64_t textLength, UErrorCode *status); michael@0: * michael@0: */ michael@0: RegexMatcher(const UnicodeString ®exp, const UChar *input, michael@0: uint32_t flags, UErrorCode &status); michael@0: public: michael@0: michael@0: michael@0: /** michael@0: * Destructor. michael@0: * michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual ~RegexMatcher(); michael@0: michael@0: michael@0: /** michael@0: * Attempts to match the entire input region against the pattern. 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 2.4 michael@0: */ michael@0: virtual UBool matches(UErrorCode &status); michael@0: michael@0: michael@0: /** michael@0: * Resets the matcher, then attempts to match the input beginning michael@0: * at the specified startIndex, and extending to the end of the input. michael@0: * The input region is reset to include the entire input string. michael@0: * A successful match must extend to the end of the input. michael@0: * @param startIndex The input string (native) index at which to begin matching. 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 2.8 michael@0: */ michael@0: virtual UBool matches(int64_t startIndex, UErrorCode &status); michael@0: michael@0: michael@0: /** michael@0: * Attempts to match the input string, starting from the beginning of the region, michael@0: * against the pattern. Like the matches() method, this function michael@0: * always starts at the beginning of the input region; michael@0: * unlike that function, it does not require that the entire region be matched. michael@0: * michael@0: *

If the match succeeds then more information can be obtained via the start(), michael@0: * end(), and group() functions.

michael@0: * michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @return TRUE if there is a match at the start of the input string. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UBool lookingAt(UErrorCode &status); michael@0: 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 match(). michael@0: * michael@0: *

If the match succeeds then more information can be obtained via the start(), michael@0: * end(), and group() functions.

michael@0: * michael@0: * @param startIndex The input string (native) index at which to begin matching. 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 2.8 michael@0: */ michael@0: virtual UBool lookingAt(int64_t startIndex, UErrorCode &status); michael@0: michael@0: michael@0: /** michael@0: * Find the next pattern match in the input string. michael@0: * The find begins searching the input at the location following the end of michael@0: * the previous match, or at the start of the string if there is no previous match. michael@0: * If a match is found, start(), end() and group() michael@0: * will provide more information regarding the match. michael@0: *

Note that if the input string is changed by the application, michael@0: * use find(startPos, status) instead of find(), because the saved starting michael@0: * position may not be valid with the altered input string.

michael@0: * @return TRUE if a match is found. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UBool find(); michael@0: michael@0: michael@0: /** michael@0: * Resets this RegexMatcher and then attempts to find the next substring of the michael@0: * input string that matches the pattern, starting at the specified index. michael@0: * michael@0: * @param start The (native) index in the input string to begin the search. 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 2.4 michael@0: */ michael@0: virtual UBool find(int64_t start, UErrorCode &status); michael@0: michael@0: michael@0: /** michael@0: * Returns a string containing the text matched by the previous match. michael@0: * If the pattern can match an empty string, an empty string may be returned. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * Possible errors are U_REGEX_INVALID_STATE if no match michael@0: * has been attempted or the last match failed. michael@0: * @return a string containing the matched input text. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UnicodeString group(UErrorCode &status) const; michael@0: michael@0: michael@0: /** michael@0: * Returns a string containing the text captured by the given group michael@0: * during the previous match operation. Group(0) is the entire match. michael@0: * michael@0: * @param groupNum the capture group number michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * Possible errors are U_REGEX_INVALID_STATE if no match michael@0: * has been attempted or the last match failed and michael@0: * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number. michael@0: * @return the captured text michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UnicodeString group(int32_t groupNum, UErrorCode &status) const; michael@0: michael@0: michael@0: /** michael@0: * Returns the number of capturing groups in this matcher's pattern. michael@0: * @return the number of capture groups michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual int32_t groupCount() const; michael@0: michael@0: michael@0: /** michael@0: * Returns a shallow clone of the entire live input string with the UText current native index michael@0: * set to the beginning of the requested group. michael@0: * michael@0: * @param dest The UText into which the input should be cloned, or NULL to create a new UText michael@0: * @param group_len A reference to receive the length of the desired capture group michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * Possible errors are U_REGEX_INVALID_STATE if no match michael@0: * has been attempted or the last match failed and michael@0: * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number. michael@0: * @return dest if non-NULL, a shallow copy of the input text otherwise michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: virtual UText *group(UText *dest, int64_t &group_len, UErrorCode &status) const; michael@0: michael@0: /** michael@0: * Returns a shallow clone of the entire live input string with the UText current native index michael@0: * set to the beginning of the requested group. michael@0: * michael@0: * @param groupNum The capture group number. michael@0: * @param dest The UText into which the input should be cloned, or NULL to create a new UText. michael@0: * @param group_len A reference to receive the length of the desired capture group michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * Possible errors are U_REGEX_INVALID_STATE if no match michael@0: * has been attempted or the last match failed and michael@0: * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number. michael@0: * @return dest if non-NULL, a shallow copy of the input text otherwise michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: virtual UText *group(int32_t groupNum, UText *dest, int64_t &group_len, UErrorCode &status) const; michael@0: michael@0: /** michael@0: * Returns a string containing the text captured by the given group michael@0: * during the previous match operation. Group(0) is the entire match. michael@0: * michael@0: * @param groupNum the capture group number michael@0: * @param dest A mutable UText in which the matching text is placed. 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: * Possible errors are U_REGEX_INVALID_STATE if no match michael@0: * has been attempted or the last match failed. michael@0: * @return A string containing the matched input text. If a pre-allocated UText michael@0: * was provided, it will always be used and returned. michael@0: * michael@0: * @internal ICU 4.4 technology preview michael@0: */ michael@0: virtual UText *group(int32_t groupNum, UText *dest, UErrorCode &status) const; michael@0: michael@0: michael@0: /** michael@0: * Returns the index in the input string of the start of the text matched michael@0: * during the previous match operation. michael@0: * @param status a reference to a UErrorCode to receive any errors. michael@0: * @return The (native) position in the input string of the start of the last match. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual int32_t start(UErrorCode &status) const; michael@0: michael@0: /** michael@0: * Returns the index in the input string of the start of the text matched michael@0: * during the previous match operation. michael@0: * @param status a reference to a UErrorCode to receive any errors. michael@0: * @return The (native) position in the input string of the start of the last match. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: virtual int64_t start64(UErrorCode &status) const; michael@0: 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 exists in the pattern, but was not part of the last match. michael@0: * michael@0: * @param group the capture group number michael@0: * @param status A reference to a UErrorCode to receive any errors. Possible michael@0: * errors are U_REGEX_INVALID_STATE if no match has been michael@0: * attempted or the last match failed, and michael@0: * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number michael@0: * @return the (native) start position of substring matched by the specified group. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual int32_t start(int32_t group, UErrorCode &status) const; 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 exists in the pattern, but was not part of the last match. michael@0: * michael@0: * @param group the capture group number. michael@0: * @param status A reference to a UErrorCode to receive any errors. Possible michael@0: * errors are U_REGEX_INVALID_STATE if no match has been michael@0: * attempted or the last match failed, and michael@0: * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number. michael@0: * @return the (native) start position of substring matched by the specified group. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: virtual int64_t start64(int32_t group, UErrorCode &status) const; michael@0: michael@0: michael@0: /** michael@0: * Returns the index in the input string of the first character following the michael@0: * text matched during the previous match operation. michael@0: * michael@0: * @param status A reference to a UErrorCode to receive any errors. Possible michael@0: * errors are U_REGEX_INVALID_STATE if no match has been michael@0: * attempted or the last match failed. michael@0: * @return the index of the last character matched, plus one. michael@0: * The index value returned is a native index, corresponding to michael@0: * code units for the underlying encoding type, for example, michael@0: * a byte index for UTF-8. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual int32_t end(UErrorCode &status) const; michael@0: michael@0: /** michael@0: * Returns the index in the input string of the first character following the michael@0: * text matched during the previous match operation. michael@0: * michael@0: * @param status A reference to a UErrorCode to receive any errors. Possible michael@0: * errors are U_REGEX_INVALID_STATE if no match has been michael@0: * attempted or the last match failed. michael@0: * @return the index of the last character matched, plus one. michael@0: * The index value returned is a native index, corresponding to michael@0: * code units for the underlying encoding type, for example, michael@0: * a byte index for UTF-8. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: virtual int64_t end64(UErrorCode &status) const; michael@0: michael@0: michael@0: /** michael@0: * Returns the index in the input string of the character following the michael@0: * text matched by the specified capture group during the previous match operation. michael@0: * michael@0: * @param group the capture group number michael@0: * @param status A reference to a UErrorCode to receive any errors. Possible michael@0: * errors are U_REGEX_INVALID_STATE if no match has been michael@0: * attempted or the last match failed and michael@0: * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number michael@0: * @return the index of the first character following the text michael@0: * captured by the specified group during the previous match operation. michael@0: * Return -1 if the capture group exists in the pattern but was not part of the match. michael@0: * The index value returned is a native index, corresponding to michael@0: * code units for the underlying encoding type, for example, michael@0: * a byte index for UTF8. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual int32_t end(int32_t group, UErrorCode &status) const; michael@0: michael@0: /** michael@0: * Returns the index in the input string of the character following the michael@0: * text matched by the specified capture group during the previous match operation. michael@0: * michael@0: * @param group the capture group number michael@0: * @param status A reference to a UErrorCode to receive any errors. Possible michael@0: * errors are U_REGEX_INVALID_STATE if no match has been michael@0: * attempted or the last match failed and michael@0: * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number michael@0: * @return the index of the first character following the text michael@0: * captured by the specified group during the previous match operation. michael@0: * Return -1 if the capture group exists in the pattern but was not part of the match. michael@0: * The index value returned is a native index, corresponding to michael@0: * code units for the underlying encoding type, for example, michael@0: * a byte index for UTF8. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: virtual int64_t end64(int32_t group, UErrorCode &status) const; michael@0: michael@0: michael@0: /** michael@0: * Resets this matcher. The effect is to remove any memory of previous matches, michael@0: * and to cause subsequent find() operations to begin at the beginning of michael@0: * the input string. michael@0: * michael@0: * @return this RegexMatcher. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual RegexMatcher &reset(); michael@0: michael@0: michael@0: /** michael@0: * Resets this matcher, and set the current input position. michael@0: * The effect is to remove any memory of previous matches, michael@0: * and to cause subsequent find() operations to begin at michael@0: * the specified (native) position in the input string. michael@0: *

michael@0: * The matcher's region is reset to its default, which is the entire michael@0: * input string. michael@0: *

michael@0: * An alternative to this function is to set a match region michael@0: * beginning at the desired index. michael@0: * michael@0: * @return this RegexMatcher. michael@0: * @stable ICU 2.8 michael@0: */ michael@0: virtual RegexMatcher &reset(int64_t index, UErrorCode &status); michael@0: michael@0: michael@0: /** michael@0: * Resets this matcher with a new input string. This allows instances of RegexMatcher michael@0: * to be reused, which is more efficient than creating a new RegexMatcher for michael@0: * each input string to be processed. michael@0: * @param input The new string on which subsequent pattern matches will operate. michael@0: * The matcher retains a reference to the callers string, and operates michael@0: * directly on that. Ownership of the string remains with the caller. michael@0: * Because no copy of the string is made, it is essential that the michael@0: * caller not delete the string until after regexp operations on it michael@0: * are done. michael@0: * Note that while a reset on the matcher with an input string that is then michael@0: * modified across/during matcher operations may be supported currently for UnicodeString, michael@0: * this was not originally intended behavior, and support for this is not guaranteed michael@0: * in upcoming versions of ICU. michael@0: * @return this RegexMatcher. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual RegexMatcher &reset(const UnicodeString &input); michael@0: michael@0: michael@0: /** michael@0: * Resets this matcher with a new input string. This allows instances of RegexMatcher michael@0: * to be reused, which is more efficient than creating a new RegexMatcher for michael@0: * each input string to be processed. michael@0: * @param input The new string on which subsequent pattern matches will operate. michael@0: * The matcher makes a shallow clone of the given text; ownership of the michael@0: * original string remains with the caller. Because no deep copy of the michael@0: * text is made, it is essential that the caller not modify the string michael@0: * until after regexp operations on it are done. michael@0: * @return this RegexMatcher. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: virtual RegexMatcher &reset(UText *input); michael@0: 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 that moves michael@0: * the text in memory. michael@0: * michael@0: * @param input 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: virtual RegexMatcher &refreshInputText(UText *input, UErrorCode &status); michael@0: michael@0: private: michael@0: /** michael@0: * Cause a compilation error if an application accidentally attempts to michael@0: * reset a matcher with a (UChar *) string as input rather than michael@0: * a UnicodeString. Avoids a dangling reference to a temporary string. michael@0: *

michael@0: * To efficiently work with UChar *strings, wrap the data in a UnicodeString michael@0: * using one of the aliasing constructors, such as michael@0: * UnicodeString(UBool isTerminated, const UChar *text, int32_t textLength); michael@0: * or in a UText, using michael@0: * utext_openUChars(UText *ut, const UChar *text, int64_t textLength, UErrorCode *status); michael@0: * michael@0: */ michael@0: RegexMatcher &reset(const UChar *input); michael@0: public: michael@0: michael@0: /** michael@0: * Returns the input string being matched. Ownership of the string belongs to michael@0: * the matcher; it should not be altered or deleted. This method will work even if the input michael@0: * was originally supplied as a UText. michael@0: * @return the input string michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual const UnicodeString &input() const; michael@0: michael@0: /** michael@0: * Returns the input string being matched. This is the live input text; it should not be michael@0: * altered or deleted. This method will work even if the input was originally supplied as michael@0: * a UnicodeString. michael@0: * @return the input text michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: virtual UText *inputText() const; michael@0: michael@0: /** michael@0: * Returns the input string being matched, either by copying it into the provided michael@0: * UText parameter or by returning a shallow clone of the live input. Note that copying michael@0: * the entire input may cause significant performance and memory issues. michael@0: * @param dest The UText into which the input should be copied, or NULL to create a new UText michael@0: * @param status error code michael@0: * @return dest if non-NULL, a shallow copy of the input text otherwise michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: virtual UText *getInput(UText *dest, UErrorCode &status) const; michael@0: michael@0: michael@0: /** Sets the limits of this matcher's region. michael@0: * The region is the part of the input string that will be searched to find a match. michael@0: * Invoking this method resets the matcher, and then sets the region to start michael@0: * at the index specified by the start parameter and end at the index specified michael@0: * 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 start The (native) index to begin searches at. michael@0: * @param limit The index to end searches at (exclusive). michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: virtual RegexMatcher ®ion(int64_t start, int64_t limit, UErrorCode &status); michael@0: michael@0: /** michael@0: * Identical to region(start, limit, status) but also allows a start position without michael@0: * resetting the region state. michael@0: * @param regionStart The region start michael@0: * @param regionLimit the limit of the region michael@0: * @param startIndex The (native) index within the region bounds at which to begin searches. michael@0: * @param status A reference to a UErrorCode to receive any errors. michael@0: * If startIndex is not within the specified region bounds, michael@0: * U_INDEX_OUTOFBOUNDS_ERROR is returned. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: virtual RegexMatcher ®ion(int64_t regionStart, int64_t regionLimit, int64_t startIndex, UErrorCode &status); michael@0: michael@0: /** michael@0: * Reports the start index of this matcher's region. The searches this matcher michael@0: * conducts are limited to finding matches within regionStart (inclusive) and michael@0: * regionEnd (exclusive). michael@0: * michael@0: * @return The starting (native) index of this matcher's region. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: virtual int32_t regionStart() const; michael@0: michael@0: /** michael@0: * Reports the start index of this matcher's region. The searches this matcher michael@0: * conducts are limited to finding matches within regionStart (inclusive) and michael@0: * regionEnd (exclusive). michael@0: * michael@0: * @return The starting (native) index of this matcher's region. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: virtual int64_t regionStart64() const; michael@0: michael@0: michael@0: /** michael@0: * Reports the end (limit) index (exclusive) of this matcher's region. The searches michael@0: * this matcher conducts are limited to finding matches within regionStart michael@0: * (inclusive) and regionEnd (exclusive). michael@0: * michael@0: * @return The ending point (native) of this matcher's region. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: virtual int32_t regionEnd() const; michael@0: michael@0: /** michael@0: * Reports the end (limit) index (exclusive) of this matcher's region. The searches michael@0: * this matcher conducts are limited to finding matches within regionStart michael@0: * (inclusive) and regionEnd (exclusive). michael@0: * michael@0: * @return The ending point (native) of this matcher's region. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: virtual int64_t regionEnd64() const; michael@0: michael@0: /** michael@0: * Queries the transparency of region bounds for this matcher. michael@0: * See useTransparentBounds for a description of transparent and opaque bounds. michael@0: * By default, a matcher uses opaque region boundaries. michael@0: * 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: virtual UBool hasTransparentBounds() const; michael@0: michael@0: /** michael@0: * Sets the transparency of region bounds for this matcher. michael@0: * Invoking this function with an argument of true will set this matcher 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 this matcher's 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 matcher's region is visible to lookahead, michael@0: * lookbehind, and boundary matching constructs. michael@0: * michael@0: * By default, a matcher uses opaque bounds. michael@0: * michael@0: * @param b TRUE for transparent bounds; FALSE for opaque bounds michael@0: * @return This Matcher; michael@0: * @stable ICU 4.0 michael@0: **/ michael@0: virtual RegexMatcher &useTransparentBounds(UBool b); michael@0: michael@0: michael@0: /** michael@0: * Return true if this matcher is using anchoring bounds. michael@0: * By default, matchers use anchoring region bounds. michael@0: * michael@0: * @return TRUE if this matcher is using anchoring bounds. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: virtual UBool hasAnchoringBounds() const; michael@0: michael@0: michael@0: /** michael@0: * Set whether this matcher 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 b TRUE if to enable anchoring bounds; FALSE to disable them. michael@0: * @return This Matcher michael@0: * @stable ICU 4.0 michael@0: */ michael@0: virtual RegexMatcher &useAnchoringBounds(UBool b); michael@0: michael@0: michael@0: /** michael@0: * Return TRUE if the most recent matching operation attempted to access michael@0: * additional input beyond the available input text. michael@0: * In this case, additional input text could change the results of the match. michael@0: * michael@0: * hitEnd() is defined for both successful and unsuccessful matches. michael@0: * In either case hitEnd() will return TRUE if if the end of the text was michael@0: * reached at any point during the matching process. michael@0: * michael@0: * @return TRUE if the most recent match hit the end of input michael@0: * @stable ICU 4.0 michael@0: */ michael@0: virtual UBool hitEnd() const; 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 method 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: * @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: virtual UBool requireEnd() const; michael@0: michael@0: michael@0: /** michael@0: * Returns the pattern that is interpreted by this matcher. michael@0: * @return the RegexPattern for this RegexMatcher michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual const RegexPattern &pattern() const; 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 first resets this matcher. It then scans the input string michael@0: * looking for matches of the pattern. Input that is not part of any michael@0: * match is left unchanged; each match is replaced in the result by the michael@0: * replacement string. The replacement string may contain references to michael@0: * capture groups. michael@0: * michael@0: * @param replacement a string containing the replacement text. michael@0: * @param status a reference to a UErrorCode to receive any errors. michael@0: * @return a string containing the results of the find and replace. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UnicodeString replaceAll(const UnicodeString &replacement, UErrorCode &status); 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 first resets this matcher. It then scans the input string michael@0: * looking for matches of the pattern. Input that is not part of any michael@0: * match is left unchanged; each match is replaced in the result by the michael@0: * replacement string. The replacement string may contain references to michael@0: * capture groups. michael@0: * michael@0: * @param replacement a string containing the replacement text. michael@0: * @param dest a mutable UText in which the results are placed. 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 string 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: virtual UText *replaceAll(UText *replacement, UText *dest, UErrorCode &status); michael@0: michael@0: michael@0: /** michael@0: * Replaces the first substring of the input that matches michael@0: * the pattern with the replacement string. This is a convenience michael@0: * function that provides a complete find-and-replace operation. michael@0: * michael@0: *

This function first resets this RegexMatcher. It then scans the input string michael@0: * looking for a match of the pattern. Input that is not part michael@0: * of the match is appended directly to the result string; the match is replaced michael@0: * in the result by the replacement string. The replacement string may contain michael@0: * references to captured groups.

michael@0: * michael@0: *

The state of the matcher (the position at which a subsequent find() michael@0: * would begin) after completing a replaceFirst() is not specified. The michael@0: * RegexMatcher should be reset before doing additional find() operations.

michael@0: * michael@0: * @param replacement a string containing the replacement text. michael@0: * @param status a reference to a UErrorCode to receive any errors. michael@0: * @return a string containing the results of the find and replace. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UnicodeString replaceFirst(const UnicodeString &replacement, UErrorCode &status); michael@0: michael@0: michael@0: /** michael@0: * Replaces the first substring of the input that matches michael@0: * the pattern with the replacement string. This is a convenience michael@0: * function that provides a complete find-and-replace operation. michael@0: * michael@0: *

This function first resets this RegexMatcher. It then scans the input string michael@0: * looking for a match of the pattern. Input that is not part michael@0: * of the match is appended directly to the result string; the match is replaced michael@0: * in the result by the replacement string. The replacement string may contain michael@0: * references to captured groups.

michael@0: * michael@0: *

The state of the matcher (the position at which a subsequent find() michael@0: * would begin) after completing a replaceFirst() is not specified. The michael@0: * RegexMatcher should be reset before doing additional find() operations.

michael@0: * michael@0: * @param replacement a string containing the replacement text. michael@0: * @param dest a mutable UText in which the results are placed. 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 string 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: virtual UText *replaceFirst(UText *replacement, UText *dest, UErrorCode &status); michael@0: 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 replacement 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 dest A UnicodeString to which the results of the find-and-replace are appended. michael@0: * @param replacement A UnicodeString that provides the text to be substituted for michael@0: * the input text that matched the regexp pattern. The replacement michael@0: * text may contain references to captured text from the michael@0: * input. michael@0: * @param status A reference to a UErrorCode to receive any errors. Possible michael@0: * errors are U_REGEX_INVALID_STATE if no match has been michael@0: * attempted or the last match failed, and U_INDEX_OUTOFBOUNDS_ERROR michael@0: * if the replacement text specifies a capture group that michael@0: * does not exist in the pattern. michael@0: * michael@0: * @return this RegexMatcher michael@0: * @stable ICU 2.4 michael@0: * michael@0: */ michael@0: virtual RegexMatcher &appendReplacement(UnicodeString &dest, michael@0: const UnicodeString &replacement, UErrorCode &status); michael@0: 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 replacement 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 dest A mutable UText to which the results of the find-and-replace are appended. michael@0: * Must not be NULL. michael@0: * @param replacement A UText that provides the text to be substituted for michael@0: * the input text that matched the regexp pattern. The replacement michael@0: * text may contain references to captured text from the input. michael@0: * @param status A reference to a UErrorCode to receive any errors. Possible michael@0: * errors are U_REGEX_INVALID_STATE if no match has been michael@0: * attempted or the last match failed, and U_INDEX_OUTOFBOUNDS_ERROR michael@0: * if the replacement text specifies a capture group that michael@0: * does not exist in the pattern. michael@0: * michael@0: * @return this RegexMatcher michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: virtual RegexMatcher &appendReplacement(UText *dest, michael@0: UText *replacement, UErrorCode &status); michael@0: 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 appendReplacement(), michael@0: * to the destination string. appendTail() is intended to be invoked after one michael@0: * or more invocations of the RegexMatcher::appendReplacement(). michael@0: * michael@0: * @param dest A UnicodeString to which the results of the find-and-replace are appended. michael@0: * @return the destination string. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UnicodeString &appendTail(UnicodeString &dest); michael@0: 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 appendReplacement(), michael@0: * to the destination string. appendTail() is intended to be invoked after one michael@0: * or more invocations of the RegexMatcher::appendReplacement(). michael@0: * michael@0: * @param dest A mutable UText to which the results of the find-and-replace are appended. michael@0: * Must not be NULL. michael@0: * @param status error cod michael@0: * @return the destination string. michael@0: * michael@0: * @stable ICU 4.6 michael@0: */ michael@0: virtual UText *appendTail(UText *dest, UErrorCode &status); michael@0: 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: * @param input The string to be split into fields. The field delimiters michael@0: * match the pattern (in the "this" object). This matcher michael@0: * will be reset to this input string. michael@0: * @param dest An array of UnicodeStrings to receive the results of the split. michael@0: * This is an array of actual UnicodeString objects, not an michael@0: * array of pointers to strings. Local (stack based) arrays can michael@0: * work well here. michael@0: * @param destCapacity 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: * @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 2.6 michael@0: */ michael@0: virtual int32_t split(const UnicodeString &input, michael@0: UnicodeString dest[], michael@0: int32_t destCapacity, michael@0: UErrorCode &status); michael@0: 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: * @param input The string to be split into fields. The field delimiters michael@0: * match the pattern (in the "this" object). This matcher michael@0: * will be reset to this input string. michael@0: * @param dest 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 destCapacity 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: * @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: virtual int32_t split(UText *input, michael@0: UText *dest[], michael@0: int32_t destCapacity, michael@0: UErrorCode &status); michael@0: michael@0: /** michael@0: * Set a processing time limit for match operations with this Matcher. 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 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: virtual void setTimeLimit(int32_t limit, UErrorCode &status); michael@0: michael@0: /** michael@0: * Get the time limit, if any, for match operations made with this Matcher. michael@0: * 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: virtual int32_t getTimeLimit() const; michael@0: michael@0: /** michael@0: * Set the amount of heap storage available for use by the match backtracking stack. michael@0: * The matcher is also reset, discarding any results from previous matches. 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 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 or equal to zero. michael@0: * 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: virtual void setStackLimit(int32_t limit, 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: virtual int32_t getStackLimit() const; michael@0: michael@0: michael@0: /** michael@0: * Set a callback function for use with this Matcher. 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 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: virtual void setMatchCallback(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 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: virtual void getMatchCallback(URegexMatchCallback *&callback, michael@0: const void *&context, michael@0: UErrorCode &status); michael@0: michael@0: michael@0: /** michael@0: * Set a progress callback function for use with find operations on this Matcher. michael@0: * During find operations, the callback will be invoked after each return from a michael@0: * match attempt, giving the application the opportunity to terminate a long-running michael@0: * find operation. michael@0: * 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: virtual void setFindProgressCallback(URegexFindProgressCallback *callback, michael@0: const void *context, michael@0: UErrorCode &status); michael@0: michael@0: michael@0: /** michael@0: * Get the find progress callback function for this URegularExpression. michael@0: * 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: virtual void getFindProgressCallback(URegexFindProgressCallback *&callback, michael@0: const void *&context, michael@0: UErrorCode &status); michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * setTrace Debug function, enable/disable tracing of the matching engine. michael@0: * For internal ICU development use only. DO NO USE!!!! michael@0: * @internal michael@0: */ michael@0: void setTrace(UBool state); michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: /** michael@0: * ICU "poor man's RTTI", returns a UClassID for this class. michael@0: * michael@0: * @stable ICU 2.2 michael@0: */ michael@0: static UClassID U_EXPORT2 getStaticClassID(); michael@0: michael@0: /** michael@0: * ICU "poor man's RTTI", returns a UClassID for the actual class. michael@0: * michael@0: * @stable ICU 2.2 michael@0: */ michael@0: virtual UClassID getDynamicClassID() const; michael@0: michael@0: private: michael@0: // Constructors and other object boilerplate are private. michael@0: // Instances of RegexMatcher can not be assigned, copied, cloned, etc. michael@0: RegexMatcher(); // default constructor not implemented michael@0: RegexMatcher(const RegexPattern *pat); michael@0: RegexMatcher(const RegexMatcher &other); michael@0: RegexMatcher &operator =(const RegexMatcher &rhs); michael@0: void init(UErrorCode &status); // Common initialization michael@0: void init2(UText *t, UErrorCode &e); // Common initialization, part 2. michael@0: michael@0: friend class RegexPattern; michael@0: friend class RegexCImpl; michael@0: public: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** @internal */ michael@0: void resetPreserveRegion(); // Reset matcher state, but preserve any region. michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: private: michael@0: michael@0: // michael@0: // MatchAt This is the internal interface to the match engine itself. michael@0: // Match status comes back in matcher member variables. michael@0: // michael@0: void MatchAt(int64_t startIdx, UBool toEnd, UErrorCode &status); michael@0: inline void backTrack(int64_t &inputIdx, int32_t &patIdx); michael@0: UBool isWordBoundary(int64_t pos); // perform Perl-like \b test michael@0: UBool isUWordBoundary(int64_t pos); // perform RBBI based \b test michael@0: REStackFrame *resetStack(); michael@0: inline REStackFrame *StateSave(REStackFrame *fp, int64_t savePatIdx, UErrorCode &status); michael@0: void IncrementTime(UErrorCode &status); michael@0: UBool ReportFindProgress(int64_t matchIndex, UErrorCode &status); michael@0: michael@0: int64_t appendGroup(int32_t groupNum, UText *dest, UErrorCode &status) const; michael@0: michael@0: UBool findUsingChunk(); michael@0: void MatchChunkAt(int32_t startIdx, UBool toEnd, UErrorCode &status); michael@0: UBool isChunkWordBoundary(int32_t pos); michael@0: michael@0: const RegexPattern *fPattern; michael@0: RegexPattern *fPatternOwned; // Non-NULL if this matcher owns the pattern, and michael@0: // should delete it when through. michael@0: michael@0: const UnicodeString *fInput; // The string being matched. Only used for input() michael@0: UText *fInputText; // The text being matched. Is never NULL. michael@0: UText *fAltInputText; // A shallow copy of the text being matched. michael@0: // Only created if the pattern contains backreferences. michael@0: int64_t fInputLength; // Full length of the input text. michael@0: int32_t fFrameSize; // The size of a frame in the backtrack stack. michael@0: michael@0: int64_t fRegionStart; // Start of the input region, default = 0. michael@0: int64_t fRegionLimit; // End of input region, default to input.length. michael@0: michael@0: int64_t fAnchorStart; // Region bounds for anchoring operations (^ or $). michael@0: int64_t fAnchorLimit; // See useAnchoringBounds michael@0: michael@0: int64_t fLookStart; // Region bounds for look-ahead/behind and michael@0: int64_t fLookLimit; // and other boundary tests. See michael@0: // useTransparentBounds michael@0: michael@0: int64_t fActiveStart; // Currently active bounds for matching. michael@0: int64_t fActiveLimit; // Usually is the same as region, but michael@0: // is changed to fLookStart/Limit when michael@0: // entering look around regions. michael@0: michael@0: UBool fTransparentBounds; // True if using transparent bounds. michael@0: UBool fAnchoringBounds; // True if using anchoring bounds. michael@0: michael@0: UBool fMatch; // True if the last attempted match was successful. michael@0: int64_t fMatchStart; // Position of the start of the most recent match michael@0: int64_t fMatchEnd; // First position after the end of the most recent match michael@0: // Zero if no previous match, even when a region michael@0: // is active. michael@0: int64_t fLastMatchEnd; // First position after the end of the previous match, michael@0: // or -1 if there was no previous match. michael@0: int64_t fAppendPosition; // First position after the end of the previous michael@0: // appendReplacement(). As described by the michael@0: // JavaDoc for Java Matcher, where it is called michael@0: // "append position" michael@0: UBool fHitEnd; // True if the last match touched the end of input. michael@0: UBool fRequireEnd; // True if the last match required end-of-input michael@0: // (matched $ or Z) michael@0: michael@0: UVector64 *fStack; michael@0: REStackFrame *fFrame; // After finding a match, the last active stack frame, michael@0: // which will contain the capture group results. michael@0: // NOT valid while match engine is running. michael@0: michael@0: int64_t *fData; // Data area for use by the compiled pattern. michael@0: int64_t fSmallData[8]; // Use this for data if it's enough. michael@0: michael@0: int32_t fTimeLimit; // Max time (in arbitrary steps) to let the michael@0: // match engine run. Zero for unlimited. michael@0: michael@0: int32_t fTime; // Match time, accumulates while matching. michael@0: int32_t fTickCounter; // Low bits counter for time. Counts down StateSaves. michael@0: // Kept separately from fTime to keep as much michael@0: // code as possible out of the inline michael@0: // StateSave function. michael@0: michael@0: int32_t fStackLimit; // Maximum memory size to use for the backtrack michael@0: // stack, in bytes. Zero for unlimited. michael@0: michael@0: URegexMatchCallback *fCallbackFn; // Pointer to match progress callback funct. michael@0: // NULL if there is no callback. michael@0: const void *fCallbackContext; // User Context ptr for callback function. michael@0: michael@0: URegexFindProgressCallback *fFindProgressCallbackFn; // Pointer to match progress callback funct. michael@0: // NULL if there is no callback. michael@0: const void *fFindProgressCallbackContext; // User Context ptr for callback function. michael@0: michael@0: michael@0: UBool fInputUniStrMaybeMutable; // Set when fInputText wraps a UnicodeString that may be mutable - compatibility. michael@0: michael@0: UBool fTraceDebug; // Set true for debug tracing of match engine. michael@0: michael@0: UErrorCode fDeferredStatus; // Save error state that cannot be immediately michael@0: // reported, or that permanently disables this matcher. michael@0: michael@0: RuleBasedBreakIterator *fWordBreakItr; michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: #endif // UCONFIG_NO_REGULAR_EXPRESSIONS michael@0: #endif