-//------------------------------------------------------------------------------
-//
-// uregex_groupUTextDeep
-//
-//------------------------------------------------------------------------------
-U_CAPI UText * U_EXPORT2
-uregex_groupUTextDeep(URegularExpression *regexp2,
- int32_t groupNum,
- UText *dest,
- UErrorCode *status) {
- RegularExpression *regexp = (RegularExpression*)regexp2;
- if (validateRE(regexp, TRUE, status) == FALSE) {
- UErrorCode emptyTextStatus = U_ZERO_ERROR;
- return (dest ? dest : utext_openUChars(NULL, NULL, 0, &emptyTextStatus));
- }
-
- if (regexp->fText != NULL) {
- //
- // Pick up the range of characters from the matcher
- // and use our already-extracted characters
- //
- int32_t startIx = regexp->fMatcher->start(groupNum, *status);
- int32_t endIx = regexp->fMatcher->end (groupNum, *status);
- if (U_FAILURE(*status)) {
- UErrorCode emptyTextStatus = U_ZERO_ERROR;
- return (dest ? dest : utext_openUChars(NULL, NULL, 0, &emptyTextStatus));
- }
-
- if (dest) {
- utext_replace(dest, 0, utext_nativeLength(dest), ®exp->fText[startIx], endIx - startIx, status);
- } else {
- UText groupText = UTEXT_INITIALIZER;
- utext_openUChars(&groupText, ®exp->fText[startIx], endIx - startIx, status);
- dest = utext_clone(NULL, &groupText, TRUE, FALSE, status);
- utext_close(&groupText);
- }
-
- return dest;
- } else {
- return regexp->fMatcher->group(groupNum, dest, *status);
- }
-}
-