From 5e02c2eb16021f8a28026d772bcb2f9fe3b78d57 Mon Sep 17 00:00:00 2001 From: Syn Wee Quek Date: Wed, 15 May 2002 20:26:26 +0000 Subject: [PATCH] ICU-1897 Synching up comments and identical search function with Java X-SVN-Rev: 8636 --- icu4c/source/i18n/unicode/stsearch.h | 10 +++++----- icu4c/source/i18n/unicode/usearch.h | 4 ++-- icu4c/source/i18n/usearch.cpp | 25 ++++++++++++++++++++----- icu4c/source/test/cintltst/usrchdat.c | 2 ++ 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/icu4c/source/i18n/unicode/stsearch.h b/icu4c/source/i18n/unicode/stsearch.h index 36a815ad81a..901095ce820 100644 --- a/icu4c/source/i18n/unicode/stsearch.h +++ b/icu4c/source/i18n/unicode/stsearch.h @@ -22,7 +22,7 @@ U_NAMESPACE_BEGIN * in a {@link RuleBasedCollator} object. * StringSearch ensures that language eccentricity can be * handled, e.g. for the German collator, characters ß and SS will be matched - * if case is chosen to be ignored. + * if case is chosen to be ignored. * See the * "ICU Collation Design Document" for more information. *

@@ -107,10 +107,10 @@ U_NAMESPACE_BEGIN * UnicodeString target("The quick brown fox jumped over the lazy fox"); * UnicodeString pattern("fox"); * - * SearchIterator *iter = new StringSearch(pattern, target); - * - * for (int pos = iter->first(); pos != USEARCH_DONE; - * pos = iter->next()) { + * SearchIterator *iter = new StringSearch(pattern, target); + * UErrorCode error = U_ZERO_ERROR; + * for (int pos = iter->first(error); pos != USEARCH_DONE; + * pos = iter->next(error)) { * printf("Found match at %d pos, length is %d\n", pos, * iter.getMatchLength()); * } diff --git a/icu4c/source/i18n/unicode/usearch.h b/icu4c/source/i18n/unicode/usearch.h index 9009cd53a1c..e19c4053fd5 100644 --- a/icu4c/source/i18n/unicode/usearch.h +++ b/icu4c/source/i18n/unicode/usearch.h @@ -111,9 +111,9 @@ * UStringSearch *search = usearch_open(pattern, -1, target, -1, "en_US", * &status); * if (U_SUCCESS(status)) { - * for (int pos = usearch_first(search); + * for (int pos = usearch_first(search, &status); * pos != USEARCH_DONE; - * pos = usearch_next(search)) { + * pos = usearch_next(search, &status)) { * printf("Found match at %d pos, length is %d\n", pos, * usearch_getMatchLength(search)); * } diff --git a/icu4c/source/i18n/usearch.cpp b/icu4c/source/i18n/usearch.cpp index 4a831da8bf2..73bf39a63ea 100644 --- a/icu4c/source/i18n/usearch.cpp +++ b/icu4c/source/i18n/usearch.cpp @@ -861,12 +861,27 @@ inline UBool checkIdentical(const UStringSearch *strsrch, int32_t start, return TRUE; } - if (strsrch->pattern.textLength != length) { - return FALSE; + UErrorCode status = U_ZERO_ERROR; + int decomplength = unorm_decompose(NULL, -1, + strsrch->search->text + start, length, + FALSE, FALSE, &status); + if (decomplength != unorm_decompose(NULL, -1, strsrch->pattern.text, + strsrch->pattern.textLength, FALSE, + FALSE, &status)) { + return false; } - - return (uprv_memcmp(strsrch->pattern.text, strsrch->search->text + start, - length * sizeof(UChar)) == 0); + decomplength ++; + UChar *text = (UChar *)uprv_malloc(decomplength * sizeof(UChar)); + UChar *pattern = (UChar *)uprv_malloc(decomplength * sizeof(UChar)); + unorm_decompose(text, decomplength, strsrch->search->text + start, + length, FALSE, FALSE, &status); + unorm_decompose(pattern, decomplength, strsrch->pattern.text, + strsrch->pattern.textLength, FALSE, FALSE, &status); + UBool result = (uprv_memcmp(pattern, text, decomplength * sizeof(UChar)) + == 0); + uprv_free(text); + uprv_free(pattern); + return result; } /** diff --git a/icu4c/source/test/cintltst/usrchdat.c b/icu4c/source/test/cintltst/usrchdat.c index 09c601fd12f..1f315f0c19a 100644 --- a/icu4c/source/test/cintltst/usrchdat.c +++ b/icu4c/source/test/cintltst/usrchdat.c @@ -81,6 +81,8 @@ static const SearchData STRENGTH[] = { {"A channel, another CHANNEL, more Channels, and one last channel...", "channel", "es", UCOL_PRIMARY, NULL, {2, 19, 33, 56, -1}, {7, 7, 7, 7}}, + {"\\u00c0 should match but not A", "A\\u0300", "en", UCOL_IDENTICAL, + NULL, {0, -1}, {1, 0}}, {NULL, NULL, NULL, UCOL_TERTIARY, NULL, {-1}, {0}} };