Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | ********************************************************************** |
michael@0 | 3 | * Copyright (C) 2002-2013, International Business Machines |
michael@0 | 4 | * Corporation and others. All Rights Reserved. |
michael@0 | 5 | ********************************************************************** |
michael@0 | 6 | * file name: regex.h |
michael@0 | 7 | * encoding: US-ASCII |
michael@0 | 8 | * indentation:4 |
michael@0 | 9 | * |
michael@0 | 10 | * created on: 2002oct22 |
michael@0 | 11 | * created by: Andy Heninger |
michael@0 | 12 | * |
michael@0 | 13 | * ICU Regular Expressions, API for C++ |
michael@0 | 14 | */ |
michael@0 | 15 | |
michael@0 | 16 | #ifndef REGEX_H |
michael@0 | 17 | #define REGEX_H |
michael@0 | 18 | |
michael@0 | 19 | //#define REGEX_DEBUG |
michael@0 | 20 | |
michael@0 | 21 | /** |
michael@0 | 22 | * \file |
michael@0 | 23 | * \brief C++ API: Regular Expressions |
michael@0 | 24 | * |
michael@0 | 25 | * <h2>Regular Expression API</h2> |
michael@0 | 26 | * |
michael@0 | 27 | * <p>The ICU API for processing regular expressions consists of two classes, |
michael@0 | 28 | * <code>RegexPattern</code> and <code>RegexMatcher</code>. |
michael@0 | 29 | * <code>RegexPattern</code> objects represent a pre-processed, or compiled |
michael@0 | 30 | * regular expression. They are created from a regular expression pattern string, |
michael@0 | 31 | * and can be used to create <code>RegexMatcher</code> objects for the pattern.</p> |
michael@0 | 32 | * |
michael@0 | 33 | * <p>Class <code>RegexMatcher</code> bundles together a regular expression |
michael@0 | 34 | * pattern and a target string to which the search pattern will be applied. |
michael@0 | 35 | * <code>RegexMatcher</code> includes API for doing plain find or search |
michael@0 | 36 | * operations, for search and replace operations, and for obtaining detailed |
michael@0 | 37 | * information about bounds of a match. </p> |
michael@0 | 38 | * |
michael@0 | 39 | * <p>Note that by constructing <code>RegexMatcher</code> objects directly from regular |
michael@0 | 40 | * expression pattern strings application code can be simplified and the explicit |
michael@0 | 41 | * need for <code>RegexPattern</code> objects can usually be eliminated. |
michael@0 | 42 | * </p> |
michael@0 | 43 | */ |
michael@0 | 44 | |
michael@0 | 45 | #include "unicode/utypes.h" |
michael@0 | 46 | |
michael@0 | 47 | #if !UCONFIG_NO_REGULAR_EXPRESSIONS |
michael@0 | 48 | |
michael@0 | 49 | #include "unicode/uobject.h" |
michael@0 | 50 | #include "unicode/unistr.h" |
michael@0 | 51 | #include "unicode/utext.h" |
michael@0 | 52 | #include "unicode/parseerr.h" |
michael@0 | 53 | |
michael@0 | 54 | #include "unicode/uregex.h" |
michael@0 | 55 | |
michael@0 | 56 | // Forward Declarations |
michael@0 | 57 | |
michael@0 | 58 | U_NAMESPACE_BEGIN |
michael@0 | 59 | |
michael@0 | 60 | struct Regex8BitSet; |
michael@0 | 61 | class RegexCImpl; |
michael@0 | 62 | class RegexMatcher; |
michael@0 | 63 | class RegexPattern; |
michael@0 | 64 | struct REStackFrame; |
michael@0 | 65 | class RuleBasedBreakIterator; |
michael@0 | 66 | class UnicodeSet; |
michael@0 | 67 | class UVector; |
michael@0 | 68 | class UVector32; |
michael@0 | 69 | class UVector64; |
michael@0 | 70 | |
michael@0 | 71 | #ifndef U_HIDE_INTERNAL_API |
michael@0 | 72 | /** |
michael@0 | 73 | * RBBIPatternDump Debug function, displays the compiled form of a pattern. |
michael@0 | 74 | * @internal |
michael@0 | 75 | */ |
michael@0 | 76 | #ifdef REGEX_DEBUG |
michael@0 | 77 | U_INTERNAL void U_EXPORT2 |
michael@0 | 78 | RegexPatternDump(const RegexPattern *pat); |
michael@0 | 79 | #else |
michael@0 | 80 | #undef RegexPatternDump |
michael@0 | 81 | #define RegexPatternDump(pat) |
michael@0 | 82 | #endif |
michael@0 | 83 | #endif /* U_HIDE_INTERNAL_API */ |
michael@0 | 84 | |
michael@0 | 85 | |
michael@0 | 86 | |
michael@0 | 87 | /** |
michael@0 | 88 | * Class <code>RegexPattern</code> represents a compiled regular expression. It includes |
michael@0 | 89 | * factory methods for creating a RegexPattern object from the source (string) form |
michael@0 | 90 | * of a regular expression, methods for creating RegexMatchers that allow the pattern |
michael@0 | 91 | * to be applied to input text, and a few convenience methods for simple common |
michael@0 | 92 | * uses of regular expressions. |
michael@0 | 93 | * |
michael@0 | 94 | * <p>Class RegexPattern is not intended to be subclassed.</p> |
michael@0 | 95 | * |
michael@0 | 96 | * @stable ICU 2.4 |
michael@0 | 97 | */ |
michael@0 | 98 | class U_I18N_API RegexPattern: public UObject { |
michael@0 | 99 | public: |
michael@0 | 100 | |
michael@0 | 101 | /** |
michael@0 | 102 | * default constructor. Create a RegexPattern object that refers to no actual |
michael@0 | 103 | * pattern. Not normally needed; RegexPattern objects are usually |
michael@0 | 104 | * created using the factory method <code>compile()</code>. |
michael@0 | 105 | * |
michael@0 | 106 | * @stable ICU 2.4 |
michael@0 | 107 | */ |
michael@0 | 108 | RegexPattern(); |
michael@0 | 109 | |
michael@0 | 110 | /** |
michael@0 | 111 | * Copy Constructor. Create a new RegexPattern object that is equivalent |
michael@0 | 112 | * to the source object. |
michael@0 | 113 | * @param source the pattern object to be copied. |
michael@0 | 114 | * @stable ICU 2.4 |
michael@0 | 115 | */ |
michael@0 | 116 | RegexPattern(const RegexPattern &source); |
michael@0 | 117 | |
michael@0 | 118 | /** |
michael@0 | 119 | * Destructor. Note that a RegexPattern object must persist so long as any |
michael@0 | 120 | * RegexMatcher objects that were created from the RegexPattern are active. |
michael@0 | 121 | * @stable ICU 2.4 |
michael@0 | 122 | */ |
michael@0 | 123 | virtual ~RegexPattern(); |
michael@0 | 124 | |
michael@0 | 125 | /** |
michael@0 | 126 | * Comparison operator. Two RegexPattern objects are considered equal if they |
michael@0 | 127 | * were constructed from identical source patterns using the same match flag |
michael@0 | 128 | * settings. |
michael@0 | 129 | * @param that a RegexPattern object to compare with "this". |
michael@0 | 130 | * @return TRUE if the objects are equivalent. |
michael@0 | 131 | * @stable ICU 2.4 |
michael@0 | 132 | */ |
michael@0 | 133 | UBool operator==(const RegexPattern& that) const; |
michael@0 | 134 | |
michael@0 | 135 | /** |
michael@0 | 136 | * Comparison operator. Two RegexPattern objects are considered equal if they |
michael@0 | 137 | * were constructed from identical source patterns using the same match flag |
michael@0 | 138 | * settings. |
michael@0 | 139 | * @param that a RegexPattern object to compare with "this". |
michael@0 | 140 | * @return TRUE if the objects are different. |
michael@0 | 141 | * @stable ICU 2.4 |
michael@0 | 142 | */ |
michael@0 | 143 | inline UBool operator!=(const RegexPattern& that) const {return ! operator ==(that);} |
michael@0 | 144 | |
michael@0 | 145 | /** |
michael@0 | 146 | * Assignment operator. After assignment, this RegexPattern will behave identically |
michael@0 | 147 | * to the source object. |
michael@0 | 148 | * @stable ICU 2.4 |
michael@0 | 149 | */ |
michael@0 | 150 | RegexPattern &operator =(const RegexPattern &source); |
michael@0 | 151 | |
michael@0 | 152 | /** |
michael@0 | 153 | * Create an exact copy of this RegexPattern object. Since RegexPattern is not |
michael@0 | 154 | * intended to be subclasses, <code>clone()</code> and the copy construction are |
michael@0 | 155 | * equivalent operations. |
michael@0 | 156 | * @return the copy of this RegexPattern |
michael@0 | 157 | * @stable ICU 2.4 |
michael@0 | 158 | */ |
michael@0 | 159 | virtual RegexPattern *clone() const; |
michael@0 | 160 | |
michael@0 | 161 | |
michael@0 | 162 | /** |
michael@0 | 163 | * Compiles the regular expression in string form into a RegexPattern |
michael@0 | 164 | * object. These compile methods, rather than the constructors, are the usual |
michael@0 | 165 | * way that RegexPattern objects are created. |
michael@0 | 166 | * |
michael@0 | 167 | * <p>Note that RegexPattern objects must not be deleted while RegexMatcher |
michael@0 | 168 | * objects created from the pattern are active. RegexMatchers keep a pointer |
michael@0 | 169 | * back to their pattern, so premature deletion of the pattern is a |
michael@0 | 170 | * catastrophic error.</p> |
michael@0 | 171 | * |
michael@0 | 172 | * <p>All pattern match mode flags are set to their default values.</p> |
michael@0 | 173 | * |
michael@0 | 174 | * <p>Note that it is often more convenient to construct a RegexMatcher directly |
michael@0 | 175 | * from a pattern string rather than separately compiling the pattern and |
michael@0 | 176 | * then creating a RegexMatcher object from the pattern.</p> |
michael@0 | 177 | * |
michael@0 | 178 | * @param regex The regular expression to be compiled. |
michael@0 | 179 | * @param pe Receives the position (line and column nubers) of any error |
michael@0 | 180 | * within the regular expression.) |
michael@0 | 181 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 182 | * @return A regexPattern object for the compiled pattern. |
michael@0 | 183 | * |
michael@0 | 184 | * @stable ICU 2.4 |
michael@0 | 185 | */ |
michael@0 | 186 | static RegexPattern * U_EXPORT2 compile( const UnicodeString ®ex, |
michael@0 | 187 | UParseError &pe, |
michael@0 | 188 | UErrorCode &status); |
michael@0 | 189 | |
michael@0 | 190 | /** |
michael@0 | 191 | * Compiles the regular expression in string form into a RegexPattern |
michael@0 | 192 | * object. These compile methods, rather than the constructors, are the usual |
michael@0 | 193 | * way that RegexPattern objects are created. |
michael@0 | 194 | * |
michael@0 | 195 | * <p>Note that RegexPattern objects must not be deleted while RegexMatcher |
michael@0 | 196 | * objects created from the pattern are active. RegexMatchers keep a pointer |
michael@0 | 197 | * back to their pattern, so premature deletion of the pattern is a |
michael@0 | 198 | * catastrophic error.</p> |
michael@0 | 199 | * |
michael@0 | 200 | * <p>All pattern match mode flags are set to their default values.</p> |
michael@0 | 201 | * |
michael@0 | 202 | * <p>Note that it is often more convenient to construct a RegexMatcher directly |
michael@0 | 203 | * from a pattern string rather than separately compiling the pattern and |
michael@0 | 204 | * then creating a RegexMatcher object from the pattern.</p> |
michael@0 | 205 | * |
michael@0 | 206 | * @param regex The regular expression to be compiled. Note, the text referred |
michael@0 | 207 | * to by this UText must not be deleted during the lifetime of the |
michael@0 | 208 | * RegexPattern object or any RegexMatcher object created from it. |
michael@0 | 209 | * @param pe Receives the position (line and column nubers) of any error |
michael@0 | 210 | * within the regular expression.) |
michael@0 | 211 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 212 | * @return A regexPattern object for the compiled pattern. |
michael@0 | 213 | * |
michael@0 | 214 | * @stable ICU 4.6 |
michael@0 | 215 | */ |
michael@0 | 216 | static RegexPattern * U_EXPORT2 compile( UText *regex, |
michael@0 | 217 | UParseError &pe, |
michael@0 | 218 | UErrorCode &status); |
michael@0 | 219 | |
michael@0 | 220 | /** |
michael@0 | 221 | * Compiles the regular expression in string form into a RegexPattern |
michael@0 | 222 | * object using the specified match mode flags. These compile methods, |
michael@0 | 223 | * rather than the constructors, are the usual way that RegexPattern objects |
michael@0 | 224 | * are created. |
michael@0 | 225 | * |
michael@0 | 226 | * <p>Note that RegexPattern objects must not be deleted while RegexMatcher |
michael@0 | 227 | * objects created from the pattern are active. RegexMatchers keep a pointer |
michael@0 | 228 | * back to their pattern, so premature deletion of the pattern is a |
michael@0 | 229 | * catastrophic error.</p> |
michael@0 | 230 | * |
michael@0 | 231 | * <p>Note that it is often more convenient to construct a RegexMatcher directly |
michael@0 | 232 | * from a pattern string instead of than separately compiling the pattern and |
michael@0 | 233 | * then creating a RegexMatcher object from the pattern.</p> |
michael@0 | 234 | * |
michael@0 | 235 | * @param regex The regular expression to be compiled. |
michael@0 | 236 | * @param flags The match mode flags to be used. |
michael@0 | 237 | * @param pe Receives the position (line and column numbers) of any error |
michael@0 | 238 | * within the regular expression.) |
michael@0 | 239 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 240 | * @return A regexPattern object for the compiled pattern. |
michael@0 | 241 | * |
michael@0 | 242 | * @stable ICU 2.4 |
michael@0 | 243 | */ |
michael@0 | 244 | static RegexPattern * U_EXPORT2 compile( const UnicodeString ®ex, |
michael@0 | 245 | uint32_t flags, |
michael@0 | 246 | UParseError &pe, |
michael@0 | 247 | UErrorCode &status); |
michael@0 | 248 | |
michael@0 | 249 | /** |
michael@0 | 250 | * Compiles the regular expression in string form into a RegexPattern |
michael@0 | 251 | * object using the specified match mode flags. These compile methods, |
michael@0 | 252 | * rather than the constructors, are the usual way that RegexPattern objects |
michael@0 | 253 | * are created. |
michael@0 | 254 | * |
michael@0 | 255 | * <p>Note that RegexPattern objects must not be deleted while RegexMatcher |
michael@0 | 256 | * objects created from the pattern are active. RegexMatchers keep a pointer |
michael@0 | 257 | * back to their pattern, so premature deletion of the pattern is a |
michael@0 | 258 | * catastrophic error.</p> |
michael@0 | 259 | * |
michael@0 | 260 | * <p>Note that it is often more convenient to construct a RegexMatcher directly |
michael@0 | 261 | * from a pattern string instead of than separately compiling the pattern and |
michael@0 | 262 | * then creating a RegexMatcher object from the pattern.</p> |
michael@0 | 263 | * |
michael@0 | 264 | * @param regex The regular expression to be compiled. Note, the text referred |
michael@0 | 265 | * to by this UText must not be deleted during the lifetime of the |
michael@0 | 266 | * RegexPattern object or any RegexMatcher object created from it. |
michael@0 | 267 | * @param flags The match mode flags to be used. |
michael@0 | 268 | * @param pe Receives the position (line and column numbers) of any error |
michael@0 | 269 | * within the regular expression.) |
michael@0 | 270 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 271 | * @return A regexPattern object for the compiled pattern. |
michael@0 | 272 | * |
michael@0 | 273 | * @stable ICU 4.6 |
michael@0 | 274 | */ |
michael@0 | 275 | static RegexPattern * U_EXPORT2 compile( UText *regex, |
michael@0 | 276 | uint32_t flags, |
michael@0 | 277 | UParseError &pe, |
michael@0 | 278 | UErrorCode &status); |
michael@0 | 279 | |
michael@0 | 280 | /** |
michael@0 | 281 | * Compiles the regular expression in string form into a RegexPattern |
michael@0 | 282 | * object using the specified match mode flags. These compile methods, |
michael@0 | 283 | * rather than the constructors, are the usual way that RegexPattern objects |
michael@0 | 284 | * are created. |
michael@0 | 285 | * |
michael@0 | 286 | * <p>Note that RegexPattern objects must not be deleted while RegexMatcher |
michael@0 | 287 | * objects created from the pattern are active. RegexMatchers keep a pointer |
michael@0 | 288 | * back to their pattern, so premature deletion of the pattern is a |
michael@0 | 289 | * catastrophic error.</p> |
michael@0 | 290 | * |
michael@0 | 291 | * <p>Note that it is often more convenient to construct a RegexMatcher directly |
michael@0 | 292 | * from a pattern string instead of than separately compiling the pattern and |
michael@0 | 293 | * then creating a RegexMatcher object from the pattern.</p> |
michael@0 | 294 | * |
michael@0 | 295 | * @param regex The regular expression to be compiled. |
michael@0 | 296 | * @param flags The match mode flags to be used. |
michael@0 | 297 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 298 | * @return A regexPattern object for the compiled pattern. |
michael@0 | 299 | * |
michael@0 | 300 | * @stable ICU 2.6 |
michael@0 | 301 | */ |
michael@0 | 302 | static RegexPattern * U_EXPORT2 compile( const UnicodeString ®ex, |
michael@0 | 303 | uint32_t flags, |
michael@0 | 304 | UErrorCode &status); |
michael@0 | 305 | |
michael@0 | 306 | /** |
michael@0 | 307 | * Compiles the regular expression in string form into a RegexPattern |
michael@0 | 308 | * object using the specified match mode flags. These compile methods, |
michael@0 | 309 | * rather than the constructors, are the usual way that RegexPattern objects |
michael@0 | 310 | * are created. |
michael@0 | 311 | * |
michael@0 | 312 | * <p>Note that RegexPattern objects must not be deleted while RegexMatcher |
michael@0 | 313 | * objects created from the pattern are active. RegexMatchers keep a pointer |
michael@0 | 314 | * back to their pattern, so premature deletion of the pattern is a |
michael@0 | 315 | * catastrophic error.</p> |
michael@0 | 316 | * |
michael@0 | 317 | * <p>Note that it is often more convenient to construct a RegexMatcher directly |
michael@0 | 318 | * from a pattern string instead of than separately compiling the pattern and |
michael@0 | 319 | * then creating a RegexMatcher object from the pattern.</p> |
michael@0 | 320 | * |
michael@0 | 321 | * @param regex The regular expression to be compiled. Note, the text referred |
michael@0 | 322 | * to by this UText must not be deleted during the lifetime of the |
michael@0 | 323 | * RegexPattern object or any RegexMatcher object created from it. |
michael@0 | 324 | * @param flags The match mode flags to be used. |
michael@0 | 325 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 326 | * @return A regexPattern object for the compiled pattern. |
michael@0 | 327 | * |
michael@0 | 328 | * @stable ICU 4.6 |
michael@0 | 329 | */ |
michael@0 | 330 | static RegexPattern * U_EXPORT2 compile( UText *regex, |
michael@0 | 331 | uint32_t flags, |
michael@0 | 332 | UErrorCode &status); |
michael@0 | 333 | |
michael@0 | 334 | /** |
michael@0 | 335 | * Get the match mode flags that were used when compiling this pattern. |
michael@0 | 336 | * @return the match mode flags |
michael@0 | 337 | * @stable ICU 2.4 |
michael@0 | 338 | */ |
michael@0 | 339 | virtual uint32_t flags() const; |
michael@0 | 340 | |
michael@0 | 341 | /** |
michael@0 | 342 | * Creates a RegexMatcher that will match the given input against this pattern. The |
michael@0 | 343 | * RegexMatcher can then be used to perform match, find or replace operations |
michael@0 | 344 | * on the input. Note that a RegexPattern object must not be deleted while |
michael@0 | 345 | * RegexMatchers created from it still exist and might possibly be used again. |
michael@0 | 346 | * <p> |
michael@0 | 347 | * The matcher will retain a reference to the supplied input string, and all regexp |
michael@0 | 348 | * pattern matching operations happen directly on this original string. It is |
michael@0 | 349 | * critical that the string not be altered or deleted before use by the regular |
michael@0 | 350 | * expression operations is complete. |
michael@0 | 351 | * |
michael@0 | 352 | * @param input The input string to which the regular expression will be applied. |
michael@0 | 353 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 354 | * @return A RegexMatcher object for this pattern and input. |
michael@0 | 355 | * |
michael@0 | 356 | * @stable ICU 2.4 |
michael@0 | 357 | */ |
michael@0 | 358 | virtual RegexMatcher *matcher(const UnicodeString &input, |
michael@0 | 359 | UErrorCode &status) const; |
michael@0 | 360 | |
michael@0 | 361 | private: |
michael@0 | 362 | /** |
michael@0 | 363 | * Cause a compilation error if an application accidentally attempts to |
michael@0 | 364 | * create a matcher with a (UChar *) string as input rather than |
michael@0 | 365 | * a UnicodeString. Avoids a dangling reference to a temporary string. |
michael@0 | 366 | * <p> |
michael@0 | 367 | * To efficiently work with UChar *strings, wrap the data in a UnicodeString |
michael@0 | 368 | * using one of the aliasing constructors, such as |
michael@0 | 369 | * <code>UnicodeString(UBool isTerminated, const UChar *text, int32_t textLength);</code> |
michael@0 | 370 | * or in a UText, using |
michael@0 | 371 | * <code>utext_openUChars(UText *ut, const UChar *text, int64_t textLength, UErrorCode *status);</code> |
michael@0 | 372 | * |
michael@0 | 373 | */ |
michael@0 | 374 | RegexMatcher *matcher(const UChar *input, |
michael@0 | 375 | UErrorCode &status) const; |
michael@0 | 376 | public: |
michael@0 | 377 | |
michael@0 | 378 | |
michael@0 | 379 | /** |
michael@0 | 380 | * Creates a RegexMatcher that will match against this pattern. The |
michael@0 | 381 | * RegexMatcher can be used to perform match, find or replace operations. |
michael@0 | 382 | * Note that a RegexPattern object must not be deleted while |
michael@0 | 383 | * RegexMatchers created from it still exist and might possibly be used again. |
michael@0 | 384 | * |
michael@0 | 385 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 386 | * @return A RegexMatcher object for this pattern and input. |
michael@0 | 387 | * |
michael@0 | 388 | * @stable ICU 2.6 |
michael@0 | 389 | */ |
michael@0 | 390 | virtual RegexMatcher *matcher(UErrorCode &status) const; |
michael@0 | 391 | |
michael@0 | 392 | |
michael@0 | 393 | /** |
michael@0 | 394 | * Test whether a string matches a regular expression. This convenience function |
michael@0 | 395 | * both compiles the regular expression and applies it in a single operation. |
michael@0 | 396 | * Note that if the same pattern needs to be applied repeatedly, this method will be |
michael@0 | 397 | * less efficient than creating and reusing a RegexMatcher object. |
michael@0 | 398 | * |
michael@0 | 399 | * @param regex The regular expression |
michael@0 | 400 | * @param input The string data to be matched |
michael@0 | 401 | * @param pe Receives the position of any syntax errors within the regular expression |
michael@0 | 402 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 403 | * @return True if the regular expression exactly matches the full input string. |
michael@0 | 404 | * |
michael@0 | 405 | * @stable ICU 2.4 |
michael@0 | 406 | */ |
michael@0 | 407 | static UBool U_EXPORT2 matches(const UnicodeString ®ex, |
michael@0 | 408 | const UnicodeString &input, |
michael@0 | 409 | UParseError &pe, |
michael@0 | 410 | UErrorCode &status); |
michael@0 | 411 | |
michael@0 | 412 | /** |
michael@0 | 413 | * Test whether a string matches a regular expression. This convenience function |
michael@0 | 414 | * both compiles the regular expression and applies it in a single operation. |
michael@0 | 415 | * Note that if the same pattern needs to be applied repeatedly, this method will be |
michael@0 | 416 | * less efficient than creating and reusing a RegexMatcher object. |
michael@0 | 417 | * |
michael@0 | 418 | * @param regex The regular expression |
michael@0 | 419 | * @param input The string data to be matched |
michael@0 | 420 | * @param pe Receives the position of any syntax errors within the regular expression |
michael@0 | 421 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 422 | * @return True if the regular expression exactly matches the full input string. |
michael@0 | 423 | * |
michael@0 | 424 | * @stable ICU 4.6 |
michael@0 | 425 | */ |
michael@0 | 426 | static UBool U_EXPORT2 matches(UText *regex, |
michael@0 | 427 | UText *input, |
michael@0 | 428 | UParseError &pe, |
michael@0 | 429 | UErrorCode &status); |
michael@0 | 430 | |
michael@0 | 431 | /** |
michael@0 | 432 | * Returns the regular expression from which this pattern was compiled. This method will work |
michael@0 | 433 | * even if the pattern was compiled from a UText. |
michael@0 | 434 | * |
michael@0 | 435 | * Note: If the pattern was originally compiled from a UText, and that UText was modified, |
michael@0 | 436 | * the returned string may no longer reflect the RegexPattern object. |
michael@0 | 437 | * @stable ICU 2.4 |
michael@0 | 438 | */ |
michael@0 | 439 | virtual UnicodeString pattern() const; |
michael@0 | 440 | |
michael@0 | 441 | |
michael@0 | 442 | /** |
michael@0 | 443 | * Returns the regular expression from which this pattern was compiled. This method will work |
michael@0 | 444 | * even if the pattern was compiled from a UnicodeString. |
michael@0 | 445 | * |
michael@0 | 446 | * Note: This is the original input, not a clone. If the pattern was originally compiled from a |
michael@0 | 447 | * UText, and that UText was modified, the returned UText may no longer reflect the RegexPattern |
michael@0 | 448 | * object. |
michael@0 | 449 | * |
michael@0 | 450 | * @stable ICU 4.6 |
michael@0 | 451 | */ |
michael@0 | 452 | virtual UText *patternText(UErrorCode &status) const; |
michael@0 | 453 | |
michael@0 | 454 | |
michael@0 | 455 | /** |
michael@0 | 456 | * Split a string into fields. Somewhat like split() from Perl or Java. |
michael@0 | 457 | * Pattern matches identify delimiters that separate the input |
michael@0 | 458 | * into fields. The input data between the delimiters becomes the |
michael@0 | 459 | * fields themselves. |
michael@0 | 460 | * |
michael@0 | 461 | * If the delimiter pattern includes capture groups, the captured text will |
michael@0 | 462 | * also appear in the destination array of output strings, interspersed |
michael@0 | 463 | * with the fields. This is similar to Perl, but differs from Java, |
michael@0 | 464 | * which ignores the presence of capture groups in the pattern. |
michael@0 | 465 | * |
michael@0 | 466 | * Trailing empty fields will always be returned, assuming sufficient |
michael@0 | 467 | * destination capacity. This differs from the default behavior for Java |
michael@0 | 468 | * and Perl where trailing empty fields are not returned. |
michael@0 | 469 | * |
michael@0 | 470 | * The number of strings produced by the split operation is returned. |
michael@0 | 471 | * This count includes the strings from capture groups in the delimiter pattern. |
michael@0 | 472 | * This behavior differs from Java, which ignores capture groups. |
michael@0 | 473 | * |
michael@0 | 474 | * For the best performance on split() operations, |
michael@0 | 475 | * <code>RegexMatcher::split</code> is preferable to this function |
michael@0 | 476 | * |
michael@0 | 477 | * @param input The string to be split into fields. The field delimiters |
michael@0 | 478 | * match the pattern (in the "this" object) |
michael@0 | 479 | * @param dest An array of UnicodeStrings to receive the results of the split. |
michael@0 | 480 | * This is an array of actual UnicodeString objects, not an |
michael@0 | 481 | * array of pointers to strings. Local (stack based) arrays can |
michael@0 | 482 | * work well here. |
michael@0 | 483 | * @param destCapacity The number of elements in the destination array. |
michael@0 | 484 | * If the number of fields found is less than destCapacity, the |
michael@0 | 485 | * extra strings in the destination array are not altered. |
michael@0 | 486 | * If the number of destination strings is less than the number |
michael@0 | 487 | * of fields, the trailing part of the input string, including any |
michael@0 | 488 | * field delimiters, is placed in the last destination string. |
michael@0 | 489 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 490 | * @return The number of fields into which the input string was split. |
michael@0 | 491 | * @stable ICU 2.4 |
michael@0 | 492 | */ |
michael@0 | 493 | virtual int32_t split(const UnicodeString &input, |
michael@0 | 494 | UnicodeString dest[], |
michael@0 | 495 | int32_t destCapacity, |
michael@0 | 496 | UErrorCode &status) const; |
michael@0 | 497 | |
michael@0 | 498 | |
michael@0 | 499 | /** |
michael@0 | 500 | * Split a string into fields. Somewhat like split() from Perl or Java. |
michael@0 | 501 | * Pattern matches identify delimiters that separate the input |
michael@0 | 502 | * into fields. The input data between the delimiters becomes the |
michael@0 | 503 | * fields themselves. |
michael@0 | 504 | * |
michael@0 | 505 | * If the delimiter pattern includes capture groups, the captured text will |
michael@0 | 506 | * also appear in the destination array of output strings, interspersed |
michael@0 | 507 | * with the fields. This is similar to Perl, but differs from Java, |
michael@0 | 508 | * which ignores the presence of capture groups in the pattern. |
michael@0 | 509 | * |
michael@0 | 510 | * Trailing empty fields will always be returned, assuming sufficient |
michael@0 | 511 | * destination capacity. This differs from the default behavior for Java |
michael@0 | 512 | * and Perl where trailing empty fields are not returned. |
michael@0 | 513 | * |
michael@0 | 514 | * The number of strings produced by the split operation is returned. |
michael@0 | 515 | * This count includes the strings from capture groups in the delimiter pattern. |
michael@0 | 516 | * This behavior differs from Java, which ignores capture groups. |
michael@0 | 517 | * |
michael@0 | 518 | * For the best performance on split() operations, |
michael@0 | 519 | * <code>RegexMatcher::split</code> is preferable to this function |
michael@0 | 520 | * |
michael@0 | 521 | * @param input The string to be split into fields. The field delimiters |
michael@0 | 522 | * match the pattern (in the "this" object) |
michael@0 | 523 | * @param dest An array of mutable UText structs to receive the results of the split. |
michael@0 | 524 | * If a field is NULL, a new UText is allocated to contain the results for |
michael@0 | 525 | * that field. This new UText is not guaranteed to be mutable. |
michael@0 | 526 | * @param destCapacity The number of elements in the destination array. |
michael@0 | 527 | * If the number of fields found is less than destCapacity, the |
michael@0 | 528 | * extra strings in the destination array are not altered. |
michael@0 | 529 | * If the number of destination strings is less than the number |
michael@0 | 530 | * of fields, the trailing part of the input string, including any |
michael@0 | 531 | * field delimiters, is placed in the last destination string. |
michael@0 | 532 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 533 | * @return The number of destination strings used. |
michael@0 | 534 | * |
michael@0 | 535 | * @stable ICU 4.6 |
michael@0 | 536 | */ |
michael@0 | 537 | virtual int32_t split(UText *input, |
michael@0 | 538 | UText *dest[], |
michael@0 | 539 | int32_t destCapacity, |
michael@0 | 540 | UErrorCode &status) const; |
michael@0 | 541 | |
michael@0 | 542 | |
michael@0 | 543 | /** |
michael@0 | 544 | * ICU "poor man's RTTI", returns a UClassID for the actual class. |
michael@0 | 545 | * |
michael@0 | 546 | * @stable ICU 2.4 |
michael@0 | 547 | */ |
michael@0 | 548 | virtual UClassID getDynamicClassID() const; |
michael@0 | 549 | |
michael@0 | 550 | /** |
michael@0 | 551 | * ICU "poor man's RTTI", returns a UClassID for this class. |
michael@0 | 552 | * |
michael@0 | 553 | * @stable ICU 2.4 |
michael@0 | 554 | */ |
michael@0 | 555 | static UClassID U_EXPORT2 getStaticClassID(); |
michael@0 | 556 | |
michael@0 | 557 | private: |
michael@0 | 558 | // |
michael@0 | 559 | // Implementation Data |
michael@0 | 560 | // |
michael@0 | 561 | UText *fPattern; // The original pattern string. |
michael@0 | 562 | UnicodeString *fPatternString; // The original pattern UncodeString if relevant |
michael@0 | 563 | uint32_t fFlags; // The flags used when compiling the pattern. |
michael@0 | 564 | // |
michael@0 | 565 | UVector64 *fCompiledPat; // The compiled pattern p-code. |
michael@0 | 566 | UnicodeString fLiteralText; // Any literal string data from the pattern, |
michael@0 | 567 | // after un-escaping, for use during the match. |
michael@0 | 568 | |
michael@0 | 569 | UVector *fSets; // Any UnicodeSets referenced from the pattern. |
michael@0 | 570 | Regex8BitSet *fSets8; // (and fast sets for latin-1 range.) |
michael@0 | 571 | |
michael@0 | 572 | |
michael@0 | 573 | UErrorCode fDeferredStatus; // status if some prior error has left this |
michael@0 | 574 | // RegexPattern in an unusable state. |
michael@0 | 575 | |
michael@0 | 576 | int32_t fMinMatchLen; // Minimum Match Length. All matches will have length |
michael@0 | 577 | // >= this value. For some patterns, this calculated |
michael@0 | 578 | // value may be less than the true shortest |
michael@0 | 579 | // possible match. |
michael@0 | 580 | |
michael@0 | 581 | int32_t fFrameSize; // Size of a state stack frame in the |
michael@0 | 582 | // execution engine. |
michael@0 | 583 | |
michael@0 | 584 | int32_t fDataSize; // The size of the data needed by the pattern that |
michael@0 | 585 | // does not go on the state stack, but has just |
michael@0 | 586 | // a single copy per matcher. |
michael@0 | 587 | |
michael@0 | 588 | UVector32 *fGroupMap; // Map from capture group number to position of |
michael@0 | 589 | // the group's variables in the matcher stack frame. |
michael@0 | 590 | |
michael@0 | 591 | int32_t fMaxCaptureDigits; |
michael@0 | 592 | |
michael@0 | 593 | UnicodeSet **fStaticSets; // Ptr to static (shared) sets for predefined |
michael@0 | 594 | // regex character classes, e.g. Word. |
michael@0 | 595 | |
michael@0 | 596 | Regex8BitSet *fStaticSets8; // Ptr to the static (shared) latin-1 only |
michael@0 | 597 | // sets for predefined regex classes. |
michael@0 | 598 | |
michael@0 | 599 | int32_t fStartType; // Info on how a match must start. |
michael@0 | 600 | int32_t fInitialStringIdx; // |
michael@0 | 601 | int32_t fInitialStringLen; |
michael@0 | 602 | UnicodeSet *fInitialChars; |
michael@0 | 603 | UChar32 fInitialChar; |
michael@0 | 604 | Regex8BitSet *fInitialChars8; |
michael@0 | 605 | UBool fNeedsAltInput; |
michael@0 | 606 | |
michael@0 | 607 | friend class RegexCompile; |
michael@0 | 608 | friend class RegexMatcher; |
michael@0 | 609 | friend class RegexCImpl; |
michael@0 | 610 | |
michael@0 | 611 | // |
michael@0 | 612 | // Implementation Methods |
michael@0 | 613 | // |
michael@0 | 614 | void init(); // Common initialization, for use by constructors. |
michael@0 | 615 | void zap(); // Common cleanup |
michael@0 | 616 | #ifdef REGEX_DEBUG |
michael@0 | 617 | void dumpOp(int32_t index) const; |
michael@0 | 618 | friend void U_EXPORT2 RegexPatternDump(const RegexPattern *); |
michael@0 | 619 | #endif |
michael@0 | 620 | |
michael@0 | 621 | }; |
michael@0 | 622 | |
michael@0 | 623 | |
michael@0 | 624 | |
michael@0 | 625 | /** |
michael@0 | 626 | * class RegexMatcher bundles together a regular expression pattern and |
michael@0 | 627 | * input text to which the expression can be applied. It includes methods |
michael@0 | 628 | * for testing for matches, and for find and replace operations. |
michael@0 | 629 | * |
michael@0 | 630 | * <p>Class RegexMatcher is not intended to be subclassed.</p> |
michael@0 | 631 | * |
michael@0 | 632 | * @stable ICU 2.4 |
michael@0 | 633 | */ |
michael@0 | 634 | class U_I18N_API RegexMatcher: public UObject { |
michael@0 | 635 | public: |
michael@0 | 636 | |
michael@0 | 637 | /** |
michael@0 | 638 | * Construct a RegexMatcher for a regular expression. |
michael@0 | 639 | * This is a convenience method that avoids the need to explicitly create |
michael@0 | 640 | * a RegexPattern object. Note that if several RegexMatchers need to be |
michael@0 | 641 | * created for the same expression, it will be more efficient to |
michael@0 | 642 | * separately create and cache a RegexPattern object, and use |
michael@0 | 643 | * its matcher() method to create the RegexMatcher objects. |
michael@0 | 644 | * |
michael@0 | 645 | * @param regexp The Regular Expression to be compiled. |
michael@0 | 646 | * @param flags Regular expression options, such as case insensitive matching. |
michael@0 | 647 | * @see UREGEX_CASE_INSENSITIVE |
michael@0 | 648 | * @param status Any errors are reported by setting this UErrorCode variable. |
michael@0 | 649 | * @stable ICU 2.6 |
michael@0 | 650 | */ |
michael@0 | 651 | RegexMatcher(const UnicodeString ®exp, uint32_t flags, UErrorCode &status); |
michael@0 | 652 | |
michael@0 | 653 | /** |
michael@0 | 654 | * Construct a RegexMatcher for a regular expression. |
michael@0 | 655 | * This is a convenience method that avoids the need to explicitly create |
michael@0 | 656 | * a RegexPattern object. Note that if several RegexMatchers need to be |
michael@0 | 657 | * created for the same expression, it will be more efficient to |
michael@0 | 658 | * separately create and cache a RegexPattern object, and use |
michael@0 | 659 | * its matcher() method to create the RegexMatcher objects. |
michael@0 | 660 | * |
michael@0 | 661 | * @param regexp The regular expression to be compiled. |
michael@0 | 662 | * @param flags Regular expression options, such as case insensitive matching. |
michael@0 | 663 | * @see UREGEX_CASE_INSENSITIVE |
michael@0 | 664 | * @param status Any errors are reported by setting this UErrorCode variable. |
michael@0 | 665 | * |
michael@0 | 666 | * @stable ICU 4.6 |
michael@0 | 667 | */ |
michael@0 | 668 | RegexMatcher(UText *regexp, uint32_t flags, UErrorCode &status); |
michael@0 | 669 | |
michael@0 | 670 | /** |
michael@0 | 671 | * Construct a RegexMatcher for a regular expression. |
michael@0 | 672 | * This is a convenience method that avoids the need to explicitly create |
michael@0 | 673 | * a RegexPattern object. Note that if several RegexMatchers need to be |
michael@0 | 674 | * created for the same expression, it will be more efficient to |
michael@0 | 675 | * separately create and cache a RegexPattern object, and use |
michael@0 | 676 | * its matcher() method to create the RegexMatcher objects. |
michael@0 | 677 | * <p> |
michael@0 | 678 | * The matcher will retain a reference to the supplied input string, and all regexp |
michael@0 | 679 | * pattern matching operations happen directly on the original string. It is |
michael@0 | 680 | * critical that the string not be altered or deleted before use by the regular |
michael@0 | 681 | * expression operations is complete. |
michael@0 | 682 | * |
michael@0 | 683 | * @param regexp The Regular Expression to be compiled. |
michael@0 | 684 | * @param input The string to match. The matcher retains a reference to the |
michael@0 | 685 | * caller's string; mo copy is made. |
michael@0 | 686 | * @param flags Regular expression options, such as case insensitive matching. |
michael@0 | 687 | * @see UREGEX_CASE_INSENSITIVE |
michael@0 | 688 | * @param status Any errors are reported by setting this UErrorCode variable. |
michael@0 | 689 | * @stable ICU 2.6 |
michael@0 | 690 | */ |
michael@0 | 691 | RegexMatcher(const UnicodeString ®exp, const UnicodeString &input, |
michael@0 | 692 | uint32_t flags, UErrorCode &status); |
michael@0 | 693 | |
michael@0 | 694 | /** |
michael@0 | 695 | * Construct a RegexMatcher for a regular expression. |
michael@0 | 696 | * This is a convenience method that avoids the need to explicitly create |
michael@0 | 697 | * a RegexPattern object. Note that if several RegexMatchers need to be |
michael@0 | 698 | * created for the same expression, it will be more efficient to |
michael@0 | 699 | * separately create and cache a RegexPattern object, and use |
michael@0 | 700 | * its matcher() method to create the RegexMatcher objects. |
michael@0 | 701 | * <p> |
michael@0 | 702 | * The matcher will make a shallow clone of the supplied input text, and all regexp |
michael@0 | 703 | * pattern matching operations happen on this clone. While read-only operations on |
michael@0 | 704 | * the supplied text are permitted, it is critical that the underlying string not be |
michael@0 | 705 | * altered or deleted before use by the regular expression operations is complete. |
michael@0 | 706 | * |
michael@0 | 707 | * @param regexp The Regular Expression to be compiled. |
michael@0 | 708 | * @param input The string to match. The matcher retains a shallow clone of the text. |
michael@0 | 709 | * @param flags Regular expression options, such as case insensitive matching. |
michael@0 | 710 | * @see UREGEX_CASE_INSENSITIVE |
michael@0 | 711 | * @param status Any errors are reported by setting this UErrorCode variable. |
michael@0 | 712 | * |
michael@0 | 713 | * @stable ICU 4.6 |
michael@0 | 714 | */ |
michael@0 | 715 | RegexMatcher(UText *regexp, UText *input, |
michael@0 | 716 | uint32_t flags, UErrorCode &status); |
michael@0 | 717 | |
michael@0 | 718 | private: |
michael@0 | 719 | /** |
michael@0 | 720 | * Cause a compilation error if an application accidentally attempts to |
michael@0 | 721 | * create a matcher with a (UChar *) string as input rather than |
michael@0 | 722 | * a UnicodeString. Avoids a dangling reference to a temporary string. |
michael@0 | 723 | * <p> |
michael@0 | 724 | * To efficiently work with UChar *strings, wrap the data in a UnicodeString |
michael@0 | 725 | * using one of the aliasing constructors, such as |
michael@0 | 726 | * <code>UnicodeString(UBool isTerminated, const UChar *text, int32_t textLength);</code> |
michael@0 | 727 | * or in a UText, using |
michael@0 | 728 | * <code>utext_openUChars(UText *ut, const UChar *text, int64_t textLength, UErrorCode *status);</code> |
michael@0 | 729 | * |
michael@0 | 730 | */ |
michael@0 | 731 | RegexMatcher(const UnicodeString ®exp, const UChar *input, |
michael@0 | 732 | uint32_t flags, UErrorCode &status); |
michael@0 | 733 | public: |
michael@0 | 734 | |
michael@0 | 735 | |
michael@0 | 736 | /** |
michael@0 | 737 | * Destructor. |
michael@0 | 738 | * |
michael@0 | 739 | * @stable ICU 2.4 |
michael@0 | 740 | */ |
michael@0 | 741 | virtual ~RegexMatcher(); |
michael@0 | 742 | |
michael@0 | 743 | |
michael@0 | 744 | /** |
michael@0 | 745 | * Attempts to match the entire input region against the pattern. |
michael@0 | 746 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 747 | * @return TRUE if there is a match |
michael@0 | 748 | * @stable ICU 2.4 |
michael@0 | 749 | */ |
michael@0 | 750 | virtual UBool matches(UErrorCode &status); |
michael@0 | 751 | |
michael@0 | 752 | |
michael@0 | 753 | /** |
michael@0 | 754 | * Resets the matcher, then attempts to match the input beginning |
michael@0 | 755 | * at the specified startIndex, and extending to the end of the input. |
michael@0 | 756 | * The input region is reset to include the entire input string. |
michael@0 | 757 | * A successful match must extend to the end of the input. |
michael@0 | 758 | * @param startIndex The input string (native) index at which to begin matching. |
michael@0 | 759 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 760 | * @return TRUE if there is a match |
michael@0 | 761 | * @stable ICU 2.8 |
michael@0 | 762 | */ |
michael@0 | 763 | virtual UBool matches(int64_t startIndex, UErrorCode &status); |
michael@0 | 764 | |
michael@0 | 765 | |
michael@0 | 766 | /** |
michael@0 | 767 | * Attempts to match the input string, starting from the beginning of the region, |
michael@0 | 768 | * against the pattern. Like the matches() method, this function |
michael@0 | 769 | * always starts at the beginning of the input region; |
michael@0 | 770 | * unlike that function, it does not require that the entire region be matched. |
michael@0 | 771 | * |
michael@0 | 772 | * <p>If the match succeeds then more information can be obtained via the <code>start()</code>, |
michael@0 | 773 | * <code>end()</code>, and <code>group()</code> functions.</p> |
michael@0 | 774 | * |
michael@0 | 775 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 776 | * @return TRUE if there is a match at the start of the input string. |
michael@0 | 777 | * @stable ICU 2.4 |
michael@0 | 778 | */ |
michael@0 | 779 | virtual UBool lookingAt(UErrorCode &status); |
michael@0 | 780 | |
michael@0 | 781 | |
michael@0 | 782 | /** |
michael@0 | 783 | * Attempts to match the input string, starting from the specified index, against the pattern. |
michael@0 | 784 | * The match may be of any length, and is not required to extend to the end |
michael@0 | 785 | * of the input string. Contrast with match(). |
michael@0 | 786 | * |
michael@0 | 787 | * <p>If the match succeeds then more information can be obtained via the <code>start()</code>, |
michael@0 | 788 | * <code>end()</code>, and <code>group()</code> functions.</p> |
michael@0 | 789 | * |
michael@0 | 790 | * @param startIndex The input string (native) index at which to begin matching. |
michael@0 | 791 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 792 | * @return TRUE if there is a match. |
michael@0 | 793 | * @stable ICU 2.8 |
michael@0 | 794 | */ |
michael@0 | 795 | virtual UBool lookingAt(int64_t startIndex, UErrorCode &status); |
michael@0 | 796 | |
michael@0 | 797 | |
michael@0 | 798 | /** |
michael@0 | 799 | * Find the next pattern match in the input string. |
michael@0 | 800 | * The find begins searching the input at the location following the end of |
michael@0 | 801 | * the previous match, or at the start of the string if there is no previous match. |
michael@0 | 802 | * If a match is found, <code>start(), end()</code> and <code>group()</code> |
michael@0 | 803 | * will provide more information regarding the match. |
michael@0 | 804 | * <p>Note that if the input string is changed by the application, |
michael@0 | 805 | * use find(startPos, status) instead of find(), because the saved starting |
michael@0 | 806 | * position may not be valid with the altered input string.</p> |
michael@0 | 807 | * @return TRUE if a match is found. |
michael@0 | 808 | * @stable ICU 2.4 |
michael@0 | 809 | */ |
michael@0 | 810 | virtual UBool find(); |
michael@0 | 811 | |
michael@0 | 812 | |
michael@0 | 813 | /** |
michael@0 | 814 | * Resets this RegexMatcher and then attempts to find the next substring of the |
michael@0 | 815 | * input string that matches the pattern, starting at the specified index. |
michael@0 | 816 | * |
michael@0 | 817 | * @param start The (native) index in the input string to begin the search. |
michael@0 | 818 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 819 | * @return TRUE if a match is found. |
michael@0 | 820 | * @stable ICU 2.4 |
michael@0 | 821 | */ |
michael@0 | 822 | virtual UBool find(int64_t start, UErrorCode &status); |
michael@0 | 823 | |
michael@0 | 824 | |
michael@0 | 825 | /** |
michael@0 | 826 | * Returns a string containing the text matched by the previous match. |
michael@0 | 827 | * If the pattern can match an empty string, an empty string may be returned. |
michael@0 | 828 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 829 | * Possible errors are U_REGEX_INVALID_STATE if no match |
michael@0 | 830 | * has been attempted or the last match failed. |
michael@0 | 831 | * @return a string containing the matched input text. |
michael@0 | 832 | * @stable ICU 2.4 |
michael@0 | 833 | */ |
michael@0 | 834 | virtual UnicodeString group(UErrorCode &status) const; |
michael@0 | 835 | |
michael@0 | 836 | |
michael@0 | 837 | /** |
michael@0 | 838 | * Returns a string containing the text captured by the given group |
michael@0 | 839 | * during the previous match operation. Group(0) is the entire match. |
michael@0 | 840 | * |
michael@0 | 841 | * @param groupNum the capture group number |
michael@0 | 842 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 843 | * Possible errors are U_REGEX_INVALID_STATE if no match |
michael@0 | 844 | * has been attempted or the last match failed and |
michael@0 | 845 | * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number. |
michael@0 | 846 | * @return the captured text |
michael@0 | 847 | * @stable ICU 2.4 |
michael@0 | 848 | */ |
michael@0 | 849 | virtual UnicodeString group(int32_t groupNum, UErrorCode &status) const; |
michael@0 | 850 | |
michael@0 | 851 | |
michael@0 | 852 | /** |
michael@0 | 853 | * Returns the number of capturing groups in this matcher's pattern. |
michael@0 | 854 | * @return the number of capture groups |
michael@0 | 855 | * @stable ICU 2.4 |
michael@0 | 856 | */ |
michael@0 | 857 | virtual int32_t groupCount() const; |
michael@0 | 858 | |
michael@0 | 859 | |
michael@0 | 860 | /** |
michael@0 | 861 | * Returns a shallow clone of the entire live input string with the UText current native index |
michael@0 | 862 | * set to the beginning of the requested group. |
michael@0 | 863 | * |
michael@0 | 864 | * @param dest The UText into which the input should be cloned, or NULL to create a new UText |
michael@0 | 865 | * @param group_len A reference to receive the length of the desired capture group |
michael@0 | 866 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 867 | * Possible errors are U_REGEX_INVALID_STATE if no match |
michael@0 | 868 | * has been attempted or the last match failed and |
michael@0 | 869 | * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number. |
michael@0 | 870 | * @return dest if non-NULL, a shallow copy of the input text otherwise |
michael@0 | 871 | * |
michael@0 | 872 | * @stable ICU 4.6 |
michael@0 | 873 | */ |
michael@0 | 874 | virtual UText *group(UText *dest, int64_t &group_len, UErrorCode &status) const; |
michael@0 | 875 | |
michael@0 | 876 | /** |
michael@0 | 877 | * Returns a shallow clone of the entire live input string with the UText current native index |
michael@0 | 878 | * set to the beginning of the requested group. |
michael@0 | 879 | * |
michael@0 | 880 | * @param groupNum The capture group number. |
michael@0 | 881 | * @param dest The UText into which the input should be cloned, or NULL to create a new UText. |
michael@0 | 882 | * @param group_len A reference to receive the length of the desired capture group |
michael@0 | 883 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 884 | * Possible errors are U_REGEX_INVALID_STATE if no match |
michael@0 | 885 | * has been attempted or the last match failed and |
michael@0 | 886 | * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number. |
michael@0 | 887 | * @return dest if non-NULL, a shallow copy of the input text otherwise |
michael@0 | 888 | * |
michael@0 | 889 | * @stable ICU 4.6 |
michael@0 | 890 | */ |
michael@0 | 891 | virtual UText *group(int32_t groupNum, UText *dest, int64_t &group_len, UErrorCode &status) const; |
michael@0 | 892 | |
michael@0 | 893 | /** |
michael@0 | 894 | * Returns a string containing the text captured by the given group |
michael@0 | 895 | * during the previous match operation. Group(0) is the entire match. |
michael@0 | 896 | * |
michael@0 | 897 | * @param groupNum the capture group number |
michael@0 | 898 | * @param dest A mutable UText in which the matching text is placed. |
michael@0 | 899 | * If NULL, a new UText will be created (which may not be mutable). |
michael@0 | 900 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 901 | * Possible errors are U_REGEX_INVALID_STATE if no match |
michael@0 | 902 | * has been attempted or the last match failed. |
michael@0 | 903 | * @return A string containing the matched input text. If a pre-allocated UText |
michael@0 | 904 | * was provided, it will always be used and returned. |
michael@0 | 905 | * |
michael@0 | 906 | * @internal ICU 4.4 technology preview |
michael@0 | 907 | */ |
michael@0 | 908 | virtual UText *group(int32_t groupNum, UText *dest, UErrorCode &status) const; |
michael@0 | 909 | |
michael@0 | 910 | |
michael@0 | 911 | /** |
michael@0 | 912 | * Returns the index in the input string of the start of the text matched |
michael@0 | 913 | * during the previous match operation. |
michael@0 | 914 | * @param status a reference to a UErrorCode to receive any errors. |
michael@0 | 915 | * @return The (native) position in the input string of the start of the last match. |
michael@0 | 916 | * @stable ICU 2.4 |
michael@0 | 917 | */ |
michael@0 | 918 | virtual int32_t start(UErrorCode &status) const; |
michael@0 | 919 | |
michael@0 | 920 | /** |
michael@0 | 921 | * Returns the index in the input string of the start of the text matched |
michael@0 | 922 | * during the previous match operation. |
michael@0 | 923 | * @param status a reference to a UErrorCode to receive any errors. |
michael@0 | 924 | * @return The (native) position in the input string of the start of the last match. |
michael@0 | 925 | * @stable ICU 4.6 |
michael@0 | 926 | */ |
michael@0 | 927 | virtual int64_t start64(UErrorCode &status) const; |
michael@0 | 928 | |
michael@0 | 929 | |
michael@0 | 930 | /** |
michael@0 | 931 | * Returns the index in the input string of the start of the text matched by the |
michael@0 | 932 | * specified capture group during the previous match operation. Return -1 if |
michael@0 | 933 | * the capture group exists in the pattern, but was not part of the last match. |
michael@0 | 934 | * |
michael@0 | 935 | * @param group the capture group number |
michael@0 | 936 | * @param status A reference to a UErrorCode to receive any errors. Possible |
michael@0 | 937 | * errors are U_REGEX_INVALID_STATE if no match has been |
michael@0 | 938 | * attempted or the last match failed, and |
michael@0 | 939 | * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number |
michael@0 | 940 | * @return the (native) start position of substring matched by the specified group. |
michael@0 | 941 | * @stable ICU 2.4 |
michael@0 | 942 | */ |
michael@0 | 943 | virtual int32_t start(int32_t group, UErrorCode &status) const; |
michael@0 | 944 | |
michael@0 | 945 | /** |
michael@0 | 946 | * Returns the index in the input string of the start of the text matched by the |
michael@0 | 947 | * specified capture group during the previous match operation. Return -1 if |
michael@0 | 948 | * the capture group exists in the pattern, but was not part of the last match. |
michael@0 | 949 | * |
michael@0 | 950 | * @param group the capture group number. |
michael@0 | 951 | * @param status A reference to a UErrorCode to receive any errors. Possible |
michael@0 | 952 | * errors are U_REGEX_INVALID_STATE if no match has been |
michael@0 | 953 | * attempted or the last match failed, and |
michael@0 | 954 | * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number. |
michael@0 | 955 | * @return the (native) start position of substring matched by the specified group. |
michael@0 | 956 | * @stable ICU 4.6 |
michael@0 | 957 | */ |
michael@0 | 958 | virtual int64_t start64(int32_t group, UErrorCode &status) const; |
michael@0 | 959 | |
michael@0 | 960 | |
michael@0 | 961 | /** |
michael@0 | 962 | * Returns the index in the input string of the first character following the |
michael@0 | 963 | * text matched during the previous match operation. |
michael@0 | 964 | * |
michael@0 | 965 | * @param status A reference to a UErrorCode to receive any errors. Possible |
michael@0 | 966 | * errors are U_REGEX_INVALID_STATE if no match has been |
michael@0 | 967 | * attempted or the last match failed. |
michael@0 | 968 | * @return the index of the last character matched, plus one. |
michael@0 | 969 | * The index value returned is a native index, corresponding to |
michael@0 | 970 | * code units for the underlying encoding type, for example, |
michael@0 | 971 | * a byte index for UTF-8. |
michael@0 | 972 | * @stable ICU 2.4 |
michael@0 | 973 | */ |
michael@0 | 974 | virtual int32_t end(UErrorCode &status) const; |
michael@0 | 975 | |
michael@0 | 976 | /** |
michael@0 | 977 | * Returns the index in the input string of the first character following the |
michael@0 | 978 | * text matched during the previous match operation. |
michael@0 | 979 | * |
michael@0 | 980 | * @param status A reference to a UErrorCode to receive any errors. Possible |
michael@0 | 981 | * errors are U_REGEX_INVALID_STATE if no match has been |
michael@0 | 982 | * attempted or the last match failed. |
michael@0 | 983 | * @return the index of the last character matched, plus one. |
michael@0 | 984 | * The index value returned is a native index, corresponding to |
michael@0 | 985 | * code units for the underlying encoding type, for example, |
michael@0 | 986 | * a byte index for UTF-8. |
michael@0 | 987 | * @stable ICU 4.6 |
michael@0 | 988 | */ |
michael@0 | 989 | virtual int64_t end64(UErrorCode &status) const; |
michael@0 | 990 | |
michael@0 | 991 | |
michael@0 | 992 | /** |
michael@0 | 993 | * Returns the index in the input string of the character following the |
michael@0 | 994 | * text matched by the specified capture group during the previous match operation. |
michael@0 | 995 | * |
michael@0 | 996 | * @param group the capture group number |
michael@0 | 997 | * @param status A reference to a UErrorCode to receive any errors. Possible |
michael@0 | 998 | * errors are U_REGEX_INVALID_STATE if no match has been |
michael@0 | 999 | * attempted or the last match failed and |
michael@0 | 1000 | * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number |
michael@0 | 1001 | * @return the index of the first character following the text |
michael@0 | 1002 | * captured by the specified group during the previous match operation. |
michael@0 | 1003 | * Return -1 if the capture group exists in the pattern but was not part of the match. |
michael@0 | 1004 | * The index value returned is a native index, corresponding to |
michael@0 | 1005 | * code units for the underlying encoding type, for example, |
michael@0 | 1006 | * a byte index for UTF8. |
michael@0 | 1007 | * @stable ICU 2.4 |
michael@0 | 1008 | */ |
michael@0 | 1009 | virtual int32_t end(int32_t group, UErrorCode &status) const; |
michael@0 | 1010 | |
michael@0 | 1011 | /** |
michael@0 | 1012 | * Returns the index in the input string of the character following the |
michael@0 | 1013 | * text matched by the specified capture group during the previous match operation. |
michael@0 | 1014 | * |
michael@0 | 1015 | * @param group the capture group number |
michael@0 | 1016 | * @param status A reference to a UErrorCode to receive any errors. Possible |
michael@0 | 1017 | * errors are U_REGEX_INVALID_STATE if no match has been |
michael@0 | 1018 | * attempted or the last match failed and |
michael@0 | 1019 | * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number |
michael@0 | 1020 | * @return the index of the first character following the text |
michael@0 | 1021 | * captured by the specified group during the previous match operation. |
michael@0 | 1022 | * Return -1 if the capture group exists in the pattern but was not part of the match. |
michael@0 | 1023 | * The index value returned is a native index, corresponding to |
michael@0 | 1024 | * code units for the underlying encoding type, for example, |
michael@0 | 1025 | * a byte index for UTF8. |
michael@0 | 1026 | * @stable ICU 4.6 |
michael@0 | 1027 | */ |
michael@0 | 1028 | virtual int64_t end64(int32_t group, UErrorCode &status) const; |
michael@0 | 1029 | |
michael@0 | 1030 | |
michael@0 | 1031 | /** |
michael@0 | 1032 | * Resets this matcher. The effect is to remove any memory of previous matches, |
michael@0 | 1033 | * and to cause subsequent find() operations to begin at the beginning of |
michael@0 | 1034 | * the input string. |
michael@0 | 1035 | * |
michael@0 | 1036 | * @return this RegexMatcher. |
michael@0 | 1037 | * @stable ICU 2.4 |
michael@0 | 1038 | */ |
michael@0 | 1039 | virtual RegexMatcher &reset(); |
michael@0 | 1040 | |
michael@0 | 1041 | |
michael@0 | 1042 | /** |
michael@0 | 1043 | * Resets this matcher, and set the current input position. |
michael@0 | 1044 | * The effect is to remove any memory of previous matches, |
michael@0 | 1045 | * and to cause subsequent find() operations to begin at |
michael@0 | 1046 | * the specified (native) position in the input string. |
michael@0 | 1047 | * <p> |
michael@0 | 1048 | * The matcher's region is reset to its default, which is the entire |
michael@0 | 1049 | * input string. |
michael@0 | 1050 | * <p> |
michael@0 | 1051 | * An alternative to this function is to set a match region |
michael@0 | 1052 | * beginning at the desired index. |
michael@0 | 1053 | * |
michael@0 | 1054 | * @return this RegexMatcher. |
michael@0 | 1055 | * @stable ICU 2.8 |
michael@0 | 1056 | */ |
michael@0 | 1057 | virtual RegexMatcher &reset(int64_t index, UErrorCode &status); |
michael@0 | 1058 | |
michael@0 | 1059 | |
michael@0 | 1060 | /** |
michael@0 | 1061 | * Resets this matcher with a new input string. This allows instances of RegexMatcher |
michael@0 | 1062 | * to be reused, which is more efficient than creating a new RegexMatcher for |
michael@0 | 1063 | * each input string to be processed. |
michael@0 | 1064 | * @param input The new string on which subsequent pattern matches will operate. |
michael@0 | 1065 | * The matcher retains a reference to the callers string, and operates |
michael@0 | 1066 | * directly on that. Ownership of the string remains with the caller. |
michael@0 | 1067 | * Because no copy of the string is made, it is essential that the |
michael@0 | 1068 | * caller not delete the string until after regexp operations on it |
michael@0 | 1069 | * are done. |
michael@0 | 1070 | * Note that while a reset on the matcher with an input string that is then |
michael@0 | 1071 | * modified across/during matcher operations may be supported currently for UnicodeString, |
michael@0 | 1072 | * this was not originally intended behavior, and support for this is not guaranteed |
michael@0 | 1073 | * in upcoming versions of ICU. |
michael@0 | 1074 | * @return this RegexMatcher. |
michael@0 | 1075 | * @stable ICU 2.4 |
michael@0 | 1076 | */ |
michael@0 | 1077 | virtual RegexMatcher &reset(const UnicodeString &input); |
michael@0 | 1078 | |
michael@0 | 1079 | |
michael@0 | 1080 | /** |
michael@0 | 1081 | * Resets this matcher with a new input string. This allows instances of RegexMatcher |
michael@0 | 1082 | * to be reused, which is more efficient than creating a new RegexMatcher for |
michael@0 | 1083 | * each input string to be processed. |
michael@0 | 1084 | * @param input The new string on which subsequent pattern matches will operate. |
michael@0 | 1085 | * The matcher makes a shallow clone of the given text; ownership of the |
michael@0 | 1086 | * original string remains with the caller. Because no deep copy of the |
michael@0 | 1087 | * text is made, it is essential that the caller not modify the string |
michael@0 | 1088 | * until after regexp operations on it are done. |
michael@0 | 1089 | * @return this RegexMatcher. |
michael@0 | 1090 | * |
michael@0 | 1091 | * @stable ICU 4.6 |
michael@0 | 1092 | */ |
michael@0 | 1093 | virtual RegexMatcher &reset(UText *input); |
michael@0 | 1094 | |
michael@0 | 1095 | |
michael@0 | 1096 | /** |
michael@0 | 1097 | * Set the subject text string upon which the regular expression is looking for matches |
michael@0 | 1098 | * without changing any other aspect of the matching state. |
michael@0 | 1099 | * The new and previous text strings must have the same content. |
michael@0 | 1100 | * |
michael@0 | 1101 | * This function is intended for use in environments where ICU is operating on |
michael@0 | 1102 | * strings that may move around in memory. It provides a mechanism for notifying |
michael@0 | 1103 | * ICU that the string has been relocated, and providing a new UText to access the |
michael@0 | 1104 | * string in its new position. |
michael@0 | 1105 | * |
michael@0 | 1106 | * Note that the regular expression implementation never copies the underlying text |
michael@0 | 1107 | * of a string being matched, but always operates directly on the original text |
michael@0 | 1108 | * provided by the user. Refreshing simply drops the references to the old text |
michael@0 | 1109 | * and replaces them with references to the new. |
michael@0 | 1110 | * |
michael@0 | 1111 | * Caution: this function is normally used only by very specialized, |
michael@0 | 1112 | * system-level code. One example use case is with garbage collection that moves |
michael@0 | 1113 | * the text in memory. |
michael@0 | 1114 | * |
michael@0 | 1115 | * @param input The new (moved) text string. |
michael@0 | 1116 | * @param status Receives errors detected by this function. |
michael@0 | 1117 | * |
michael@0 | 1118 | * @stable ICU 4.8 |
michael@0 | 1119 | */ |
michael@0 | 1120 | virtual RegexMatcher &refreshInputText(UText *input, UErrorCode &status); |
michael@0 | 1121 | |
michael@0 | 1122 | private: |
michael@0 | 1123 | /** |
michael@0 | 1124 | * Cause a compilation error if an application accidentally attempts to |
michael@0 | 1125 | * reset a matcher with a (UChar *) string as input rather than |
michael@0 | 1126 | * a UnicodeString. Avoids a dangling reference to a temporary string. |
michael@0 | 1127 | * <p> |
michael@0 | 1128 | * To efficiently work with UChar *strings, wrap the data in a UnicodeString |
michael@0 | 1129 | * using one of the aliasing constructors, such as |
michael@0 | 1130 | * <code>UnicodeString(UBool isTerminated, const UChar *text, int32_t textLength);</code> |
michael@0 | 1131 | * or in a UText, using |
michael@0 | 1132 | * <code>utext_openUChars(UText *ut, const UChar *text, int64_t textLength, UErrorCode *status);</code> |
michael@0 | 1133 | * |
michael@0 | 1134 | */ |
michael@0 | 1135 | RegexMatcher &reset(const UChar *input); |
michael@0 | 1136 | public: |
michael@0 | 1137 | |
michael@0 | 1138 | /** |
michael@0 | 1139 | * Returns the input string being matched. Ownership of the string belongs to |
michael@0 | 1140 | * the matcher; it should not be altered or deleted. This method will work even if the input |
michael@0 | 1141 | * was originally supplied as a UText. |
michael@0 | 1142 | * @return the input string |
michael@0 | 1143 | * @stable ICU 2.4 |
michael@0 | 1144 | */ |
michael@0 | 1145 | virtual const UnicodeString &input() const; |
michael@0 | 1146 | |
michael@0 | 1147 | /** |
michael@0 | 1148 | * Returns the input string being matched. This is the live input text; it should not be |
michael@0 | 1149 | * altered or deleted. This method will work even if the input was originally supplied as |
michael@0 | 1150 | * a UnicodeString. |
michael@0 | 1151 | * @return the input text |
michael@0 | 1152 | * |
michael@0 | 1153 | * @stable ICU 4.6 |
michael@0 | 1154 | */ |
michael@0 | 1155 | virtual UText *inputText() const; |
michael@0 | 1156 | |
michael@0 | 1157 | /** |
michael@0 | 1158 | * Returns the input string being matched, either by copying it into the provided |
michael@0 | 1159 | * UText parameter or by returning a shallow clone of the live input. Note that copying |
michael@0 | 1160 | * the entire input may cause significant performance and memory issues. |
michael@0 | 1161 | * @param dest The UText into which the input should be copied, or NULL to create a new UText |
michael@0 | 1162 | * @param status error code |
michael@0 | 1163 | * @return dest if non-NULL, a shallow copy of the input text otherwise |
michael@0 | 1164 | * |
michael@0 | 1165 | * @stable ICU 4.6 |
michael@0 | 1166 | */ |
michael@0 | 1167 | virtual UText *getInput(UText *dest, UErrorCode &status) const; |
michael@0 | 1168 | |
michael@0 | 1169 | |
michael@0 | 1170 | /** Sets the limits of this matcher's region. |
michael@0 | 1171 | * The region is the part of the input string that will be searched to find a match. |
michael@0 | 1172 | * Invoking this method resets the matcher, and then sets the region to start |
michael@0 | 1173 | * at the index specified by the start parameter and end at the index specified |
michael@0 | 1174 | * by the end parameter. |
michael@0 | 1175 | * |
michael@0 | 1176 | * Depending on the transparency and anchoring being used (see useTransparentBounds |
michael@0 | 1177 | * and useAnchoringBounds), certain constructs such as anchors may behave differently |
michael@0 | 1178 | * at or around the boundaries of the region |
michael@0 | 1179 | * |
michael@0 | 1180 | * The function will fail if start is greater than limit, or if either index |
michael@0 | 1181 | * is less than zero or greater than the length of the string being matched. |
michael@0 | 1182 | * |
michael@0 | 1183 | * @param start The (native) index to begin searches at. |
michael@0 | 1184 | * @param limit The index to end searches at (exclusive). |
michael@0 | 1185 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 1186 | * @stable ICU 4.0 |
michael@0 | 1187 | */ |
michael@0 | 1188 | virtual RegexMatcher ®ion(int64_t start, int64_t limit, UErrorCode &status); |
michael@0 | 1189 | |
michael@0 | 1190 | /** |
michael@0 | 1191 | * Identical to region(start, limit, status) but also allows a start position without |
michael@0 | 1192 | * resetting the region state. |
michael@0 | 1193 | * @param regionStart The region start |
michael@0 | 1194 | * @param regionLimit the limit of the region |
michael@0 | 1195 | * @param startIndex The (native) index within the region bounds at which to begin searches. |
michael@0 | 1196 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 1197 | * If startIndex is not within the specified region bounds, |
michael@0 | 1198 | * U_INDEX_OUTOFBOUNDS_ERROR is returned. |
michael@0 | 1199 | * @stable ICU 4.6 |
michael@0 | 1200 | */ |
michael@0 | 1201 | virtual RegexMatcher ®ion(int64_t regionStart, int64_t regionLimit, int64_t startIndex, UErrorCode &status); |
michael@0 | 1202 | |
michael@0 | 1203 | /** |
michael@0 | 1204 | * Reports the start index of this matcher's region. The searches this matcher |
michael@0 | 1205 | * conducts are limited to finding matches within regionStart (inclusive) and |
michael@0 | 1206 | * regionEnd (exclusive). |
michael@0 | 1207 | * |
michael@0 | 1208 | * @return The starting (native) index of this matcher's region. |
michael@0 | 1209 | * @stable ICU 4.0 |
michael@0 | 1210 | */ |
michael@0 | 1211 | virtual int32_t regionStart() const; |
michael@0 | 1212 | |
michael@0 | 1213 | /** |
michael@0 | 1214 | * Reports the start index of this matcher's region. The searches this matcher |
michael@0 | 1215 | * conducts are limited to finding matches within regionStart (inclusive) and |
michael@0 | 1216 | * regionEnd (exclusive). |
michael@0 | 1217 | * |
michael@0 | 1218 | * @return The starting (native) index of this matcher's region. |
michael@0 | 1219 | * @stable ICU 4.6 |
michael@0 | 1220 | */ |
michael@0 | 1221 | virtual int64_t regionStart64() const; |
michael@0 | 1222 | |
michael@0 | 1223 | |
michael@0 | 1224 | /** |
michael@0 | 1225 | * Reports the end (limit) index (exclusive) of this matcher's region. The searches |
michael@0 | 1226 | * this matcher conducts are limited to finding matches within regionStart |
michael@0 | 1227 | * (inclusive) and regionEnd (exclusive). |
michael@0 | 1228 | * |
michael@0 | 1229 | * @return The ending point (native) of this matcher's region. |
michael@0 | 1230 | * @stable ICU 4.0 |
michael@0 | 1231 | */ |
michael@0 | 1232 | virtual int32_t regionEnd() const; |
michael@0 | 1233 | |
michael@0 | 1234 | /** |
michael@0 | 1235 | * Reports the end (limit) index (exclusive) of this matcher's region. The searches |
michael@0 | 1236 | * this matcher conducts are limited to finding matches within regionStart |
michael@0 | 1237 | * (inclusive) and regionEnd (exclusive). |
michael@0 | 1238 | * |
michael@0 | 1239 | * @return The ending point (native) of this matcher's region. |
michael@0 | 1240 | * @stable ICU 4.6 |
michael@0 | 1241 | */ |
michael@0 | 1242 | virtual int64_t regionEnd64() const; |
michael@0 | 1243 | |
michael@0 | 1244 | /** |
michael@0 | 1245 | * Queries the transparency of region bounds for this matcher. |
michael@0 | 1246 | * See useTransparentBounds for a description of transparent and opaque bounds. |
michael@0 | 1247 | * By default, a matcher uses opaque region boundaries. |
michael@0 | 1248 | * |
michael@0 | 1249 | * @return TRUE if this matcher is using opaque bounds, false if it is not. |
michael@0 | 1250 | * @stable ICU 4.0 |
michael@0 | 1251 | */ |
michael@0 | 1252 | virtual UBool hasTransparentBounds() const; |
michael@0 | 1253 | |
michael@0 | 1254 | /** |
michael@0 | 1255 | * Sets the transparency of region bounds for this matcher. |
michael@0 | 1256 | * Invoking this function with an argument of true will set this matcher to use transparent bounds. |
michael@0 | 1257 | * If the boolean argument is false, then opaque bounds will be used. |
michael@0 | 1258 | * |
michael@0 | 1259 | * Using transparent bounds, the boundaries of this matcher's region are transparent |
michael@0 | 1260 | * to lookahead, lookbehind, and boundary matching constructs. Those constructs can |
michael@0 | 1261 | * see text beyond the boundaries of the region while checking for a match. |
michael@0 | 1262 | * |
michael@0 | 1263 | * With opaque bounds, no text outside of the matcher's region is visible to lookahead, |
michael@0 | 1264 | * lookbehind, and boundary matching constructs. |
michael@0 | 1265 | * |
michael@0 | 1266 | * By default, a matcher uses opaque bounds. |
michael@0 | 1267 | * |
michael@0 | 1268 | * @param b TRUE for transparent bounds; FALSE for opaque bounds |
michael@0 | 1269 | * @return This Matcher; |
michael@0 | 1270 | * @stable ICU 4.0 |
michael@0 | 1271 | **/ |
michael@0 | 1272 | virtual RegexMatcher &useTransparentBounds(UBool b); |
michael@0 | 1273 | |
michael@0 | 1274 | |
michael@0 | 1275 | /** |
michael@0 | 1276 | * Return true if this matcher is using anchoring bounds. |
michael@0 | 1277 | * By default, matchers use anchoring region bounds. |
michael@0 | 1278 | * |
michael@0 | 1279 | * @return TRUE if this matcher is using anchoring bounds. |
michael@0 | 1280 | * @stable ICU 4.0 |
michael@0 | 1281 | */ |
michael@0 | 1282 | virtual UBool hasAnchoringBounds() const; |
michael@0 | 1283 | |
michael@0 | 1284 | |
michael@0 | 1285 | /** |
michael@0 | 1286 | * Set whether this matcher is using Anchoring Bounds for its region. |
michael@0 | 1287 | * With anchoring bounds, pattern anchors such as ^ and $ will match at the start |
michael@0 | 1288 | * and end of the region. Without Anchoring Bounds, anchors will only match at |
michael@0 | 1289 | * the positions they would in the complete text. |
michael@0 | 1290 | * |
michael@0 | 1291 | * Anchoring Bounds are the default for regions. |
michael@0 | 1292 | * |
michael@0 | 1293 | * @param b TRUE if to enable anchoring bounds; FALSE to disable them. |
michael@0 | 1294 | * @return This Matcher |
michael@0 | 1295 | * @stable ICU 4.0 |
michael@0 | 1296 | */ |
michael@0 | 1297 | virtual RegexMatcher &useAnchoringBounds(UBool b); |
michael@0 | 1298 | |
michael@0 | 1299 | |
michael@0 | 1300 | /** |
michael@0 | 1301 | * Return TRUE if the most recent matching operation attempted to access |
michael@0 | 1302 | * additional input beyond the available input text. |
michael@0 | 1303 | * In this case, additional input text could change the results of the match. |
michael@0 | 1304 | * |
michael@0 | 1305 | * hitEnd() is defined for both successful and unsuccessful matches. |
michael@0 | 1306 | * In either case hitEnd() will return TRUE if if the end of the text was |
michael@0 | 1307 | * reached at any point during the matching process. |
michael@0 | 1308 | * |
michael@0 | 1309 | * @return TRUE if the most recent match hit the end of input |
michael@0 | 1310 | * @stable ICU 4.0 |
michael@0 | 1311 | */ |
michael@0 | 1312 | virtual UBool hitEnd() const; |
michael@0 | 1313 | |
michael@0 | 1314 | /** |
michael@0 | 1315 | * Return TRUE the most recent match succeeded and additional input could cause |
michael@0 | 1316 | * it to fail. If this method returns false and a match was found, then more input |
michael@0 | 1317 | * might change the match but the match won't be lost. If a match was not found, |
michael@0 | 1318 | * then requireEnd has no meaning. |
michael@0 | 1319 | * |
michael@0 | 1320 | * @return TRUE if more input could cause the most recent match to no longer match. |
michael@0 | 1321 | * @stable ICU 4.0 |
michael@0 | 1322 | */ |
michael@0 | 1323 | virtual UBool requireEnd() const; |
michael@0 | 1324 | |
michael@0 | 1325 | |
michael@0 | 1326 | /** |
michael@0 | 1327 | * Returns the pattern that is interpreted by this matcher. |
michael@0 | 1328 | * @return the RegexPattern for this RegexMatcher |
michael@0 | 1329 | * @stable ICU 2.4 |
michael@0 | 1330 | */ |
michael@0 | 1331 | virtual const RegexPattern &pattern() const; |
michael@0 | 1332 | |
michael@0 | 1333 | |
michael@0 | 1334 | /** |
michael@0 | 1335 | * Replaces every substring of the input that matches the pattern |
michael@0 | 1336 | * with the given replacement string. This is a convenience function that |
michael@0 | 1337 | * provides a complete find-and-replace-all operation. |
michael@0 | 1338 | * |
michael@0 | 1339 | * This method first resets this matcher. It then scans the input string |
michael@0 | 1340 | * looking for matches of the pattern. Input that is not part of any |
michael@0 | 1341 | * match is left unchanged; each match is replaced in the result by the |
michael@0 | 1342 | * replacement string. The replacement string may contain references to |
michael@0 | 1343 | * capture groups. |
michael@0 | 1344 | * |
michael@0 | 1345 | * @param replacement a string containing the replacement text. |
michael@0 | 1346 | * @param status a reference to a UErrorCode to receive any errors. |
michael@0 | 1347 | * @return a string containing the results of the find and replace. |
michael@0 | 1348 | * @stable ICU 2.4 |
michael@0 | 1349 | */ |
michael@0 | 1350 | virtual UnicodeString replaceAll(const UnicodeString &replacement, UErrorCode &status); |
michael@0 | 1351 | |
michael@0 | 1352 | |
michael@0 | 1353 | /** |
michael@0 | 1354 | * Replaces every substring of the input that matches the pattern |
michael@0 | 1355 | * with the given replacement string. This is a convenience function that |
michael@0 | 1356 | * provides a complete find-and-replace-all operation. |
michael@0 | 1357 | * |
michael@0 | 1358 | * This method first resets this matcher. It then scans the input string |
michael@0 | 1359 | * looking for matches of the pattern. Input that is not part of any |
michael@0 | 1360 | * match is left unchanged; each match is replaced in the result by the |
michael@0 | 1361 | * replacement string. The replacement string may contain references to |
michael@0 | 1362 | * capture groups. |
michael@0 | 1363 | * |
michael@0 | 1364 | * @param replacement a string containing the replacement text. |
michael@0 | 1365 | * @param dest a mutable UText in which the results are placed. |
michael@0 | 1366 | * If NULL, a new UText will be created (which may not be mutable). |
michael@0 | 1367 | * @param status a reference to a UErrorCode to receive any errors. |
michael@0 | 1368 | * @return a string containing the results of the find and replace. |
michael@0 | 1369 | * If a pre-allocated UText was provided, it will always be used and returned. |
michael@0 | 1370 | * |
michael@0 | 1371 | * @stable ICU 4.6 |
michael@0 | 1372 | */ |
michael@0 | 1373 | virtual UText *replaceAll(UText *replacement, UText *dest, UErrorCode &status); |
michael@0 | 1374 | |
michael@0 | 1375 | |
michael@0 | 1376 | /** |
michael@0 | 1377 | * Replaces the first substring of the input that matches |
michael@0 | 1378 | * the pattern with the replacement string. This is a convenience |
michael@0 | 1379 | * function that provides a complete find-and-replace operation. |
michael@0 | 1380 | * |
michael@0 | 1381 | * <p>This function first resets this RegexMatcher. It then scans the input string |
michael@0 | 1382 | * looking for a match of the pattern. Input that is not part |
michael@0 | 1383 | * of the match is appended directly to the result string; the match is replaced |
michael@0 | 1384 | * in the result by the replacement string. The replacement string may contain |
michael@0 | 1385 | * references to captured groups.</p> |
michael@0 | 1386 | * |
michael@0 | 1387 | * <p>The state of the matcher (the position at which a subsequent find() |
michael@0 | 1388 | * would begin) after completing a replaceFirst() is not specified. The |
michael@0 | 1389 | * RegexMatcher should be reset before doing additional find() operations.</p> |
michael@0 | 1390 | * |
michael@0 | 1391 | * @param replacement a string containing the replacement text. |
michael@0 | 1392 | * @param status a reference to a UErrorCode to receive any errors. |
michael@0 | 1393 | * @return a string containing the results of the find and replace. |
michael@0 | 1394 | * @stable ICU 2.4 |
michael@0 | 1395 | */ |
michael@0 | 1396 | virtual UnicodeString replaceFirst(const UnicodeString &replacement, UErrorCode &status); |
michael@0 | 1397 | |
michael@0 | 1398 | |
michael@0 | 1399 | /** |
michael@0 | 1400 | * Replaces the first substring of the input that matches |
michael@0 | 1401 | * the pattern with the replacement string. This is a convenience |
michael@0 | 1402 | * function that provides a complete find-and-replace operation. |
michael@0 | 1403 | * |
michael@0 | 1404 | * <p>This function first resets this RegexMatcher. It then scans the input string |
michael@0 | 1405 | * looking for a match of the pattern. Input that is not part |
michael@0 | 1406 | * of the match is appended directly to the result string; the match is replaced |
michael@0 | 1407 | * in the result by the replacement string. The replacement string may contain |
michael@0 | 1408 | * references to captured groups.</p> |
michael@0 | 1409 | * |
michael@0 | 1410 | * <p>The state of the matcher (the position at which a subsequent find() |
michael@0 | 1411 | * would begin) after completing a replaceFirst() is not specified. The |
michael@0 | 1412 | * RegexMatcher should be reset before doing additional find() operations.</p> |
michael@0 | 1413 | * |
michael@0 | 1414 | * @param replacement a string containing the replacement text. |
michael@0 | 1415 | * @param dest a mutable UText in which the results are placed. |
michael@0 | 1416 | * If NULL, a new UText will be created (which may not be mutable). |
michael@0 | 1417 | * @param status a reference to a UErrorCode to receive any errors. |
michael@0 | 1418 | * @return a string containing the results of the find and replace. |
michael@0 | 1419 | * If a pre-allocated UText was provided, it will always be used and returned. |
michael@0 | 1420 | * |
michael@0 | 1421 | * @stable ICU 4.6 |
michael@0 | 1422 | */ |
michael@0 | 1423 | virtual UText *replaceFirst(UText *replacement, UText *dest, UErrorCode &status); |
michael@0 | 1424 | |
michael@0 | 1425 | |
michael@0 | 1426 | /** |
michael@0 | 1427 | * Implements a replace operation intended to be used as part of an |
michael@0 | 1428 | * incremental find-and-replace. |
michael@0 | 1429 | * |
michael@0 | 1430 | * <p>The input string, starting from the end of the previous replacement and ending at |
michael@0 | 1431 | * the start of the current match, is appended to the destination string. Then the |
michael@0 | 1432 | * replacement string is appended to the output string, |
michael@0 | 1433 | * including handling any substitutions of captured text.</p> |
michael@0 | 1434 | * |
michael@0 | 1435 | * <p>For simple, prepackaged, non-incremental find-and-replace |
michael@0 | 1436 | * operations, see replaceFirst() or replaceAll().</p> |
michael@0 | 1437 | * |
michael@0 | 1438 | * @param dest A UnicodeString to which the results of the find-and-replace are appended. |
michael@0 | 1439 | * @param replacement A UnicodeString that provides the text to be substituted for |
michael@0 | 1440 | * the input text that matched the regexp pattern. The replacement |
michael@0 | 1441 | * text may contain references to captured text from the |
michael@0 | 1442 | * input. |
michael@0 | 1443 | * @param status A reference to a UErrorCode to receive any errors. Possible |
michael@0 | 1444 | * errors are U_REGEX_INVALID_STATE if no match has been |
michael@0 | 1445 | * attempted or the last match failed, and U_INDEX_OUTOFBOUNDS_ERROR |
michael@0 | 1446 | * if the replacement text specifies a capture group that |
michael@0 | 1447 | * does not exist in the pattern. |
michael@0 | 1448 | * |
michael@0 | 1449 | * @return this RegexMatcher |
michael@0 | 1450 | * @stable ICU 2.4 |
michael@0 | 1451 | * |
michael@0 | 1452 | */ |
michael@0 | 1453 | virtual RegexMatcher &appendReplacement(UnicodeString &dest, |
michael@0 | 1454 | const UnicodeString &replacement, UErrorCode &status); |
michael@0 | 1455 | |
michael@0 | 1456 | |
michael@0 | 1457 | /** |
michael@0 | 1458 | * Implements a replace operation intended to be used as part of an |
michael@0 | 1459 | * incremental find-and-replace. |
michael@0 | 1460 | * |
michael@0 | 1461 | * <p>The input string, starting from the end of the previous replacement and ending at |
michael@0 | 1462 | * the start of the current match, is appended to the destination string. Then the |
michael@0 | 1463 | * replacement string is appended to the output string, |
michael@0 | 1464 | * including handling any substitutions of captured text.</p> |
michael@0 | 1465 | * |
michael@0 | 1466 | * <p>For simple, prepackaged, non-incremental find-and-replace |
michael@0 | 1467 | * operations, see replaceFirst() or replaceAll().</p> |
michael@0 | 1468 | * |
michael@0 | 1469 | * @param dest A mutable UText to which the results of the find-and-replace are appended. |
michael@0 | 1470 | * Must not be NULL. |
michael@0 | 1471 | * @param replacement A UText that provides the text to be substituted for |
michael@0 | 1472 | * the input text that matched the regexp pattern. The replacement |
michael@0 | 1473 | * text may contain references to captured text from the input. |
michael@0 | 1474 | * @param status A reference to a UErrorCode to receive any errors. Possible |
michael@0 | 1475 | * errors are U_REGEX_INVALID_STATE if no match has been |
michael@0 | 1476 | * attempted or the last match failed, and U_INDEX_OUTOFBOUNDS_ERROR |
michael@0 | 1477 | * if the replacement text specifies a capture group that |
michael@0 | 1478 | * does not exist in the pattern. |
michael@0 | 1479 | * |
michael@0 | 1480 | * @return this RegexMatcher |
michael@0 | 1481 | * |
michael@0 | 1482 | * @stable ICU 4.6 |
michael@0 | 1483 | */ |
michael@0 | 1484 | virtual RegexMatcher &appendReplacement(UText *dest, |
michael@0 | 1485 | UText *replacement, UErrorCode &status); |
michael@0 | 1486 | |
michael@0 | 1487 | |
michael@0 | 1488 | /** |
michael@0 | 1489 | * As the final step in a find-and-replace operation, append the remainder |
michael@0 | 1490 | * of the input string, starting at the position following the last appendReplacement(), |
michael@0 | 1491 | * to the destination string. <code>appendTail()</code> is intended to be invoked after one |
michael@0 | 1492 | * or more invocations of the <code>RegexMatcher::appendReplacement()</code>. |
michael@0 | 1493 | * |
michael@0 | 1494 | * @param dest A UnicodeString to which the results of the find-and-replace are appended. |
michael@0 | 1495 | * @return the destination string. |
michael@0 | 1496 | * @stable ICU 2.4 |
michael@0 | 1497 | */ |
michael@0 | 1498 | virtual UnicodeString &appendTail(UnicodeString &dest); |
michael@0 | 1499 | |
michael@0 | 1500 | |
michael@0 | 1501 | /** |
michael@0 | 1502 | * As the final step in a find-and-replace operation, append the remainder |
michael@0 | 1503 | * of the input string, starting at the position following the last appendReplacement(), |
michael@0 | 1504 | * to the destination string. <code>appendTail()</code> is intended to be invoked after one |
michael@0 | 1505 | * or more invocations of the <code>RegexMatcher::appendReplacement()</code>. |
michael@0 | 1506 | * |
michael@0 | 1507 | * @param dest A mutable UText to which the results of the find-and-replace are appended. |
michael@0 | 1508 | * Must not be NULL. |
michael@0 | 1509 | * @param status error cod |
michael@0 | 1510 | * @return the destination string. |
michael@0 | 1511 | * |
michael@0 | 1512 | * @stable ICU 4.6 |
michael@0 | 1513 | */ |
michael@0 | 1514 | virtual UText *appendTail(UText *dest, UErrorCode &status); |
michael@0 | 1515 | |
michael@0 | 1516 | |
michael@0 | 1517 | /** |
michael@0 | 1518 | * Split a string into fields. Somewhat like split() from Perl. |
michael@0 | 1519 | * The pattern matches identify delimiters that separate the input |
michael@0 | 1520 | * into fields. The input data between the matches becomes the |
michael@0 | 1521 | * fields themselves. |
michael@0 | 1522 | * |
michael@0 | 1523 | * @param input The string to be split into fields. The field delimiters |
michael@0 | 1524 | * match the pattern (in the "this" object). This matcher |
michael@0 | 1525 | * will be reset to this input string. |
michael@0 | 1526 | * @param dest An array of UnicodeStrings to receive the results of the split. |
michael@0 | 1527 | * This is an array of actual UnicodeString objects, not an |
michael@0 | 1528 | * array of pointers to strings. Local (stack based) arrays can |
michael@0 | 1529 | * work well here. |
michael@0 | 1530 | * @param destCapacity The number of elements in the destination array. |
michael@0 | 1531 | * If the number of fields found is less than destCapacity, the |
michael@0 | 1532 | * extra strings in the destination array are not altered. |
michael@0 | 1533 | * If the number of destination strings is less than the number |
michael@0 | 1534 | * of fields, the trailing part of the input string, including any |
michael@0 | 1535 | * field delimiters, is placed in the last destination string. |
michael@0 | 1536 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 1537 | * @return The number of fields into which the input string was split. |
michael@0 | 1538 | * @stable ICU 2.6 |
michael@0 | 1539 | */ |
michael@0 | 1540 | virtual int32_t split(const UnicodeString &input, |
michael@0 | 1541 | UnicodeString dest[], |
michael@0 | 1542 | int32_t destCapacity, |
michael@0 | 1543 | UErrorCode &status); |
michael@0 | 1544 | |
michael@0 | 1545 | |
michael@0 | 1546 | /** |
michael@0 | 1547 | * Split a string into fields. Somewhat like split() from Perl. |
michael@0 | 1548 | * The pattern matches identify delimiters that separate the input |
michael@0 | 1549 | * into fields. The input data between the matches becomes the |
michael@0 | 1550 | * fields themselves. |
michael@0 | 1551 | * |
michael@0 | 1552 | * @param input The string to be split into fields. The field delimiters |
michael@0 | 1553 | * match the pattern (in the "this" object). This matcher |
michael@0 | 1554 | * will be reset to this input string. |
michael@0 | 1555 | * @param dest An array of mutable UText structs to receive the results of the split. |
michael@0 | 1556 | * If a field is NULL, a new UText is allocated to contain the results for |
michael@0 | 1557 | * that field. This new UText is not guaranteed to be mutable. |
michael@0 | 1558 | * @param destCapacity The number of elements in the destination array. |
michael@0 | 1559 | * If the number of fields found is less than destCapacity, the |
michael@0 | 1560 | * extra strings in the destination array are not altered. |
michael@0 | 1561 | * If the number of destination strings is less than the number |
michael@0 | 1562 | * of fields, the trailing part of the input string, including any |
michael@0 | 1563 | * field delimiters, is placed in the last destination string. |
michael@0 | 1564 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 1565 | * @return The number of fields into which the input string was split. |
michael@0 | 1566 | * |
michael@0 | 1567 | * @stable ICU 4.6 |
michael@0 | 1568 | */ |
michael@0 | 1569 | virtual int32_t split(UText *input, |
michael@0 | 1570 | UText *dest[], |
michael@0 | 1571 | int32_t destCapacity, |
michael@0 | 1572 | UErrorCode &status); |
michael@0 | 1573 | |
michael@0 | 1574 | /** |
michael@0 | 1575 | * Set a processing time limit for match operations with this Matcher. |
michael@0 | 1576 | * |
michael@0 | 1577 | * Some patterns, when matching certain strings, can run in exponential time. |
michael@0 | 1578 | * For practical purposes, the match operation may appear to be in an |
michael@0 | 1579 | * infinite loop. |
michael@0 | 1580 | * When a limit is set a match operation will fail with an error if the |
michael@0 | 1581 | * limit is exceeded. |
michael@0 | 1582 | * <p> |
michael@0 | 1583 | * The units of the limit are steps of the match engine. |
michael@0 | 1584 | * Correspondence with actual processor time will depend on the speed |
michael@0 | 1585 | * of the processor and the details of the specific pattern, but will |
michael@0 | 1586 | * typically be on the order of milliseconds. |
michael@0 | 1587 | * <p> |
michael@0 | 1588 | * By default, the matching time is not limited. |
michael@0 | 1589 | * <p> |
michael@0 | 1590 | * |
michael@0 | 1591 | * @param limit The limit value, or 0 for no limit. |
michael@0 | 1592 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 1593 | * @stable ICU 4.0 |
michael@0 | 1594 | */ |
michael@0 | 1595 | virtual void setTimeLimit(int32_t limit, UErrorCode &status); |
michael@0 | 1596 | |
michael@0 | 1597 | /** |
michael@0 | 1598 | * Get the time limit, if any, for match operations made with this Matcher. |
michael@0 | 1599 | * |
michael@0 | 1600 | * @return the maximum allowed time for a match, in units of processing steps. |
michael@0 | 1601 | * @stable ICU 4.0 |
michael@0 | 1602 | */ |
michael@0 | 1603 | virtual int32_t getTimeLimit() const; |
michael@0 | 1604 | |
michael@0 | 1605 | /** |
michael@0 | 1606 | * Set the amount of heap storage available for use by the match backtracking stack. |
michael@0 | 1607 | * The matcher is also reset, discarding any results from previous matches. |
michael@0 | 1608 | * <p> |
michael@0 | 1609 | * ICU uses a backtracking regular expression engine, with the backtrack stack |
michael@0 | 1610 | * maintained on the heap. This function sets the limit to the amount of memory |
michael@0 | 1611 | * that can be used for this purpose. A backtracking stack overflow will |
michael@0 | 1612 | * result in an error from the match operation that caused it. |
michael@0 | 1613 | * <p> |
michael@0 | 1614 | * A limit is desirable because a malicious or poorly designed pattern can use |
michael@0 | 1615 | * excessive memory, potentially crashing the process. A limit is enabled |
michael@0 | 1616 | * by default. |
michael@0 | 1617 | * <p> |
michael@0 | 1618 | * @param limit The maximum size, in bytes, of the matching backtrack stack. |
michael@0 | 1619 | * A value of zero means no limit. |
michael@0 | 1620 | * The limit must be greater or equal to zero. |
michael@0 | 1621 | * |
michael@0 | 1622 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 1623 | * |
michael@0 | 1624 | * @stable ICU 4.0 |
michael@0 | 1625 | */ |
michael@0 | 1626 | virtual void setStackLimit(int32_t limit, UErrorCode &status); |
michael@0 | 1627 | |
michael@0 | 1628 | /** |
michael@0 | 1629 | * Get the size of the heap storage available for use by the back tracking stack. |
michael@0 | 1630 | * |
michael@0 | 1631 | * @return the maximum backtracking stack size, in bytes, or zero if the |
michael@0 | 1632 | * stack size is unlimited. |
michael@0 | 1633 | * @stable ICU 4.0 |
michael@0 | 1634 | */ |
michael@0 | 1635 | virtual int32_t getStackLimit() const; |
michael@0 | 1636 | |
michael@0 | 1637 | |
michael@0 | 1638 | /** |
michael@0 | 1639 | * Set a callback function for use with this Matcher. |
michael@0 | 1640 | * During matching operations the function will be called periodically, |
michael@0 | 1641 | * giving the application the opportunity to terminate a long-running |
michael@0 | 1642 | * match. |
michael@0 | 1643 | * |
michael@0 | 1644 | * @param callback A pointer to the user-supplied callback function. |
michael@0 | 1645 | * @param context User context pointer. The value supplied at the |
michael@0 | 1646 | * time the callback function is set will be saved |
michael@0 | 1647 | * and passed to the callback each time that it is called. |
michael@0 | 1648 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 1649 | * @stable ICU 4.0 |
michael@0 | 1650 | */ |
michael@0 | 1651 | virtual void setMatchCallback(URegexMatchCallback *callback, |
michael@0 | 1652 | const void *context, |
michael@0 | 1653 | UErrorCode &status); |
michael@0 | 1654 | |
michael@0 | 1655 | |
michael@0 | 1656 | /** |
michael@0 | 1657 | * Get the callback function for this URegularExpression. |
michael@0 | 1658 | * |
michael@0 | 1659 | * @param callback Out parameter, receives a pointer to the user-supplied |
michael@0 | 1660 | * callback function. |
michael@0 | 1661 | * @param context Out parameter, receives the user context pointer that |
michael@0 | 1662 | * was set when uregex_setMatchCallback() was called. |
michael@0 | 1663 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 1664 | * @stable ICU 4.0 |
michael@0 | 1665 | */ |
michael@0 | 1666 | virtual void getMatchCallback(URegexMatchCallback *&callback, |
michael@0 | 1667 | const void *&context, |
michael@0 | 1668 | UErrorCode &status); |
michael@0 | 1669 | |
michael@0 | 1670 | |
michael@0 | 1671 | /** |
michael@0 | 1672 | * Set a progress callback function for use with find operations on this Matcher. |
michael@0 | 1673 | * During find operations, the callback will be invoked after each return from a |
michael@0 | 1674 | * match attempt, giving the application the opportunity to terminate a long-running |
michael@0 | 1675 | * find operation. |
michael@0 | 1676 | * |
michael@0 | 1677 | * @param callback A pointer to the user-supplied callback function. |
michael@0 | 1678 | * @param context User context pointer. The value supplied at the |
michael@0 | 1679 | * time the callback function is set will be saved |
michael@0 | 1680 | * and passed to the callback each time that it is called. |
michael@0 | 1681 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 1682 | * @stable ICU 4.6 |
michael@0 | 1683 | */ |
michael@0 | 1684 | virtual void setFindProgressCallback(URegexFindProgressCallback *callback, |
michael@0 | 1685 | const void *context, |
michael@0 | 1686 | UErrorCode &status); |
michael@0 | 1687 | |
michael@0 | 1688 | |
michael@0 | 1689 | /** |
michael@0 | 1690 | * Get the find progress callback function for this URegularExpression. |
michael@0 | 1691 | * |
michael@0 | 1692 | * @param callback Out parameter, receives a pointer to the user-supplied |
michael@0 | 1693 | * callback function. |
michael@0 | 1694 | * @param context Out parameter, receives the user context pointer that |
michael@0 | 1695 | * was set when uregex_setFindProgressCallback() was called. |
michael@0 | 1696 | * @param status A reference to a UErrorCode to receive any errors. |
michael@0 | 1697 | * @stable ICU 4.6 |
michael@0 | 1698 | */ |
michael@0 | 1699 | virtual void getFindProgressCallback(URegexFindProgressCallback *&callback, |
michael@0 | 1700 | const void *&context, |
michael@0 | 1701 | UErrorCode &status); |
michael@0 | 1702 | |
michael@0 | 1703 | #ifndef U_HIDE_INTERNAL_API |
michael@0 | 1704 | /** |
michael@0 | 1705 | * setTrace Debug function, enable/disable tracing of the matching engine. |
michael@0 | 1706 | * For internal ICU development use only. DO NO USE!!!! |
michael@0 | 1707 | * @internal |
michael@0 | 1708 | */ |
michael@0 | 1709 | void setTrace(UBool state); |
michael@0 | 1710 | #endif /* U_HIDE_INTERNAL_API */ |
michael@0 | 1711 | |
michael@0 | 1712 | /** |
michael@0 | 1713 | * ICU "poor man's RTTI", returns a UClassID for this class. |
michael@0 | 1714 | * |
michael@0 | 1715 | * @stable ICU 2.2 |
michael@0 | 1716 | */ |
michael@0 | 1717 | static UClassID U_EXPORT2 getStaticClassID(); |
michael@0 | 1718 | |
michael@0 | 1719 | /** |
michael@0 | 1720 | * ICU "poor man's RTTI", returns a UClassID for the actual class. |
michael@0 | 1721 | * |
michael@0 | 1722 | * @stable ICU 2.2 |
michael@0 | 1723 | */ |
michael@0 | 1724 | virtual UClassID getDynamicClassID() const; |
michael@0 | 1725 | |
michael@0 | 1726 | private: |
michael@0 | 1727 | // Constructors and other object boilerplate are private. |
michael@0 | 1728 | // Instances of RegexMatcher can not be assigned, copied, cloned, etc. |
michael@0 | 1729 | RegexMatcher(); // default constructor not implemented |
michael@0 | 1730 | RegexMatcher(const RegexPattern *pat); |
michael@0 | 1731 | RegexMatcher(const RegexMatcher &other); |
michael@0 | 1732 | RegexMatcher &operator =(const RegexMatcher &rhs); |
michael@0 | 1733 | void init(UErrorCode &status); // Common initialization |
michael@0 | 1734 | void init2(UText *t, UErrorCode &e); // Common initialization, part 2. |
michael@0 | 1735 | |
michael@0 | 1736 | friend class RegexPattern; |
michael@0 | 1737 | friend class RegexCImpl; |
michael@0 | 1738 | public: |
michael@0 | 1739 | #ifndef U_HIDE_INTERNAL_API |
michael@0 | 1740 | /** @internal */ |
michael@0 | 1741 | void resetPreserveRegion(); // Reset matcher state, but preserve any region. |
michael@0 | 1742 | #endif /* U_HIDE_INTERNAL_API */ |
michael@0 | 1743 | private: |
michael@0 | 1744 | |
michael@0 | 1745 | // |
michael@0 | 1746 | // MatchAt This is the internal interface to the match engine itself. |
michael@0 | 1747 | // Match status comes back in matcher member variables. |
michael@0 | 1748 | // |
michael@0 | 1749 | void MatchAt(int64_t startIdx, UBool toEnd, UErrorCode &status); |
michael@0 | 1750 | inline void backTrack(int64_t &inputIdx, int32_t &patIdx); |
michael@0 | 1751 | UBool isWordBoundary(int64_t pos); // perform Perl-like \b test |
michael@0 | 1752 | UBool isUWordBoundary(int64_t pos); // perform RBBI based \b test |
michael@0 | 1753 | REStackFrame *resetStack(); |
michael@0 | 1754 | inline REStackFrame *StateSave(REStackFrame *fp, int64_t savePatIdx, UErrorCode &status); |
michael@0 | 1755 | void IncrementTime(UErrorCode &status); |
michael@0 | 1756 | UBool ReportFindProgress(int64_t matchIndex, UErrorCode &status); |
michael@0 | 1757 | |
michael@0 | 1758 | int64_t appendGroup(int32_t groupNum, UText *dest, UErrorCode &status) const; |
michael@0 | 1759 | |
michael@0 | 1760 | UBool findUsingChunk(); |
michael@0 | 1761 | void MatchChunkAt(int32_t startIdx, UBool toEnd, UErrorCode &status); |
michael@0 | 1762 | UBool isChunkWordBoundary(int32_t pos); |
michael@0 | 1763 | |
michael@0 | 1764 | const RegexPattern *fPattern; |
michael@0 | 1765 | RegexPattern *fPatternOwned; // Non-NULL if this matcher owns the pattern, and |
michael@0 | 1766 | // should delete it when through. |
michael@0 | 1767 | |
michael@0 | 1768 | const UnicodeString *fInput; // The string being matched. Only used for input() |
michael@0 | 1769 | UText *fInputText; // The text being matched. Is never NULL. |
michael@0 | 1770 | UText *fAltInputText; // A shallow copy of the text being matched. |
michael@0 | 1771 | // Only created if the pattern contains backreferences. |
michael@0 | 1772 | int64_t fInputLength; // Full length of the input text. |
michael@0 | 1773 | int32_t fFrameSize; // The size of a frame in the backtrack stack. |
michael@0 | 1774 | |
michael@0 | 1775 | int64_t fRegionStart; // Start of the input region, default = 0. |
michael@0 | 1776 | int64_t fRegionLimit; // End of input region, default to input.length. |
michael@0 | 1777 | |
michael@0 | 1778 | int64_t fAnchorStart; // Region bounds for anchoring operations (^ or $). |
michael@0 | 1779 | int64_t fAnchorLimit; // See useAnchoringBounds |
michael@0 | 1780 | |
michael@0 | 1781 | int64_t fLookStart; // Region bounds for look-ahead/behind and |
michael@0 | 1782 | int64_t fLookLimit; // and other boundary tests. See |
michael@0 | 1783 | // useTransparentBounds |
michael@0 | 1784 | |
michael@0 | 1785 | int64_t fActiveStart; // Currently active bounds for matching. |
michael@0 | 1786 | int64_t fActiveLimit; // Usually is the same as region, but |
michael@0 | 1787 | // is changed to fLookStart/Limit when |
michael@0 | 1788 | // entering look around regions. |
michael@0 | 1789 | |
michael@0 | 1790 | UBool fTransparentBounds; // True if using transparent bounds. |
michael@0 | 1791 | UBool fAnchoringBounds; // True if using anchoring bounds. |
michael@0 | 1792 | |
michael@0 | 1793 | UBool fMatch; // True if the last attempted match was successful. |
michael@0 | 1794 | int64_t fMatchStart; // Position of the start of the most recent match |
michael@0 | 1795 | int64_t fMatchEnd; // First position after the end of the most recent match |
michael@0 | 1796 | // Zero if no previous match, even when a region |
michael@0 | 1797 | // is active. |
michael@0 | 1798 | int64_t fLastMatchEnd; // First position after the end of the previous match, |
michael@0 | 1799 | // or -1 if there was no previous match. |
michael@0 | 1800 | int64_t fAppendPosition; // First position after the end of the previous |
michael@0 | 1801 | // appendReplacement(). As described by the |
michael@0 | 1802 | // JavaDoc for Java Matcher, where it is called |
michael@0 | 1803 | // "append position" |
michael@0 | 1804 | UBool fHitEnd; // True if the last match touched the end of input. |
michael@0 | 1805 | UBool fRequireEnd; // True if the last match required end-of-input |
michael@0 | 1806 | // (matched $ or Z) |
michael@0 | 1807 | |
michael@0 | 1808 | UVector64 *fStack; |
michael@0 | 1809 | REStackFrame *fFrame; // After finding a match, the last active stack frame, |
michael@0 | 1810 | // which will contain the capture group results. |
michael@0 | 1811 | // NOT valid while match engine is running. |
michael@0 | 1812 | |
michael@0 | 1813 | int64_t *fData; // Data area for use by the compiled pattern. |
michael@0 | 1814 | int64_t fSmallData[8]; // Use this for data if it's enough. |
michael@0 | 1815 | |
michael@0 | 1816 | int32_t fTimeLimit; // Max time (in arbitrary steps) to let the |
michael@0 | 1817 | // match engine run. Zero for unlimited. |
michael@0 | 1818 | |
michael@0 | 1819 | int32_t fTime; // Match time, accumulates while matching. |
michael@0 | 1820 | int32_t fTickCounter; // Low bits counter for time. Counts down StateSaves. |
michael@0 | 1821 | // Kept separately from fTime to keep as much |
michael@0 | 1822 | // code as possible out of the inline |
michael@0 | 1823 | // StateSave function. |
michael@0 | 1824 | |
michael@0 | 1825 | int32_t fStackLimit; // Maximum memory size to use for the backtrack |
michael@0 | 1826 | // stack, in bytes. Zero for unlimited. |
michael@0 | 1827 | |
michael@0 | 1828 | URegexMatchCallback *fCallbackFn; // Pointer to match progress callback funct. |
michael@0 | 1829 | // NULL if there is no callback. |
michael@0 | 1830 | const void *fCallbackContext; // User Context ptr for callback function. |
michael@0 | 1831 | |
michael@0 | 1832 | URegexFindProgressCallback *fFindProgressCallbackFn; // Pointer to match progress callback funct. |
michael@0 | 1833 | // NULL if there is no callback. |
michael@0 | 1834 | const void *fFindProgressCallbackContext; // User Context ptr for callback function. |
michael@0 | 1835 | |
michael@0 | 1836 | |
michael@0 | 1837 | UBool fInputUniStrMaybeMutable; // Set when fInputText wraps a UnicodeString that may be mutable - compatibility. |
michael@0 | 1838 | |
michael@0 | 1839 | UBool fTraceDebug; // Set true for debug tracing of match engine. |
michael@0 | 1840 | |
michael@0 | 1841 | UErrorCode fDeferredStatus; // Save error state that cannot be immediately |
michael@0 | 1842 | // reported, or that permanently disables this matcher. |
michael@0 | 1843 | |
michael@0 | 1844 | RuleBasedBreakIterator *fWordBreakItr; |
michael@0 | 1845 | }; |
michael@0 | 1846 | |
michael@0 | 1847 | U_NAMESPACE_END |
michael@0 | 1848 | #endif // UCONFIG_NO_REGULAR_EXPRESSIONS |
michael@0 | 1849 | #endif |