diff --git a/icu4c/source/i18n/unicode/uregex.h b/icu4c/source/i18n/unicode/uregex.h index b1b5d65d150..c6381ca1691 100644 --- a/icu4c/source/i18n/unicode/uregex.h +++ b/icu4c/source/i18n/unicode/uregex.h @@ -487,7 +487,7 @@ uregex_matches64(URegularExpression *regexp, * *

If the match succeeds then more information can be obtained via the * uregexp_start(), uregexp_end(), - * and uregexp_group() functions.

+ * and uregex_group() functions.

* * @param regexp The compiled regular expression. * @param startIndex The input string (native) index at which to begin matching, or @@ -516,7 +516,7 @@ uregex_lookingAt(URegularExpression *regexp, * *

If the match succeeds then more information can be obtained via the * uregexp_start(), uregexp_end(), - * and uregexp_group() functions.

+ * and uregex_group() functions.

* * @param regexp The compiled regular expression. * @param startIndex The input string (native) index at which to begin matching, or diff --git a/icu4c/source/test/intltest/regextst.cpp b/icu4c/source/test/intltest/regextst.cpp index c488e0e25db..bf13426041e 100644 --- a/icu4c/source/test/intltest/regextst.cpp +++ b/icu4c/source/test/intltest/regextst.cpp @@ -23,6 +23,10 @@ #include "intltest.h" #if !UCONFIG_NO_REGULAR_EXPRESSIONS +#include +#include +#include + #include "unicode/localpointer.h" #include "unicode/regex.h" #include "unicode/uchar.h" @@ -31,13 +35,12 @@ #include "unicode/uregex.h" #include "unicode/usetiter.h" #include "unicode/ustring.h" +#include "unicode/utext.h" + #include "regextst.h" #include "regexcmp.h" #include "uvector.h" #include "util.h" -#include -#include -#include #include "cmemory.h" #include "cstring.h" #include "uinvchar.h" @@ -5780,7 +5783,7 @@ void RegexTest::TestBug11371() { void RegexTest::TestBug11480() { // C API, get capture group of a group that does not participate in the match. // (Returns a zero length string, with nul termination, - // indistinguishable from a group with a zero lenght match.) + // indistinguishable from a group with a zero length match.) UErrorCode status = U_ZERO_ERROR; URegularExpression *re = uregex_openC("(A)|(B)", 0, NULL, &status); @@ -5796,6 +5799,29 @@ void RegexTest::TestBug11480() { REGEX_ASSERT(buf[1] == 0); REGEX_ASSERT(buf[2] == 13); uregex_close(re); + + // UText C++ API, length of match is 0 for non-participating matches. + UText ut = UTEXT_INITIALIZER; + utext_openUnicodeString(&ut, &text, &status); + RegexMatcher matcher(UnicodeString("(A)|(B)"), 0, status); + REGEX_CHECK_STATUS; + matcher.reset(&ut); + REGEX_ASSERT(matcher.lookingAt(0, status)); + + // UText C++ API, Capture group 1 matches "A", position 0, length 1. + int64_t groupLen = -666; + UText group = UTEXT_INITIALIZER; + matcher.group(1, &group, groupLen, status); + REGEX_CHECK_STATUS; + REGEX_ASSERT(groupLen == 1); + REGEX_ASSERT(utext_getNativeIndex(&group) == 0); + + // Capture group 2, the (B), does not participate in the match. + matcher.group(2, &group, groupLen, status); + REGEX_CHECK_STATUS; + REGEX_ASSERT(groupLen == 0); + REGEX_ASSERT(matcher.start(2, status) == -1); + REGEX_CHECK_STATUS; }