uregex.h 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612
  1. /*
  2. **********************************************************************
  3. * Copyright (C) 2004-2016, International Business Machines
  4. * Corporation and others. All Rights Reserved.
  5. **********************************************************************
  6. * file name: uregex.h
  7. * encoding: US-ASCII
  8. * indentation:4
  9. *
  10. * created on: 2004mar09
  11. * created by: Andy Heninger
  12. *
  13. * ICU Regular Expressions, API for C
  14. */
  15. /**
  16. * \file
  17. * \brief C API: Regular Expressions
  18. *
  19. * <p>This is a C wrapper around the C++ RegexPattern and RegexMatcher classes.</p>
  20. */
  21. #ifndef UREGEX_H
  22. #define UREGEX_H
  23. #include "unicode/utext.h"
  24. #include "unicode/utypes.h"
  25. #if !UCONFIG_NO_REGULAR_EXPRESSIONS
  26. #include "unicode/localpointer.h"
  27. #include "unicode/parseerr.h"
  28. struct URegularExpression;
  29. /**
  30. * Structure representing a compiled regular expression, plus the results
  31. * of a match operation.
  32. * @stable ICU 3.0
  33. */
  34. typedef struct URegularExpression URegularExpression;
  35. /**
  36. * Constants for Regular Expression Match Modes.
  37. * @stable ICU 2.4
  38. */
  39. typedef enum URegexpFlag{
  40. #ifndef U_HIDE_DRAFT_API
  41. /** Forces normalization of pattern and strings.
  42. Not implemented yet, just a placeholder, hence draft.
  43. @draft ICU 2.4 */
  44. UREGEX_CANON_EQ = 128,
  45. #endif /* U_HIDE_DRAFT_API */
  46. /** Enable case insensitive matching. @stable ICU 2.4 */
  47. UREGEX_CASE_INSENSITIVE = 2,
  48. /** Allow white space and comments within patterns @stable ICU 2.4 */
  49. UREGEX_COMMENTS = 4,
  50. /** If set, '.' matches line terminators, otherwise '.' matching stops at line end.
  51. * @stable ICU 2.4 */
  52. UREGEX_DOTALL = 32,
  53. /** If set, treat the entire pattern as a literal string.
  54. * Metacharacters or escape sequences in the input sequence will be given
  55. * no special meaning.
  56. *
  57. * The flag UREGEX_CASE_INSENSITIVE retains its impact
  58. * on matching when used in conjunction with this flag.
  59. * The other flags become superfluous.
  60. *
  61. * @stable ICU 4.0
  62. */
  63. UREGEX_LITERAL = 16,
  64. /** Control behavior of "$" and "^"
  65. * If set, recognize line terminators within string,
  66. * otherwise, match only at start and end of input string.
  67. * @stable ICU 2.4 */
  68. UREGEX_MULTILINE = 8,
  69. /** Unix-only line endings.
  70. * When this mode is enabled, only \\u000a is recognized as a line ending
  71. * in the behavior of ., ^, and $.
  72. * @stable ICU 4.0
  73. */
  74. UREGEX_UNIX_LINES = 1,
  75. /** Unicode word boundaries.
  76. * If set, \b uses the Unicode TR 29 definition of word boundaries.
  77. * Warning: Unicode word boundaries are quite different from
  78. * traditional regular expression word boundaries. See
  79. * http://unicode.org/reports/tr29/#Word_Boundaries
  80. * @stable ICU 2.8
  81. */
  82. UREGEX_UWORD = 256,
  83. /** Error on Unrecognized backslash escapes.
  84. * If set, fail with an error on patterns that contain
  85. * backslash-escaped ASCII letters without a known special
  86. * meaning. If this flag is not set, these
  87. * escaped letters represent themselves.
  88. * @stable ICU 4.0
  89. */
  90. UREGEX_ERROR_ON_UNKNOWN_ESCAPES = 512
  91. } URegexpFlag;
  92. /**
  93. * Open (compile) an ICU regular expression. Compiles the regular expression in
  94. * string form into an internal representation using the specified match mode flags.
  95. * The resulting regular expression handle can then be used to perform various
  96. * matching operations.
  97. *
  98. *
  99. * @param pattern The Regular Expression pattern to be compiled.
  100. * @param patternLength The length of the pattern, or -1 if the pattern is
  101. * NUL terminated.
  102. * @param flags Flags that alter the default matching behavior for
  103. * the regular expression, UREGEX_CASE_INSENSITIVE, for
  104. * example. For default behavior, set this parameter to zero.
  105. * See <code>enum URegexpFlag</code>. All desired flags
  106. * are bitwise-ORed together.
  107. * @param pe Receives the position (line and column numbers) of any syntax
  108. * error within the source regular expression string. If this
  109. * information is not wanted, pass NULL for this parameter.
  110. * @param status Receives error detected by this function.
  111. * @stable ICU 3.0
  112. *
  113. */
  114. U_STABLE URegularExpression * U_EXPORT2
  115. uregex_open( const UChar *pattern,
  116. int32_t patternLength,
  117. uint32_t flags,
  118. UParseError *pe,
  119. UErrorCode *status);
  120. /**
  121. * Open (compile) an ICU regular expression. Compiles the regular expression in
  122. * string form into an internal representation using the specified match mode flags.
  123. * The resulting regular expression handle can then be used to perform various
  124. * matching operations.
  125. * <p>
  126. * The contents of the pattern UText will be extracted and saved. Ownership of the
  127. * UText struct itself remains with the caller. This is to match the behavior of
  128. * uregex_open().
  129. *
  130. * @param pattern The Regular Expression pattern to be compiled.
  131. * @param flags Flags that alter the default matching behavior for
  132. * the regular expression, UREGEX_CASE_INSENSITIVE, for
  133. * example. For default behavior, set this parameter to zero.
  134. * See <code>enum URegexpFlag</code>. All desired flags
  135. * are bitwise-ORed together.
  136. * @param pe Receives the position (line and column numbers) of any syntax
  137. * error within the source regular expression string. If this
  138. * information is not wanted, pass NULL for this parameter.
  139. * @param status Receives error detected by this function.
  140. *
  141. * @stable ICU 4.6
  142. */
  143. U_STABLE URegularExpression * U_EXPORT2
  144. uregex_openUText(UText *pattern,
  145. uint32_t flags,
  146. UParseError *pe,
  147. UErrorCode *status);
  148. /**
  149. * Open (compile) an ICU regular expression. The resulting regular expression
  150. * handle can then be used to perform various matching operations.
  151. * <p>
  152. * This function is the same as uregex_open, except that the pattern
  153. * is supplied as an 8 bit char * string in the default code page.
  154. *
  155. * @param pattern The Regular Expression pattern to be compiled,
  156. * NUL terminated.
  157. * @param flags Flags that alter the default matching behavior for
  158. * the regular expression, UREGEX_CASE_INSENSITIVE, for
  159. * example. For default behavior, set this parameter to zero.
  160. * See <code>enum URegexpFlag</code>. All desired flags
  161. * are bitwise-ORed together.
  162. * @param pe Receives the position (line and column numbers) of any syntax
  163. * error within the source regular expression string. If this
  164. * information is not wanted, pass NULL for this parameter.
  165. * @param status Receives errors detected by this function.
  166. * @return The URegularExpression object representing the compiled
  167. * pattern.
  168. *
  169. * @stable ICU 3.0
  170. */
  171. #if !UCONFIG_NO_CONVERSION
  172. U_STABLE URegularExpression * U_EXPORT2
  173. uregex_openC( const char *pattern,
  174. uint32_t flags,
  175. UParseError *pe,
  176. UErrorCode *status);
  177. #endif
  178. /**
  179. * Close the regular expression, recovering all resources (memory) it
  180. * was holding.
  181. *
  182. * @param regexp The regular expression to be closed.
  183. * @stable ICU 3.0
  184. */
  185. U_STABLE void U_EXPORT2
  186. uregex_close(URegularExpression *regexp);
  187. #if U_SHOW_CPLUSPLUS_API
  188. U_NAMESPACE_BEGIN
  189. /**
  190. * \class LocalURegularExpressionPointer
  191. * "Smart pointer" class, closes a URegularExpression via uregex_close().
  192. * For most methods see the LocalPointerBase base class.
  193. *
  194. * @see LocalPointerBase
  195. * @see LocalPointer
  196. * @stable ICU 4.4
  197. */
  198. U_DEFINE_LOCAL_OPEN_POINTER(LocalURegularExpressionPointer, URegularExpression, uregex_close);
  199. U_NAMESPACE_END
  200. #endif
  201. /**
  202. * Make a copy of a compiled regular expression. Cloning a regular
  203. * expression is faster than opening a second instance from the source
  204. * form of the expression, and requires less memory.
  205. * <p>
  206. * Note that the current input string and the position of any matched text
  207. * within it are not cloned; only the pattern itself and the
  208. * match mode flags are copied.
  209. * <p>
  210. * Cloning can be particularly useful to threaded applications that perform
  211. * multiple match operations in parallel. Each concurrent RE
  212. * operation requires its own instance of a URegularExpression.
  213. *
  214. * @param regexp The compiled regular expression to be cloned.
  215. * @param status Receives indication of any errors encountered
  216. * @return the cloned copy of the compiled regular expression.
  217. * @stable ICU 3.0
  218. */
  219. U_STABLE URegularExpression * U_EXPORT2
  220. uregex_clone(const URegularExpression *regexp, UErrorCode *status);
  221. /**
  222. * Returns a pointer to the source form of the pattern for this regular expression.
  223. * This function will work even if the pattern was originally specified as a UText.
  224. *
  225. * @param regexp The compiled regular expression.
  226. * @param patLength This output parameter will be set to the length of the
  227. * pattern string. A NULL pointer may be used here if the
  228. * pattern length is not needed, as would be the case if
  229. * the pattern is known in advance to be a NUL terminated
  230. * string.
  231. * @param status Receives errors detected by this function.
  232. * @return a pointer to the pattern string. The storage for the string is
  233. * owned by the regular expression object, and must not be
  234. * altered or deleted by the application. The returned string
  235. * will remain valid until the regular expression is closed.
  236. * @stable ICU 3.0
  237. */
  238. U_STABLE const UChar * U_EXPORT2
  239. uregex_pattern(const URegularExpression *regexp,
  240. int32_t *patLength,
  241. UErrorCode *status);
  242. /**
  243. * Returns the source text of the pattern for this regular expression.
  244. * This function will work even if the pattern was originally specified as a UChar string.
  245. *
  246. * @param regexp The compiled regular expression.
  247. * @param status Receives errors detected by this function.
  248. * @return the pattern text. The storage for the text is owned by the regular expression
  249. * object, and must not be altered or deleted.
  250. *
  251. * @stable ICU 4.6
  252. */
  253. U_STABLE UText * U_EXPORT2
  254. uregex_patternUText(const URegularExpression *regexp,
  255. UErrorCode *status);
  256. /**
  257. * Get the match mode flags that were specified when compiling this regular expression.
  258. * @param status Receives errors detected by this function.
  259. * @param regexp The compiled regular expression.
  260. * @return The match mode flags
  261. * @see URegexpFlag
  262. * @stable ICU 3.0
  263. */
  264. U_STABLE int32_t U_EXPORT2
  265. uregex_flags(const URegularExpression *regexp,
  266. UErrorCode *status);
  267. /**
  268. * Set the subject text string upon which the regular expression will look for matches.
  269. * This function may be called any number of times, allowing the regular
  270. * expression pattern to be applied to different strings.
  271. * <p>
  272. * Regular expression matching operations work directly on the application's
  273. * string data. No copy is made. The subject string data must not be
  274. * altered after calling this function until after all regular expression
  275. * operations involving this string data are completed.
  276. * <p>
  277. * Zero length strings are permitted. In this case, no subsequent match
  278. * operation will dereference the text string pointer.
  279. *
  280. * @param regexp The compiled regular expression.
  281. * @param text The subject text string.
  282. * @param textLength The length of the subject text, or -1 if the string
  283. * is NUL terminated.
  284. * @param status Receives errors detected by this function.
  285. * @stable ICU 3.0
  286. */
  287. U_STABLE void U_EXPORT2
  288. uregex_setText(URegularExpression *regexp,
  289. const UChar *text,
  290. int32_t textLength,
  291. UErrorCode *status);
  292. /**
  293. * Set the subject text string upon which the regular expression will look for matches.
  294. * This function may be called any number of times, allowing the regular
  295. * expression pattern to be applied to different strings.
  296. * <p>
  297. * Regular expression matching operations work directly on the application's
  298. * string data; only a shallow clone is made. The subject string data must not be
  299. * altered after calling this function until after all regular expression
  300. * operations involving this string data are completed.
  301. *
  302. * @param regexp The compiled regular expression.
  303. * @param text The subject text string.
  304. * @param status Receives errors detected by this function.
  305. *
  306. * @stable ICU 4.6
  307. */
  308. U_STABLE void U_EXPORT2
  309. uregex_setUText(URegularExpression *regexp,
  310. UText *text,
  311. UErrorCode *status);
  312. /**
  313. * Get the subject text that is currently associated with this
  314. * regular expression object. If the input was supplied using uregex_setText(),
  315. * that pointer will be returned. Otherwise, the characters in the input will
  316. * be extracted to a buffer and returned. In either case, ownership remains
  317. * with the regular expression object.
  318. *
  319. * This function will work even if the input was originally specified as a UText.
  320. *
  321. * @param regexp The compiled regular expression.
  322. * @param textLength The length of the string is returned in this output parameter.
  323. * A NULL pointer may be used here if the
  324. * text length is not needed, as would be the case if
  325. * the text is known in advance to be a NUL terminated
  326. * string.
  327. * @param status Receives errors detected by this function.
  328. * @return Pointer to the subject text string currently associated with
  329. * this regular expression.
  330. * @stable ICU 3.0
  331. */
  332. U_STABLE const UChar * U_EXPORT2
  333. uregex_getText(URegularExpression *regexp,
  334. int32_t *textLength,
  335. UErrorCode *status);
  336. /**
  337. * Get the subject text that is currently associated with this
  338. * regular expression object.
  339. *
  340. * This function will work even if the input was originally specified as a UChar string.
  341. *
  342. * @param regexp The compiled regular expression.
  343. * @param dest A mutable UText in which to store the current input.
  344. * If NULL, a new UText will be created as an immutable shallow clone
  345. * of the actual input string.
  346. * @param status Receives errors detected by this function.
  347. * @return The subject text currently associated with this regular expression.
  348. * If a pre-allocated UText was provided, it will always be used and returned.
  349. *
  350. * @stable ICU 4.6
  351. */
  352. U_STABLE UText * U_EXPORT2
  353. uregex_getUText(URegularExpression *regexp,
  354. UText *dest,
  355. UErrorCode *status);
  356. /**
  357. * Set the subject text string upon which the regular expression is looking for matches
  358. * without changing any other aspect of the matching state.
  359. * The new and previous text strings must have the same content.
  360. *
  361. * This function is intended for use in environments where ICU is operating on
  362. * strings that may move around in memory. It provides a mechanism for notifying
  363. * ICU that the string has been relocated, and providing a new UText to access the
  364. * string in its new position.
  365. *
  366. * Note that the regular expression implementation never copies the underlying text
  367. * of a string being matched, but always operates directly on the original text
  368. * provided by the user. Refreshing simply drops the references to the old text
  369. * and replaces them with references to the new.
  370. *
  371. * Caution: this function is normally used only by very specialized
  372. * system-level code. One example use case is with garbage collection
  373. * that moves the text in memory.
  374. *
  375. * @param regexp The compiled regular expression.
  376. * @param text The new (moved) text string.
  377. * @param status Receives errors detected by this function.
  378. *
  379. * @stable ICU 4.8
  380. */
  381. U_STABLE void U_EXPORT2
  382. uregex_refreshUText(URegularExpression *regexp,
  383. UText *text,
  384. UErrorCode *status);
  385. /**
  386. * Attempts to match the input string against the pattern.
  387. * To succeed, the match must extend to the end of the string,
  388. * or cover the complete match region.
  389. *
  390. * If startIndex >= zero the match operation starts at the specified
  391. * index and must extend to the end of the input string. Any region
  392. * that has been specified is reset.
  393. *
  394. * If startIndex == -1 the match must cover the input region, or the entire
  395. * input string if no region has been set. This directly corresponds to
  396. * Matcher.matches() in Java
  397. *
  398. * @param regexp The compiled regular expression.
  399. * @param startIndex The input string (native) index at which to begin matching, or -1
  400. * to match the input Region.
  401. * @param status Receives errors detected by this function.
  402. * @return TRUE if there is a match
  403. * @stable ICU 3.0
  404. */
  405. U_STABLE UBool U_EXPORT2
  406. uregex_matches(URegularExpression *regexp,
  407. int32_t startIndex,
  408. UErrorCode *status);
  409. /**
  410. * 64bit version of uregex_matches.
  411. * Attempts to match the input string against the pattern.
  412. * To succeed, the match must extend to the end of the string,
  413. * or cover the complete match region.
  414. *
  415. * If startIndex >= zero the match operation starts at the specified
  416. * index and must extend to the end of the input string. Any region
  417. * that has been specified is reset.
  418. *
  419. * If startIndex == -1 the match must cover the input region, or the entire
  420. * input string if no region has been set. This directly corresponds to
  421. * Matcher.matches() in Java
  422. *
  423. * @param regexp The compiled regular expression.
  424. * @param startIndex The input string (native) index at which to begin matching, or -1
  425. * to match the input Region.
  426. * @param status Receives errors detected by this function.
  427. * @return TRUE if there is a match
  428. * @stable ICU 4.6
  429. */
  430. U_STABLE UBool U_EXPORT2
  431. uregex_matches64(URegularExpression *regexp,
  432. int64_t startIndex,
  433. UErrorCode *status);
  434. /**
  435. * Attempts to match the input string, starting from the specified index, against the pattern.
  436. * The match may be of any length, and is not required to extend to the end
  437. * of the input string. Contrast with uregex_matches().
  438. *
  439. * <p>If startIndex is >= 0 any input region that was set for this
  440. * URegularExpression is reset before the operation begins.
  441. *
  442. * <p>If the specified starting index == -1 the match begins at the start of the input
  443. * region, or at the start of the full string if no region has been specified.
  444. * This corresponds directly with Matcher.lookingAt() in Java.
  445. *
  446. * <p>If the match succeeds then more information can be obtained via the
  447. * <code>uregexp_start()</code>, <code>uregexp_end()</code>,
  448. * and <code>uregex_group()</code> functions.</p>
  449. *
  450. * @param regexp The compiled regular expression.
  451. * @param startIndex The input string (native) index at which to begin matching, or
  452. * -1 to match the Input Region
  453. * @param status A reference to a UErrorCode to receive any errors.
  454. * @return TRUE if there is a match.
  455. * @stable ICU 3.0
  456. */
  457. U_STABLE UBool U_EXPORT2
  458. uregex_lookingAt(URegularExpression *regexp,
  459. int32_t startIndex,
  460. UErrorCode *status);
  461. /**
  462. * 64bit version of uregex_lookingAt.
  463. * Attempts to match the input string, starting from the specified index, against the pattern.
  464. * The match may be of any length, and is not required to extend to the end
  465. * of the input string. Contrast with uregex_matches().
  466. *
  467. * <p>If startIndex is >= 0 any input region that was set for this
  468. * URegularExpression is reset before the operation begins.
  469. *
  470. * <p>If the specified starting index == -1 the match begins at the start of the input
  471. * region, or at the start of the full string if no region has been specified.
  472. * This corresponds directly with Matcher.lookingAt() in Java.
  473. *
  474. * <p>If the match succeeds then more information can be obtained via the
  475. * <code>uregexp_start()</code>, <code>uregexp_end()</code>,
  476. * and <code>uregex_group()</code> functions.</p>
  477. *
  478. * @param regexp The compiled regular expression.
  479. * @param startIndex The input string (native) index at which to begin matching, or
  480. * -1 to match the Input Region
  481. * @param status A reference to a UErrorCode to receive any errors.
  482. * @return TRUE if there is a match.
  483. * @stable ICU 4.6
  484. */
  485. U_STABLE UBool U_EXPORT2
  486. uregex_lookingAt64(URegularExpression *regexp,
  487. int64_t startIndex,
  488. UErrorCode *status);
  489. /**
  490. * Find the first matching substring of the input string that matches the pattern.
  491. * If startIndex is >= zero the search for a match begins at the specified index,
  492. * and any match region is reset. This corresponds directly with
  493. * Matcher.find(startIndex) in Java.
  494. *
  495. * If startIndex == -1 the search begins at the start of the input region,
  496. * or at the start of the full string if no region has been specified.
  497. *
  498. * If a match is found, <code>uregex_start(), uregex_end()</code>, and
  499. * <code>uregex_group()</code> will provide more information regarding the match.
  500. *
  501. * @param regexp The compiled regular expression.
  502. * @param startIndex The position (native) in the input string to begin the search, or
  503. * -1 to search within the Input Region.
  504. * @param status A reference to a UErrorCode to receive any errors.
  505. * @return TRUE if a match is found.
  506. * @stable ICU 3.0
  507. */
  508. U_STABLE UBool U_EXPORT2
  509. uregex_find(URegularExpression *regexp,
  510. int32_t startIndex,
  511. UErrorCode *status);
  512. /**
  513. * 64bit version of uregex_find.
  514. * Find the first matching substring of the input string that matches the pattern.
  515. * If startIndex is >= zero the search for a match begins at the specified index,
  516. * and any match region is reset. This corresponds directly with
  517. * Matcher.find(startIndex) in Java.
  518. *
  519. * If startIndex == -1 the search begins at the start of the input region,
  520. * or at the start of the full string if no region has been specified.
  521. *
  522. * If a match is found, <code>uregex_start(), uregex_end()</code>, and
  523. * <code>uregex_group()</code> will provide more information regarding the match.
  524. *
  525. * @param regexp The compiled regular expression.
  526. * @param startIndex The position (native) in the input string to begin the search, or
  527. * -1 to search within the Input Region.
  528. * @param status A reference to a UErrorCode to receive any errors.
  529. * @return TRUE if a match is found.
  530. * @stable ICU 4.6
  531. */
  532. U_STABLE UBool U_EXPORT2
  533. uregex_find64(URegularExpression *regexp,
  534. int64_t startIndex,
  535. UErrorCode *status);
  536. /**
  537. * Find the next pattern match in the input string. Begin searching
  538. * the input at the location following the end of he previous match,
  539. * or at the start of the string (or region) if there is no
  540. * previous match. If a match is found, <code>uregex_start(), uregex_end()</code>, and
  541. * <code>uregex_group()</code> will provide more information regarding the match.
  542. *
  543. * @param regexp The compiled regular expression.
  544. * @param status A reference to a UErrorCode to receive any errors.
  545. * @return TRUE if a match is found.
  546. * @see uregex_reset
  547. * @stable ICU 3.0
  548. */
  549. U_STABLE UBool U_EXPORT2
  550. uregex_findNext(URegularExpression *regexp,
  551. UErrorCode *status);
  552. /**
  553. * Get the number of capturing groups in this regular expression's pattern.
  554. * @param regexp The compiled regular expression.
  555. * @param status A reference to a UErrorCode to receive any errors.
  556. * @return the number of capture groups
  557. * @stable ICU 3.0
  558. */
  559. U_STABLE int32_t U_EXPORT2
  560. uregex_groupCount(URegularExpression *regexp,
  561. UErrorCode *status);
  562. /**
  563. * Get the group number corresponding to a named capture group.
  564. * The returned number can be used with any function that access
  565. * capture groups by number.
  566. *
  567. * The function returns an error status if the specified name does not
  568. * appear in the pattern.
  569. *
  570. * @param regexp The compiled regular expression.
  571. * @param groupName The capture group name.
  572. * @param nameLength The length of the name, or -1 if the name is a
  573. * nul-terminated string.
  574. * @param status A pointer to a UErrorCode to receive any errors.
  575. *
  576. * @stable ICU 55
  577. */
  578. U_STABLE int32_t U_EXPORT2
  579. uregex_groupNumberFromName(URegularExpression *regexp,
  580. const UChar *groupName,
  581. int32_t nameLength,
  582. UErrorCode *status);
  583. /**
  584. * Get the group number corresponding to a named capture group.
  585. * The returned number can be used with any function that access
  586. * capture groups by number.
  587. *
  588. * The function returns an error status if the specified name does not
  589. * appear in the pattern.
  590. *
  591. * @param regexp The compiled regular expression.
  592. * @param groupName The capture group name,
  593. * platform invariant characters only.
  594. * @param nameLength The length of the name, or -1 if the name is
  595. * nul-terminated.
  596. * @param status A pointer to a UErrorCode to receive any errors.
  597. *
  598. * @stable ICU 55
  599. */
  600. U_STABLE int32_t U_EXPORT2
  601. uregex_groupNumberFromCName(URegularExpression *regexp,
  602. const char *groupName,
  603. int32_t nameLength,
  604. UErrorCode *status);
  605. /** Extract the string for the specified matching expression or subexpression.
  606. * Group #0 is the complete string of matched text.
  607. * Group #1 is the text matched by the first set of capturing parentheses.
  608. *
  609. * @param regexp The compiled regular expression.
  610. * @param groupNum The capture group to extract. Group 0 is the complete
  611. * match. The value of this parameter must be
  612. * less than or equal to the number of capture groups in
  613. * the pattern.
  614. * @param dest Buffer to receive the matching string data
  615. * @param destCapacity Capacity of the dest buffer.
  616. * @param status A reference to a UErrorCode to receive any errors.
  617. * @return Length of matching data,
  618. * or -1 if no applicable match.
  619. * @stable ICU 3.0
  620. */
  621. U_STABLE int32_t U_EXPORT2
  622. uregex_group(URegularExpression *regexp,
  623. int32_t groupNum,
  624. UChar *dest,
  625. int32_t destCapacity,
  626. UErrorCode *status);
  627. /** Returns a shallow immutable clone of the entire input string with the current index set
  628. * to the beginning of the requested capture group. The capture group length is also
  629. * returned via groupLength.
  630. * Group #0 is the complete string of matched text.
  631. * Group #1 is the text matched by the first set of capturing parentheses.
  632. *
  633. * @param regexp The compiled regular expression.
  634. * @param groupNum The capture group to extract. Group 0 is the complete
  635. * match. The value of this parameter must be
  636. * less than or equal to the number of capture groups in
  637. * the pattern.
  638. * @param dest A mutable UText in which to store the current input.
  639. * If NULL, a new UText will be created as an immutable shallow clone
  640. * of the entire input string.
  641. * @param groupLength The group length of the desired capture group. Output parameter.
  642. * @param status A reference to a UErrorCode to receive any errors.
  643. * @return The subject text currently associated with this regular expression.
  644. * If a pre-allocated UText was provided, it will always be used and returned.
  645. *
  646. * @stable ICU 4.6
  647. */
  648. U_STABLE UText * U_EXPORT2
  649. uregex_groupUText(URegularExpression *regexp,
  650. int32_t groupNum,
  651. UText *dest,
  652. int64_t *groupLength,
  653. UErrorCode *status);
  654. /**
  655. * Returns the index in the input string of the start of the text matched by the
  656. * specified capture group during the previous match operation. Return -1 if
  657. * the capture group was not part of the last match.
  658. * Group #0 refers to the complete range of matched text.
  659. * Group #1 refers to the text matched by the first set of capturing parentheses.
  660. *
  661. * @param regexp The compiled regular expression.
  662. * @param groupNum The capture group number
  663. * @param status A reference to a UErrorCode to receive any errors.
  664. * @return the starting (native) position in the input of the text matched
  665. * by the specified group.
  666. * @stable ICU 3.0
  667. */
  668. U_STABLE int32_t U_EXPORT2
  669. uregex_start(URegularExpression *regexp,
  670. int32_t groupNum,
  671. UErrorCode *status);
  672. /**
  673. * 64bit version of uregex_start.
  674. * Returns the index in the input string of the start of the text matched by the
  675. * specified capture group during the previous match operation. Return -1 if
  676. * the capture group was not part of the last match.
  677. * Group #0 refers to the complete range of matched text.
  678. * Group #1 refers to the text matched by the first set of capturing parentheses.
  679. *
  680. * @param regexp The compiled regular expression.
  681. * @param groupNum The capture group number
  682. * @param status A reference to a UErrorCode to receive any errors.
  683. * @return the starting (native) position in the input of the text matched
  684. * by the specified group.
  685. * @stable ICU 4.6
  686. */
  687. U_STABLE int64_t U_EXPORT2
  688. uregex_start64(URegularExpression *regexp,
  689. int32_t groupNum,
  690. UErrorCode *status);
  691. /**
  692. * Returns the index in the input string of the position following the end
  693. * of the text matched by the specified capture group.
  694. * Return -1 if the capture group was not part of the last match.
  695. * Group #0 refers to the complete range of matched text.
  696. * Group #1 refers to the text matched by the first set of capturing parentheses.
  697. *
  698. * @param regexp The compiled regular expression.
  699. * @param groupNum The capture group number
  700. * @param status A reference to a UErrorCode to receive any errors.
  701. * @return the (native) index of the position following the last matched character.
  702. * @stable ICU 3.0
  703. */
  704. U_STABLE int32_t U_EXPORT2
  705. uregex_end(URegularExpression *regexp,
  706. int32_t groupNum,
  707. UErrorCode *status);
  708. /**
  709. * 64bit version of uregex_end.
  710. * Returns the index in the input string of the position following the end
  711. * of the text matched by the specified capture group.
  712. * Return -1 if the capture group was not part of the last match.
  713. * Group #0 refers to the complete range of matched text.
  714. * Group #1 refers to the text matched by the first set of capturing parentheses.
  715. *
  716. * @param regexp The compiled regular expression.
  717. * @param groupNum The capture group number
  718. * @param status A reference to a UErrorCode to receive any errors.
  719. * @return the (native) index of the position following the last matched character.
  720. * @stable ICU 4.6
  721. */
  722. U_STABLE int64_t U_EXPORT2
  723. uregex_end64(URegularExpression *regexp,
  724. int32_t groupNum,
  725. UErrorCode *status);
  726. /**
  727. * Reset any saved state from the previous match. Has the effect of
  728. * causing uregex_findNext to begin at the specified index, and causing
  729. * uregex_start(), uregex_end() and uregex_group() to return an error
  730. * indicating that there is no match information available. Clears any
  731. * match region that may have been set.
  732. *
  733. * @param regexp The compiled regular expression.
  734. * @param index The position (native) in the text at which a
  735. * uregex_findNext() should begin searching.
  736. * @param status A reference to a UErrorCode to receive any errors.
  737. * @stable ICU 3.0
  738. */
  739. U_STABLE void U_EXPORT2
  740. uregex_reset(URegularExpression *regexp,
  741. int32_t index,
  742. UErrorCode *status);
  743. /**
  744. * 64bit version of uregex_reset.
  745. * Reset any saved state from the previous match. Has the effect of
  746. * causing uregex_findNext to begin at the specified index, and causing
  747. * uregex_start(), uregex_end() and uregex_group() to return an error
  748. * indicating that there is no match information available. Clears any
  749. * match region that may have been set.
  750. *
  751. * @param regexp The compiled regular expression.
  752. * @param index The position (native) in the text at which a
  753. * uregex_findNext() should begin searching.
  754. * @param status A reference to a UErrorCode to receive any errors.
  755. * @stable ICU 4.6
  756. */
  757. U_STABLE void U_EXPORT2
  758. uregex_reset64(URegularExpression *regexp,
  759. int64_t index,
  760. UErrorCode *status);
  761. /**
  762. * Sets the limits of the matching region for this URegularExpression.
  763. * The region is the part of the input string that will be considered when matching.
  764. * Invoking this method resets any saved state from the previous match,
  765. * then sets the region to start at the index specified by the start parameter
  766. * and end at the index specified by the end parameter.
  767. *
  768. * Depending on the transparency and anchoring being used (see useTransparentBounds
  769. * and useAnchoringBounds), certain constructs such as anchors may behave differently
  770. * at or around the boundaries of the region
  771. *
  772. * The function will fail if start is greater than limit, or if either index
  773. * is less than zero or greater than the length of the string being matched.
  774. *
  775. * @param regexp The compiled regular expression.
  776. * @param regionStart The (native) index to begin searches at.
  777. * @param regionLimit The (native) index to end searches at (exclusive).
  778. * @param status A pointer to a UErrorCode to receive any errors.
  779. * @stable ICU 4.0
  780. */
  781. U_STABLE void U_EXPORT2
  782. uregex_setRegion(URegularExpression *regexp,
  783. int32_t regionStart,
  784. int32_t regionLimit,
  785. UErrorCode *status);
  786. /**
  787. * 64bit version of uregex_setRegion.
  788. * Sets the limits of the matching region for this URegularExpression.
  789. * The region is the part of the input string that will be considered when matching.
  790. * Invoking this method resets any saved state from the previous match,
  791. * then sets the region to start at the index specified by the start parameter
  792. * and end at the index specified by the end parameter.
  793. *
  794. * Depending on the transparency and anchoring being used (see useTransparentBounds
  795. * and useAnchoringBounds), certain constructs such as anchors may behave differently
  796. * at or around the boundaries of the region
  797. *
  798. * The function will fail if start is greater than limit, or if either index
  799. * is less than zero or greater than the length of the string being matched.
  800. *
  801. * @param regexp The compiled regular expression.
  802. * @param regionStart The (native) index to begin searches at.
  803. * @param regionLimit The (native) index to end searches at (exclusive).
  804. * @param status A pointer to a UErrorCode to receive any errors.
  805. * @stable ICU 4.6
  806. */
  807. U_STABLE void U_EXPORT2
  808. uregex_setRegion64(URegularExpression *regexp,
  809. int64_t regionStart,
  810. int64_t regionLimit,
  811. UErrorCode *status);
  812. /**
  813. * Set the matching region and the starting index for subsequent matches
  814. * in a single operation.
  815. * This is useful because the usual function for setting the starting
  816. * index, urgex_reset(), also resets any region limits.
  817. *
  818. * @param regexp The compiled regular expression.
  819. * @param regionStart The (native) index to begin searches at.
  820. * @param regionLimit The (native) index to end searches at (exclusive).
  821. * @param startIndex The index in the input text at which the next
  822. * match operation should begin.
  823. * @param status A pointer to a UErrorCode to receive any errors.
  824. * @stable ICU 4.6
  825. */
  826. U_STABLE void U_EXPORT2
  827. uregex_setRegionAndStart(URegularExpression *regexp,
  828. int64_t regionStart,
  829. int64_t regionLimit,
  830. int64_t startIndex,
  831. UErrorCode *status);
  832. /**
  833. * Reports the start index of the matching region. Any matches found are limited to
  834. * to the region bounded by regionStart (inclusive) and regionEnd (exclusive).
  835. *
  836. * @param regexp The compiled regular expression.
  837. * @param status A pointer to a UErrorCode to receive any errors.
  838. * @return The starting (native) index of this matcher's region.
  839. * @stable ICU 4.0
  840. */
  841. U_STABLE int32_t U_EXPORT2
  842. uregex_regionStart(const URegularExpression *regexp,
  843. UErrorCode *status);
  844. /**
  845. * 64bit version of uregex_regionStart.
  846. * Reports the start index of the matching region. Any matches found are limited to
  847. * to the region bounded by regionStart (inclusive) and regionEnd (exclusive).
  848. *
  849. * @param regexp The compiled regular expression.
  850. * @param status A pointer to a UErrorCode to receive any errors.
  851. * @return The starting (native) index of this matcher's region.
  852. * @stable ICU 4.6
  853. */
  854. U_STABLE int64_t U_EXPORT2
  855. uregex_regionStart64(const URegularExpression *regexp,
  856. UErrorCode *status);
  857. /**
  858. * Reports the end index (exclusive) of the matching region for this URegularExpression.
  859. * Any matches found are limited to to the region bounded by regionStart (inclusive)
  860. * and regionEnd (exclusive).
  861. *
  862. * @param regexp The compiled regular expression.
  863. * @param status A pointer to a UErrorCode to receive any errors.
  864. * @return The ending point (native) of this matcher's region.
  865. * @stable ICU 4.0
  866. */
  867. U_STABLE int32_t U_EXPORT2
  868. uregex_regionEnd(const URegularExpression *regexp,
  869. UErrorCode *status);
  870. /**
  871. * 64bit version of uregex_regionEnd.
  872. * Reports the end index (exclusive) of the matching region for this URegularExpression.
  873. * Any matches found are limited to to the region bounded by regionStart (inclusive)
  874. * and regionEnd (exclusive).
  875. *
  876. * @param regexp The compiled regular expression.
  877. * @param status A pointer to a UErrorCode to receive any errors.
  878. * @return The ending point (native) of this matcher's region.
  879. * @stable ICU 4.6
  880. */
  881. U_STABLE int64_t U_EXPORT2
  882. uregex_regionEnd64(const URegularExpression *regexp,
  883. UErrorCode *status);
  884. /**
  885. * Queries the transparency of region bounds for this URegularExpression.
  886. * See useTransparentBounds for a description of transparent and opaque bounds.
  887. * By default, matching boundaries are opaque.
  888. *
  889. * @param regexp The compiled regular expression.
  890. * @param status A pointer to a UErrorCode to receive any errors.
  891. * @return TRUE if this matcher is using opaque bounds, false if it is not.
  892. * @stable ICU 4.0
  893. */
  894. U_STABLE UBool U_EXPORT2
  895. uregex_hasTransparentBounds(const URegularExpression *regexp,
  896. UErrorCode *status);
  897. /**
  898. * Sets the transparency of region bounds for this URegularExpression.
  899. * Invoking this function with an argument of TRUE will set matches to use transparent bounds.
  900. * If the boolean argument is FALSE, then opaque bounds will be used.
  901. *
  902. * Using transparent bounds, the boundaries of the matching region are transparent
  903. * to lookahead, lookbehind, and boundary matching constructs. Those constructs can
  904. * see text beyond the boundaries of the region while checking for a match.
  905. *
  906. * With opaque bounds, no text outside of the matching region is visible to lookahead,
  907. * lookbehind, and boundary matching constructs.
  908. *
  909. * By default, opaque bounds are used.
  910. *
  911. * @param regexp The compiled regular expression.
  912. * @param b TRUE for transparent bounds; FALSE for opaque bounds
  913. * @param status A pointer to a UErrorCode to receive any errors.
  914. * @stable ICU 4.0
  915. **/
  916. U_STABLE void U_EXPORT2
  917. uregex_useTransparentBounds(URegularExpression *regexp,
  918. UBool b,
  919. UErrorCode *status);
  920. /**
  921. * Return true if this URegularExpression is using anchoring bounds.
  922. * By default, anchoring region bounds are used.
  923. *
  924. * @param regexp The compiled regular expression.
  925. * @param status A pointer to a UErrorCode to receive any errors.
  926. * @return TRUE if this matcher is using anchoring bounds.
  927. * @stable ICU 4.0
  928. */
  929. U_STABLE UBool U_EXPORT2
  930. uregex_hasAnchoringBounds(const URegularExpression *regexp,
  931. UErrorCode *status);
  932. /**
  933. * Set whether this URegularExpression is using Anchoring Bounds for its region.
  934. * With anchoring bounds, pattern anchors such as ^ and $ will match at the start
  935. * and end of the region. Without Anchoring Bounds, anchors will only match at
  936. * the positions they would in the complete text.
  937. *
  938. * Anchoring Bounds are the default for regions.
  939. *
  940. * @param regexp The compiled regular expression.
  941. * @param b TRUE if to enable anchoring bounds; FALSE to disable them.
  942. * @param status A pointer to a UErrorCode to receive any errors.
  943. * @stable ICU 4.0
  944. */
  945. U_STABLE void U_EXPORT2
  946. uregex_useAnchoringBounds(URegularExpression *regexp,
  947. UBool b,
  948. UErrorCode *status);
  949. /**
  950. * Return TRUE if the most recent matching operation touched the
  951. * end of the text being processed. In this case, additional input text could
  952. * change the results of that match.
  953. *
  954. * @param regexp The compiled regular expression.
  955. * @param status A pointer to a UErrorCode to receive any errors.
  956. * @return TRUE if the most recent match hit the end of input
  957. * @stable ICU 4.0
  958. */
  959. U_STABLE UBool U_EXPORT2
  960. uregex_hitEnd(const URegularExpression *regexp,
  961. UErrorCode *status);
  962. /**
  963. * Return TRUE the most recent match succeeded and additional input could cause
  964. * it to fail. If this function returns false and a match was found, then more input
  965. * might change the match but the match won't be lost. If a match was not found,
  966. * then requireEnd has no meaning.
  967. *
  968. * @param regexp The compiled regular expression.
  969. * @param status A pointer to a UErrorCode to receive any errors.
  970. * @return TRUE if more input could cause the most recent match to no longer match.
  971. * @stable ICU 4.0
  972. */
  973. U_STABLE UBool U_EXPORT2
  974. uregex_requireEnd(const URegularExpression *regexp,
  975. UErrorCode *status);
  976. /**
  977. * Replaces every substring of the input that matches the pattern
  978. * with the given replacement string. This is a convenience function that
  979. * provides a complete find-and-replace-all operation.
  980. *
  981. * This method scans the input string looking for matches of the pattern.
  982. * Input that is not part of any match is copied unchanged to the
  983. * destination buffer. Matched regions are replaced in the output
  984. * buffer by the replacement string. The replacement string may contain
  985. * references to capture groups; these take the form of $1, $2, etc.
  986. *
  987. * @param regexp The compiled regular expression.
  988. * @param replacementText A string containing the replacement text.
  989. * @param replacementLength The length of the replacement string, or
  990. * -1 if it is NUL terminated.
  991. * @param destBuf A (UChar *) buffer that will receive the result.
  992. * @param destCapacity The capacity of the destination buffer.
  993. * @param status A reference to a UErrorCode to receive any errors.
  994. * @return The length of the string resulting from the find
  995. * and replace operation. In the event that the
  996. * destination capacity is inadequate, the return value
  997. * is still the full length of the untruncated string.
  998. * @stable ICU 3.0
  999. */
  1000. U_STABLE int32_t U_EXPORT2
  1001. uregex_replaceAll(URegularExpression *regexp,
  1002. const UChar *replacementText,
  1003. int32_t replacementLength,
  1004. UChar *destBuf,
  1005. int32_t destCapacity,
  1006. UErrorCode *status);
  1007. /**
  1008. * Replaces every substring of the input that matches the pattern
  1009. * with the given replacement string. This is a convenience function that
  1010. * provides a complete find-and-replace-all operation.
  1011. *
  1012. * This method scans the input string looking for matches of the pattern.
  1013. * Input that is not part of any match is copied unchanged to the
  1014. * destination buffer. Matched regions are replaced in the output
  1015. * buffer by the replacement string. The replacement string may contain
  1016. * references to capture groups; these take the form of $1, $2, etc.
  1017. *
  1018. * @param regexp The compiled regular expression.
  1019. * @param replacement A string containing the replacement text.
  1020. * @param dest A mutable UText that will receive the result.
  1021. * If NULL, a new UText will be created (which may not be mutable).
  1022. * @param status A reference to a UErrorCode to receive any errors.
  1023. * @return A UText containing the results of the find and replace.
  1024. * If a pre-allocated UText was provided, it will always be used and returned.
  1025. *
  1026. * @stable ICU 4.6
  1027. */
  1028. U_STABLE UText * U_EXPORT2
  1029. uregex_replaceAllUText(URegularExpression *regexp,
  1030. UText *replacement,
  1031. UText *dest,
  1032. UErrorCode *status);
  1033. /**
  1034. * Replaces the first substring of the input that matches the pattern
  1035. * with the given replacement string. This is a convenience function that
  1036. * provides a complete find-and-replace operation.
  1037. *
  1038. * This method scans the input string looking for a match of the pattern.
  1039. * All input that is not part of the match is copied unchanged to the
  1040. * destination buffer. The matched region is replaced in the output
  1041. * buffer by the replacement string. The replacement string may contain
  1042. * references to capture groups; these take the form of $1, $2, etc.
  1043. *
  1044. * @param regexp The compiled regular expression.
  1045. * @param replacementText A string containing the replacement text.
  1046. * @param replacementLength The length of the replacement string, or
  1047. * -1 if it is NUL terminated.
  1048. * @param destBuf A (UChar *) buffer that will receive the result.
  1049. * @param destCapacity The capacity of the destination buffer.
  1050. * @param status a reference to a UErrorCode to receive any errors.
  1051. * @return The length of the string resulting from the find
  1052. * and replace operation. In the event that the
  1053. * destination capacity is inadequate, the return value
  1054. * is still the full length of the untruncated string.
  1055. * @stable ICU 3.0
  1056. */
  1057. U_STABLE int32_t U_EXPORT2
  1058. uregex_replaceFirst(URegularExpression *regexp,
  1059. const UChar *replacementText,
  1060. int32_t replacementLength,
  1061. UChar *destBuf,
  1062. int32_t destCapacity,
  1063. UErrorCode *status);
  1064. /**
  1065. * Replaces the first substring of the input that matches the pattern
  1066. * with the given replacement string. This is a convenience function that
  1067. * provides a complete find-and-replace operation.
  1068. *
  1069. * This method scans the input string looking for a match of the pattern.
  1070. * All input that is not part of the match is copied unchanged to the
  1071. * destination buffer. The matched region is replaced in the output
  1072. * buffer by the replacement string. The replacement string may contain
  1073. * references to capture groups; these take the form of $1, $2, etc.
  1074. *
  1075. * @param regexp The compiled regular expression.
  1076. * @param replacement A string containing the replacement text.
  1077. * @param dest A mutable UText that will receive the result.
  1078. * If NULL, a new UText will be created (which may not be mutable).
  1079. * @param status A reference to a UErrorCode to receive any errors.
  1080. * @return A UText containing the results of the find and replace.
  1081. * If a pre-allocated UText was provided, it will always be used and returned.
  1082. *
  1083. * @stable ICU 4.6
  1084. */
  1085. U_STABLE UText * U_EXPORT2
  1086. uregex_replaceFirstUText(URegularExpression *regexp,
  1087. UText *replacement,
  1088. UText *dest,
  1089. UErrorCode *status);
  1090. /**
  1091. * Implements a replace operation intended to be used as part of an
  1092. * incremental find-and-replace.
  1093. *
  1094. * <p>The input string, starting from the end of the previous match and ending at
  1095. * the start of the current match, is appended to the destination string. Then the
  1096. * replacement string is appended to the output string,
  1097. * including handling any substitutions of captured text.</p>
  1098. *
  1099. * <p>A note on preflight computation of buffersize and error handling:
  1100. * Calls to uregex_appendReplacement() and uregex_appendTail() are
  1101. * designed to be chained, one after another, with the destination
  1102. * buffer pointer and buffer capacity updated after each in preparation
  1103. * to for the next. If the destination buffer is exhausted partway through such a
  1104. * sequence, a U_BUFFER_OVERFLOW_ERROR status will be returned. Normal
  1105. * ICU conventions are for a function to perform no action if it is
  1106. * called with an error status, but for this one case, uregex_appendRepacement()
  1107. * will operate normally so that buffer size computations will complete
  1108. * correctly.
  1109. *
  1110. * <p>For simple, prepackaged, non-incremental find-and-replace
  1111. * operations, see replaceFirst() or replaceAll().</p>
  1112. *
  1113. * @param regexp The regular expression object.
  1114. * @param replacementText The string that will replace the matched portion of the
  1115. * input string as it is copied to the destination buffer.
  1116. * The replacement text may contain references ($1, for
  1117. * example) to capture groups from the match.
  1118. * @param replacementLength The length of the replacement text string,
  1119. * or -1 if the string is NUL terminated.
  1120. * @param destBuf The buffer into which the results of the
  1121. * find-and-replace are placed. On return, this pointer
  1122. * will be updated to refer to the beginning of the
  1123. * unused portion of buffer, leaving it in position for
  1124. * a subsequent call to this function.
  1125. * @param destCapacity The size of the output buffer, On return, this
  1126. * parameter will be updated to reflect the space remaining
  1127. * unused in the output buffer.
  1128. * @param status A reference to a UErrorCode to receive any errors.
  1129. * @return The length of the result string. In the event that
  1130. * destCapacity is inadequate, the full length of the
  1131. * untruncated output string is returned.
  1132. *
  1133. * @stable ICU 3.0
  1134. *
  1135. */
  1136. U_STABLE int32_t U_EXPORT2
  1137. uregex_appendReplacement(URegularExpression *regexp,
  1138. const UChar *replacementText,
  1139. int32_t replacementLength,
  1140. UChar **destBuf,
  1141. int32_t *destCapacity,
  1142. UErrorCode *status);
  1143. /**
  1144. * Implements a replace operation intended to be used as part of an
  1145. * incremental find-and-replace.
  1146. *
  1147. * <p>The input string, starting from the end of the previous match and ending at
  1148. * the start of the current match, is appended to the destination string. Then the
  1149. * replacement string is appended to the output string,
  1150. * including handling any substitutions of captured text.</p>
  1151. *
  1152. * <p>For simple, prepackaged, non-incremental find-and-replace
  1153. * operations, see replaceFirst() or replaceAll().</p>
  1154. *
  1155. * @param regexp The regular expression object.
  1156. * @param replacementText The string that will replace the matched portion of the
  1157. * input string as it is copied to the destination buffer.
  1158. * The replacement text may contain references ($1, for
  1159. * example) to capture groups from the match.
  1160. * @param dest A mutable UText that will receive the result. Must not be NULL.
  1161. * @param status A reference to a UErrorCode to receive any errors.
  1162. *
  1163. * @stable ICU 4.6
  1164. */
  1165. U_STABLE void U_EXPORT2
  1166. uregex_appendReplacementUText(URegularExpression *regexp,
  1167. UText *replacementText,
  1168. UText *dest,
  1169. UErrorCode *status);
  1170. /**
  1171. * As the final step in a find-and-replace operation, append the remainder
  1172. * of the input string, starting at the position following the last match,
  1173. * to the destination string. <code>uregex_appendTail()</code> is intended
  1174. * to be invoked after one or more invocations of the
  1175. * <code>uregex_appendReplacement()</code> function.
  1176. *
  1177. * @param regexp The regular expression object. This is needed to
  1178. * obtain the input string and with the position
  1179. * of the last match within it.
  1180. * @param destBuf The buffer in which the results of the
  1181. * find-and-replace are placed. On return, the pointer
  1182. * will be updated to refer to the beginning of the
  1183. * unused portion of buffer.
  1184. * @param destCapacity The size of the output buffer, On return, this
  1185. * value will be updated to reflect the space remaining
  1186. * unused in the output buffer.
  1187. * @param status A reference to a UErrorCode to receive any errors.
  1188. * @return The length of the result string. In the event that
  1189. * destCapacity is inadequate, the full length of the
  1190. * untruncated output string is returned.
  1191. *
  1192. * @stable ICU 3.0
  1193. */
  1194. U_STABLE int32_t U_EXPORT2
  1195. uregex_appendTail(URegularExpression *regexp,
  1196. UChar **destBuf,
  1197. int32_t *destCapacity,
  1198. UErrorCode *status);
  1199. /**
  1200. * As the final step in a find-and-replace operation, append the remainder
  1201. * of the input string, starting at the position following the last match,
  1202. * to the destination string. <code>uregex_appendTailUText()</code> is intended
  1203. * to be invoked after one or more invocations of the
  1204. * <code>uregex_appendReplacementUText()</code> function.
  1205. *
  1206. * @param regexp The regular expression object. This is needed to
  1207. * obtain the input string and with the position
  1208. * of the last match within it.
  1209. * @param dest A mutable UText that will receive the result. Must not be NULL.
  1210. *
  1211. * @param status Error code
  1212. *
  1213. * @return The destination UText.
  1214. *
  1215. * @stable ICU 4.6
  1216. */
  1217. U_STABLE UText * U_EXPORT2
  1218. uregex_appendTailUText(URegularExpression *regexp,
  1219. UText *dest,
  1220. UErrorCode *status);
  1221. /**
  1222. * Split a string into fields. Somewhat like split() from Perl.
  1223. * The pattern matches identify delimiters that separate the input
  1224. * into fields. The input data between the matches becomes the
  1225. * fields themselves.
  1226. *
  1227. * Each of the fields is copied from the input string to the destination
  1228. * buffer, and NUL terminated. The position of each field within
  1229. * the destination buffer is returned in the destFields array.
  1230. *
  1231. * If the delimiter pattern includes capture groups, the captured text will
  1232. * also appear in the destination array of output strings, interspersed
  1233. * with the fields. This is similar to Perl, but differs from Java,
  1234. * which ignores the presence of capture groups in the pattern.
  1235. *
  1236. * Trailing empty fields will always be returned, assuming sufficient
  1237. * destination capacity. This differs from the default behavior for Java
  1238. * and Perl where trailing empty fields are not returned.
  1239. *
  1240. * The number of strings produced by the split operation is returned.
  1241. * This count includes the strings from capture groups in the delimiter pattern.
  1242. * This behavior differs from Java, which ignores capture groups.
  1243. *
  1244. * @param regexp The compiled regular expression.
  1245. * @param destBuf A (UChar *) buffer to receive the fields that
  1246. * are extracted from the input string. These
  1247. * field pointers will refer to positions within the
  1248. * destination buffer supplied by the caller. Any
  1249. * extra positions within the destFields array will be
  1250. * set to NULL.
  1251. * @param destCapacity The capacity of the destBuf.
  1252. * @param requiredCapacity The actual capacity required of the destBuf.
  1253. * If destCapacity is too small, requiredCapacity will return
  1254. * the total capacity required to hold all of the output, and
  1255. * a U_BUFFER_OVERFLOW_ERROR will be returned.
  1256. * @param destFields An array to be filled with the position of each
  1257. * of the extracted fields within destBuf.
  1258. * @param destFieldsCapacity The number of elements in the destFields array.
  1259. * If the number of fields found is less than destFieldsCapacity,
  1260. * the extra destFields elements are set to zero.
  1261. * If destFieldsCapacity is too small, the trailing part of the
  1262. * input, including any field delimiters, is treated as if it
  1263. * were the last field - it is copied to the destBuf, and
  1264. * its position is in the destBuf is stored in the last element
  1265. * of destFields. This behavior mimics that of Perl. It is not
  1266. * an error condition, and no error status is returned when all destField
  1267. * positions are used.
  1268. * @param status A reference to a UErrorCode to receive any errors.
  1269. * @return The number of fields into which the input string was split.
  1270. * @stable ICU 3.0
  1271. */
  1272. U_STABLE int32_t U_EXPORT2
  1273. uregex_split( URegularExpression *regexp,
  1274. UChar *destBuf,
  1275. int32_t destCapacity,
  1276. int32_t *requiredCapacity,
  1277. UChar *destFields[],
  1278. int32_t destFieldsCapacity,
  1279. UErrorCode *status);
  1280. /**
  1281. * Split a string into fields. Somewhat like split() from Perl.
  1282. * The pattern matches identify delimiters that separate the input
  1283. * into fields. The input data between the matches becomes the
  1284. * fields themselves.
  1285. * <p>
  1286. * The behavior of this function is not very closely aligned with uregex_split();
  1287. * instead, it is based on (and implemented directly on top of) the C++ split method.
  1288. *
  1289. * @param regexp The compiled regular expression.
  1290. * @param destFields An array of mutable UText structs to receive the results of the split.
  1291. * If a field is NULL, a new UText is allocated to contain the results for
  1292. * that field. This new UText is not guaranteed to be mutable.
  1293. * @param destFieldsCapacity The number of elements in the destination array.
  1294. * If the number of fields found is less than destCapacity, the
  1295. * extra strings in the destination array are not altered.
  1296. * If the number of destination strings is less than the number
  1297. * of fields, the trailing part of the input string, including any
  1298. * field delimiters, is placed in the last destination string.
  1299. * This behavior mimics that of Perl. It is not an error condition, and no
  1300. * error status is returned when all destField positions are used.
  1301. * @param status A reference to a UErrorCode to receive any errors.
  1302. * @return The number of fields into which the input string was split.
  1303. *
  1304. * @stable ICU 4.6
  1305. */
  1306. U_STABLE int32_t U_EXPORT2
  1307. uregex_splitUText(URegularExpression *regexp,
  1308. UText *destFields[],
  1309. int32_t destFieldsCapacity,
  1310. UErrorCode *status);
  1311. /**
  1312. * Set a processing time limit for match operations with this URegularExpression.
  1313. *
  1314. * Some patterns, when matching certain strings, can run in exponential time.
  1315. * For practical purposes, the match operation may appear to be in an
  1316. * infinite loop.
  1317. * When a limit is set a match operation will fail with an error if the
  1318. * limit is exceeded.
  1319. * <p>
  1320. * The units of the limit are steps of the match engine.
  1321. * Correspondence with actual processor time will depend on the speed
  1322. * of the processor and the details of the specific pattern, but will
  1323. * typically be on the order of milliseconds.
  1324. * <p>
  1325. * By default, the matching time is not limited.
  1326. * <p>
  1327. *
  1328. * @param regexp The compiled regular expression.
  1329. * @param limit The limit value, or 0 for no limit.
  1330. * @param status A reference to a UErrorCode to receive any errors.
  1331. * @stable ICU 4.0
  1332. */
  1333. U_STABLE void U_EXPORT2
  1334. uregex_setTimeLimit(URegularExpression *regexp,
  1335. int32_t limit,
  1336. UErrorCode *status);
  1337. /**
  1338. * Get the time limit for for matches with this URegularExpression.
  1339. * A return value of zero indicates that there is no limit.
  1340. *
  1341. * @param regexp The compiled regular expression.
  1342. * @param status A reference to a UErrorCode to receive any errors.
  1343. * @return the maximum allowed time for a match, in units of processing steps.
  1344. * @stable ICU 4.0
  1345. */
  1346. U_STABLE int32_t U_EXPORT2
  1347. uregex_getTimeLimit(const URegularExpression *regexp,
  1348. UErrorCode *status);
  1349. /**
  1350. * Set the amount of heap storage available for use by the match backtracking stack.
  1351. * <p>
  1352. * ICU uses a backtracking regular expression engine, with the backtrack stack
  1353. * maintained on the heap. This function sets the limit to the amount of memory
  1354. * that can be used for this purpose. A backtracking stack overflow will
  1355. * result in an error from the match operation that caused it.
  1356. * <p>
  1357. * A limit is desirable because a malicious or poorly designed pattern can use
  1358. * excessive memory, potentially crashing the process. A limit is enabled
  1359. * by default.
  1360. * <p>
  1361. * @param regexp The compiled regular expression.
  1362. * @param limit The maximum size, in bytes, of the matching backtrack stack.
  1363. * A value of zero means no limit.
  1364. * The limit must be greater than or equal to zero.
  1365. * @param status A reference to a UErrorCode to receive any errors.
  1366. *
  1367. * @stable ICU 4.0
  1368. */
  1369. U_STABLE void U_EXPORT2
  1370. uregex_setStackLimit(URegularExpression *regexp,
  1371. int32_t limit,
  1372. UErrorCode *status);
  1373. /**
  1374. * Get the size of the heap storage available for use by the back tracking stack.
  1375. *
  1376. * @return the maximum backtracking stack size, in bytes, or zero if the
  1377. * stack size is unlimited.
  1378. * @stable ICU 4.0
  1379. */
  1380. U_STABLE int32_t U_EXPORT2
  1381. uregex_getStackLimit(const URegularExpression *regexp,
  1382. UErrorCode *status);
  1383. /**
  1384. * Function pointer for a regular expression matching callback function.
  1385. * When set, a callback function will be called periodically during matching
  1386. * operations. If the call back function returns FALSE, the matching
  1387. * operation will be terminated early.
  1388. *
  1389. * Note: the callback function must not call other functions on this
  1390. * URegularExpression.
  1391. *
  1392. * @param context context pointer. The callback function will be invoked
  1393. * with the context specified at the time that
  1394. * uregex_setMatchCallback() is called.
  1395. * @param steps the accumulated processing time, in match steps,
  1396. * for this matching operation.
  1397. * @return TRUE to continue the matching operation.
  1398. * FALSE to terminate the matching operation.
  1399. * @stable ICU 4.0
  1400. */
  1401. U_CDECL_BEGIN
  1402. typedef UBool U_CALLCONV URegexMatchCallback (
  1403. const void *context,
  1404. int32_t steps);
  1405. U_CDECL_END
  1406. /**
  1407. * Set a callback function for this URegularExpression.
  1408. * During matching operations the function will be called periodically,
  1409. * giving the application the opportunity to terminate a long-running
  1410. * match.
  1411. *
  1412. * @param regexp The compiled regular expression.
  1413. * @param callback A pointer to the user-supplied callback function.
  1414. * @param context User context pointer. The value supplied at the
  1415. * time the callback function is set will be saved
  1416. * and passed to the callback each time that it is called.
  1417. * @param status A reference to a UErrorCode to receive any errors.
  1418. * @stable ICU 4.0
  1419. */
  1420. U_STABLE void U_EXPORT2
  1421. uregex_setMatchCallback(URegularExpression *regexp,
  1422. URegexMatchCallback *callback,
  1423. const void *context,
  1424. UErrorCode *status);
  1425. /**
  1426. * Get the callback function for this URegularExpression.
  1427. *
  1428. * @param regexp The compiled regular expression.
  1429. * @param callback Out parameter, receives a pointer to the user-supplied
  1430. * callback function.
  1431. * @param context Out parameter, receives the user context pointer that
  1432. * was set when uregex_setMatchCallback() was called.
  1433. * @param status A reference to a UErrorCode to receive any errors.
  1434. * @stable ICU 4.0
  1435. */
  1436. U_STABLE void U_EXPORT2
  1437. uregex_getMatchCallback(const URegularExpression *regexp,
  1438. URegexMatchCallback **callback,
  1439. const void **context,
  1440. UErrorCode *status);
  1441. /**
  1442. * Function pointer for a regular expression find callback function.
  1443. *
  1444. * When set, a callback function will be called during a find operation
  1445. * and for operations that depend on find, such as findNext, split and some replace
  1446. * operations like replaceFirst.
  1447. * The callback will usually be called after each attempt at a match, but this is not a
  1448. * guarantee that the callback will be invoked at each character. For finds where the
  1449. * match engine is invoked at each character, this may be close to true, but less likely
  1450. * for more optimized loops where the pattern is known to only start, and the match
  1451. * engine invoked, at certain characters.
  1452. * When invoked, this callback will specify the index at which a match operation is about
  1453. * to be attempted, giving the application the opportunity to terminate a long-running
  1454. * find operation.
  1455. *
  1456. * If the call back function returns FALSE, the find operation will be terminated early.
  1457. *
  1458. * Note: the callback function must not call other functions on this
  1459. * URegularExpression
  1460. *
  1461. * @param context context pointer. The callback function will be invoked
  1462. * with the context specified at the time that
  1463. * uregex_setFindProgressCallback() is called.
  1464. * @param matchIndex the next index at which a match attempt will be attempted for this
  1465. * find operation. If this callback interrupts the search, this is the
  1466. * index at which a find/findNext operation may be re-initiated.
  1467. * @return TRUE to continue the matching operation.
  1468. * FALSE to terminate the matching operation.
  1469. * @stable ICU 4.6
  1470. */
  1471. U_CDECL_BEGIN
  1472. typedef UBool U_CALLCONV URegexFindProgressCallback (
  1473. const void *context,
  1474. int64_t matchIndex);
  1475. U_CDECL_END
  1476. /**
  1477. * Set the find progress callback function for this URegularExpression.
  1478. *
  1479. * @param regexp The compiled regular expression.
  1480. * @param callback A pointer to the user-supplied callback function.
  1481. * @param context User context pointer. The value supplied at the
  1482. * time the callback function is set will be saved
  1483. * and passed to the callback each time that it is called.
  1484. * @param status A reference to a UErrorCode to receive any errors.
  1485. * @stable ICU 4.6
  1486. */
  1487. U_STABLE void U_EXPORT2
  1488. uregex_setFindProgressCallback(URegularExpression *regexp,
  1489. URegexFindProgressCallback *callback,
  1490. const void *context,
  1491. UErrorCode *status);
  1492. /**
  1493. * Get the find progress callback function for this URegularExpression.
  1494. *
  1495. * @param regexp The compiled regular expression.
  1496. * @param callback Out parameter, receives a pointer to the user-supplied
  1497. * callback function.
  1498. * @param context Out parameter, receives the user context pointer that
  1499. * was set when uregex_setFindProgressCallback() was called.
  1500. * @param status A reference to a UErrorCode to receive any errors.
  1501. * @stable ICU 4.6
  1502. */
  1503. U_STABLE void U_EXPORT2
  1504. uregex_getFindProgressCallback(const URegularExpression *regexp,
  1505. URegexFindProgressCallback **callback,
  1506. const void **context,
  1507. UErrorCode *status);
  1508. #endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */
  1509. #endif /* UREGEX_H */