/*
*******************************************************************************
*
-* Copyright (C) 2005-2011, International Business Machines
+* Copyright (C) 2005-2012, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
return TRUE;
}
-U_CAPI int32_t U_EXPORT2
-utext_compare(UText *s1, int32_t length1,
- UText *s2, int32_t length2) {
- UChar32 c1 = 0, c2 = 0;
-
- if(length1<0 && length2<0) {
- /* strcmp style, go until end of string */
- for(;;) {
- c1 = UTEXT_NEXT32(s1);
- c2 = UTEXT_NEXT32(s2);
- if(c1 != c2) {
- break;
- } else if(c1 == U_SENTINEL) {
- return 0;
- }
- }
- } else {
- if(length1 < 0) {
- length1 = INT32_MIN;
- } else if (length2 < 0) {
- length2 = INT32_MIN;
- }
-
- /* memcmp/UnicodeString style, both length-specified */
- while((length1 > 0 || length1 == INT32_MIN) && (length2 > 0 || length2 == INT32_MIN)) {
- c1 = UTEXT_NEXT32(s1);
- c2 = UTEXT_NEXT32(s2);
-
- if(c1 != c2) {
- break;
- } else if(c1 == U_SENTINEL) {
- return 0;
- }
-
- if (length1 != INT32_MIN) {
- length1 -= 1;
- }
- if (length2 != INT32_MIN) {
- length2 -= 1;
- }
- }
-
- if(length1 <= 0 && length1 != INT32_MIN) {
- if(length2 <= 0) {
- return 0;
- } else {
- return -1;
- }
- } else if(length2 <= 0 && length2 != INT32_MIN) {
- if (length1 <= 0) {
- return 0;
- } else {
- return 1;
- }
- }
- }
-
- return (int32_t)c1-(int32_t)c2;
-}
-
-U_CAPI int32_t U_EXPORT2
-utext_compareNativeLimit(UText *s1, int64_t limit1,
- UText *s2, int64_t limit2) {
- UChar32 c1, c2;
-
- if(limit1<0 && limit2<0) {
- /* strcmp style, go until end of string */
- for(;;) {
- c1 = UTEXT_NEXT32(s1);
- c2 = UTEXT_NEXT32(s2);
- if(c1 != c2) {
- return (int32_t)c1-(int32_t)c2;
- } else if(c1 == U_SENTINEL) {
- return 0;
- }
- }
- } else {
- /* memcmp/UnicodeString style, both length-specified */
- int64_t index1 = (limit1 >= 0 ? UTEXT_GETNATIVEINDEX(s1) : 0);
- int64_t index2 = (limit2 >= 0 ? UTEXT_GETNATIVEINDEX(s2) : 0);
-
- while((limit1 < 0 || index1 < limit1) && (limit2 < 0 || index2 < limit2)) {
- c1 = UTEXT_NEXT32(s1);
- c2 = UTEXT_NEXT32(s2);
-
- if(c1 != c2) {
- return (int32_t)c1-(int32_t)c2;
- } else if(c1 == U_SENTINEL) {
- return 0;
- }
-
- if (limit1 >= 0) {
- index1 = UTEXT_GETNATIVEINDEX(s1);
- }
- if (limit2 >= 0) {
- index2 = UTEXT_GETNATIVEINDEX(s2);
- }
- }
-
- if(limit1 >= 0 && index1 >= limit1) {
- if(index2 >= limit2) {
- return 0;
- } else {
- return -1;
- }
- } else {
- if(index1 >= limit1) {
- return 0;
- } else {
- return 1;
- }
- }
- }
-}
-
-U_CAPI int32_t U_EXPORT2
-utext_caseCompare(UText *s1, int32_t length1,
- UText *s2, int32_t length2,
- uint32_t options, UErrorCode *pErrorCode) {
- const UCaseProps *csp;
-
- /* case folding variables */
- const UChar *p;
- int32_t length;
-
- /* case folding buffers, only use current-level start/limit */
- UChar fold1[UCASE_MAX_STRING_LENGTH+1], fold2[UCASE_MAX_STRING_LENGTH+1];
- int32_t foldOffset1, foldOffset2, foldLength1, foldLength2;
-
- /* current code points */
- UChar32 c1, c2;
- uint8_t cLength1, cLength2;
-
- /* argument checking */
- if(U_FAILURE(*pErrorCode)) {
- return 0;
- }
- if(s1==NULL || s2==NULL) {
- *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
- return 0;
- }
-
- csp=ucase_getSingleton();
-
- /* for variable-length strings */
- if(length1 < 0) {
- length1 = INT32_MIN;
- }
- if (length2 < 0) {
- length2 = INT32_MIN;
- }
-
- /* initialize */
- foldOffset1 = foldOffset2 = foldLength1 = foldLength2 = 0;
-
- /* comparison loop */
- while((foldOffset1 < foldLength1 || length1 > 0 || length1 == INT32_MIN) &&
- (foldOffset2 < foldLength2 || length2 > 0 || length2 == INT32_MIN)) {
- if(foldOffset1 < foldLength1) {
- U16_NEXT_UNSAFE(fold1, foldOffset1, c1);
- cLength1 = 0;
- } else {
- c1 = UTEXT_NEXT32(s1);
- if (c1 != U_SENTINEL) {
- cLength1 = U16_LENGTH(c1);
-
- length = ucase_toFullFolding(csp, c1, &p, options);
- if(length >= 0) {
- if(length <= UCASE_MAX_STRING_LENGTH) { // !!!: Does not correctly handle 0-length folded-case strings
- u_memcpy(fold1, p, length);
- foldOffset1 = 0;
- foldLength1 = length;
- U16_NEXT_UNSAFE(fold1, foldOffset1, c1);
- } else {
- c1 = length;
- }
- }
- }
-
- if(length1 != INT32_MIN) {
- length1 -= 1;
- }
- }
-
- if(foldOffset2 < foldLength2) {
- U16_NEXT_UNSAFE(fold2, foldOffset2, c2);
- cLength2 = 0;
- } else {
- c2 = UTEXT_NEXT32(s2);
- if (c2 != U_SENTINEL) {
- cLength2 = U16_LENGTH(c2);
-
- length = ucase_toFullFolding(csp, c2, &p, options);
- if(length >= 0) {
- if(length <= UCASE_MAX_STRING_LENGTH) { // !!!: Does not correctly handle 0-length folded-case strings
- u_memcpy(fold2, p, length);
- foldOffset2 = 0;
- foldLength2 = length;
- U16_NEXT_UNSAFE(fold2, foldOffset2, c2);
- } else {
- c2 = length;
- }
- }
- } else if(c1 == U_SENTINEL) {
- return 0; // end of both strings at once
- }
-
- if(length2 != INT32_MIN) {
- length2 -= 1;
- }
- }
-
- if(c1 != c2) {
- return (int32_t)c1-(int32_t)c2;
- }
- }
-
- /* By now at least one of the strings is out of characters */
- length1 += foldLength1 - foldOffset1;
- length2 += foldLength2 - foldOffset2;
-
- if(length1 <= 0 && length1 != INT32_MIN) {
- if(length2 <= 0) {
- return 0;
- } else {
- return -1;
- }
- } else {
- if (length1 <= 0) {
- return 0;
- } else {
- return 1;
- }
- }
-}
-
-U_CAPI int32_t U_EXPORT2
-utext_caseCompareNativeLimit(UText *s1, int64_t limit1,
- UText *s2, int64_t limit2,
- uint32_t options, UErrorCode *pErrorCode) {
- const UCaseProps *csp;
-
- /* case folding variables */
- const UChar *p;
- int32_t length;
-
- /* case folding buffers, only use current-level start/limit */
- UChar fold1[UCASE_MAX_STRING_LENGTH+1], fold2[UCASE_MAX_STRING_LENGTH+1];
- int32_t foldOffset1, foldOffset2, foldLength1, foldLength2;
-
- /* current code points */
- UChar32 c1, c2;
-
- /* native indexes into s1 and s2 */
- int64_t index1, index2;
-
- /* argument checking */
- if(U_FAILURE(*pErrorCode)) {
- return 0;
- }
- if(s1==NULL || s2==NULL) {
- *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
- return 0;
- }
-
- csp=ucase_getSingleton();
-
- /* initialize */
- index1 = (limit1 >= 0 ? UTEXT_GETNATIVEINDEX(s1) : 0);
- index2 = (limit2 >= 0 ? UTEXT_GETNATIVEINDEX(s2) : 0);
-
- foldOffset1 = foldOffset2 = foldLength1 = foldLength2 = 0;
-
- /* comparison loop */
- while((foldOffset1 < foldLength1 || limit1 < 0 || index1 < limit1) &&
- (foldOffset2 < foldLength2 || limit2 < 0 || index2 < limit2)) {
- if(foldOffset1 < foldLength1) {
- U16_NEXT_UNSAFE(fold1, foldOffset1, c1);
- } else {
- c1 = UTEXT_NEXT32(s1);
- if (c1 != U_SENTINEL) {
- length = ucase_toFullFolding(csp, c1, &p, options);
- if(length >= 0) {
- if(length <= UCASE_MAX_STRING_LENGTH) { // !!!: Does not correctly handle 0-length folded-case strings
- u_memcpy(fold1, p, length);
- foldOffset1 = 0;
- foldLength1 = length;
- U16_NEXT_UNSAFE(fold1, foldOffset1, c1);
- } else {
- c1 = length;
- }
- }
- }
-
- if (limit1 >= 0) {
- index1 = UTEXT_GETNATIVEINDEX(s1);
- }
- }
-
- if(foldOffset2 < foldLength2) {
- U16_NEXT_UNSAFE(fold2, foldOffset2, c2);
- } else {
- c2 = UTEXT_NEXT32(s2);
- if (c2 != U_SENTINEL) {
- length = ucase_toFullFolding(csp, c2, &p, options);
- if(length >= 0) {
- if(length <= UCASE_MAX_STRING_LENGTH) { // !!!: Does not correctly handle 0-length folded-case strings
- u_memcpy(fold2, p, length);
- foldOffset2 = 0;
- foldLength2 = length;
- U16_NEXT_UNSAFE(fold2, foldOffset2, c2);
- } else {
- c2 = length;
- }
- }
- } else if(c1 == U_SENTINEL) {
- return 0;
- }
-
- if (limit2 >= 0) {
- index2 = UTEXT_GETNATIVEINDEX(s2);
- }
- }
-
- if(c1 != c2) {
- return (int32_t)c1-(int32_t)c2;
- }
- }
-
- /* By now at least one of the strings is out of characters */
- index1 -= foldLength1 - foldOffset1;
- index2 -= foldLength2 - foldOffset2;
-
- if(limit1 >= 0 && index1 >= limit1) {
- if(index2 >= limit2) {
- return 0;
- } else {
- return -1;
- }
- } else {
- if(index1 >= limit1) {
- return 0;
- } else {
- return 1;
- }
- }
-}
-
-
U_CAPI UBool U_EXPORT2
utext_isWritable(const UText *ut)
{
/********************************************************************
* COPYRIGHT:
- * Copyright (c) 2005-2011, International Business Machines Corporation and
+ * Copyright (c) 2005-2012, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/************************************************************************
if (exec) Ticket5560(); break;
case 4: name = "Ticket6847";
if (exec) Ticket6847(); break;
- case 5: name = "ComparisonTest";
- if (exec) ComparisonTest(); break;
default: name = ""; break;
}
}
delete []buf;
}
-
-//
-// ComparisonTest() Check the string comparison functions. Based on UnicodeStringTest::TestCompare()
-//
-void UTextTest::ComparisonTest()
-{
- UErrorCode status = U_ZERO_ERROR;
- UnicodeString test1Str("this is a test");
- UnicodeString test2Str("this is a test");
- UnicodeString test3Str("this is a test of the emergency broadcast system");
- UnicodeString test4Str("never say, \"this is a test\"!!");
-
- UText test1 = UTEXT_INITIALIZER;
- UText test2 = UTEXT_INITIALIZER;
- UText test3 = UTEXT_INITIALIZER;
- UText test4 = UTEXT_INITIALIZER;
-
- UChar uniChars[] = { 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73,
- 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0 };
- char chars[] = { 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73,
- 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0 };
-
- UText uniCharText = UTEXT_INITIALIZER;
- UText charText = UTEXT_INITIALIZER;
-
- utext_openUnicodeString(&test1, &test1Str, &status);
- utext_openUnicodeString(&test2, &test2Str, &status);
- utext_openUnicodeString(&test3, &test3Str, &status);
- utext_openUnicodeString(&test4, &test4Str, &status);
-
- utext_openUChars(&uniCharText, uniChars, -1, &status);
- utext_openUTF8(&charText, chars, -1, &status);
-
- TEST_SUCCESS(status);
-
- // test utext_compare(), simple
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test2, 0);
- if (utext_compare(&test1, -1, &test2, -1) != 0) errln("utext_compare() failed, simple setup");
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test3, 0);
- if (utext_compare(&test1, -1, &test3, -1) >= 0) errln("utext_compare() failed, simple setup");
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test4, 0);
- if (utext_compare(&test1, -1, &test4, -1) <= 0) errln("utext_compare() failed, simple setup");
-
- // test utext_compareNativeLimit(), simple
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test2, 0);
- if (utext_compareNativeLimit(&test1, -1, &test2, -1) != 0) errln("utext_compareNativeLimit() failed, simple setup");
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test3, 0);
- if (utext_compareNativeLimit(&test1, -1, &test3, -1) >= 0) errln("utext_compareNativeLimit() failed, simple setup");
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test4, 0);
- if (utext_compareNativeLimit(&test1, -1, &test4, -1) <= 0) errln("utext_compareNativeLimit() failed, simple setup");
-
- // test utext_compare(), one explicit length
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test2, 0);
- if (utext_compare(&test1, 14, &test2, -1) != 0) errln("utext_compare() failed, one explicit length");
- UTEXT_SETNATIVEINDEX(&test2, 0);
- UTEXT_SETNATIVEINDEX(&test3, 0);
- if (utext_compare(&test3, 14, &test2, -1) != 0) errln("utext_compare() failed, one explicit length");
- UTEXT_SETNATIVEINDEX(&test2, 0);
- UTEXT_SETNATIVEINDEX(&test4, 12);
- if (utext_compare(&test4, 14, &test2, -1) != 0) errln("utext_compare() failed, one explicit length and offset");
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test3, 0);
- if (utext_compare(&test3, 18, &test2, -1) <= 0) errln("utext_compare() failed, one explicit length");
-
- // test utext_compareNativeLimit(), one explicit length
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test2, 0);
- if (utext_compareNativeLimit(&test1, 14, &test2, -1) != 0) errln("utext_compareNativeLimit() failed, one explicit length");
- UTEXT_SETNATIVEINDEX(&test2, 0);
- UTEXT_SETNATIVEINDEX(&test3, 0);
- if (utext_compareNativeLimit(&test3, 14, &test2, -1) != 0) errln("utext_compareNativeLimit() failed, one explicit length");
- UTEXT_SETNATIVEINDEX(&test2, 0);
- UTEXT_SETNATIVEINDEX(&test4, 12);
- if (utext_compareNativeLimit(&test4, 26, &test2, -1) != 0) errln("utext_compareNativeLimit() failed, one explicit length and limit");
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test3, 0);
- if (utext_compareNativeLimit(&test3, 18, &test2, -1) <= 0) errln("utext_compareNativeLimit() failed, one explicit length");
-
- // test utext_compare(), UChar-based UText
- UTEXT_SETNATIVEINDEX(&uniCharText, 0);
- UTEXT_SETNATIVEINDEX(&test2, 0);
- if (utext_compare(&test2, -1, &uniCharText, -1) != 0) errln("utext_compare() failed, UChar-based UText");
- UTEXT_SETNATIVEINDEX(&uniCharText, 0);
- UTEXT_SETNATIVEINDEX(&test3, 0);
- if (utext_compare(&test3, -1, &uniCharText, -1) <= 0) errln("utext_compare() failed, UChar-based UText");
- UTEXT_SETNATIVEINDEX(&uniCharText, 0);
- UTEXT_SETNATIVEINDEX(&test4, 0);
- if (utext_compare(&test4, -1, &uniCharText, -1) >= 0) errln("utext_compare() failed, UChar-based UText");
-
- // test utext_compareNativeLimit(), UChar-based UText
- UTEXT_SETNATIVEINDEX(&uniCharText, 0);
- UTEXT_SETNATIVEINDEX(&test2, 0);
- if (utext_compareNativeLimit(&test2, -1, &uniCharText, -1) != 0) errln("utext_compareNativeLimit() failed, UChar-based UText");
- UTEXT_SETNATIVEINDEX(&uniCharText, 0);
- UTEXT_SETNATIVEINDEX(&test3, 0);
- if (utext_compareNativeLimit(&test3, -1, &uniCharText, -1) <= 0) errln("utext_compareNativeLimit() failed, UChar-based UText");
- UTEXT_SETNATIVEINDEX(&uniCharText, 0);
- UTEXT_SETNATIVEINDEX(&test4, 0);
- if (utext_compareNativeLimit(&test4, -1, &uniCharText, -1) >= 0) errln("utext_compareNativeLimit() failed, UChar-based UText");
-
- // test utext_compare(), UTF8-based UText
- UTEXT_SETNATIVEINDEX(&charText, 0);
- UTEXT_SETNATIVEINDEX(&test2, 0);
- if (utext_compare(&test2, -1, &charText, -1) != 0) errln("utext_compare() failed, UTF8-based UText");
- UTEXT_SETNATIVEINDEX(&charText, 0);
- UTEXT_SETNATIVEINDEX(&test3, 0);
- if (utext_compare(&test3, -1, &charText, -1) <= 0) errln("utext_compare() failed, UTF8-based UText");
- UTEXT_SETNATIVEINDEX(&charText, 0);
- UTEXT_SETNATIVEINDEX(&test4, 0);
- if (utext_compare(&test4, -1, &charText, -1) >= 0) errln("utext_compare() failed, UTF8-based UText");
-
- // test utext_compareNativeLimit(), UTF8-based UText
- UTEXT_SETNATIVEINDEX(&charText, 0);
- UTEXT_SETNATIVEINDEX(&test2, 0);
- if (utext_compareNativeLimit(&test2, -1, &charText, -1) != 0) errln("utext_compareNativeLimit() failed, UTF8-based UText");
- UTEXT_SETNATIVEINDEX(&charText, 0);
- UTEXT_SETNATIVEINDEX(&test3, 0);
- if (utext_compareNativeLimit(&test3, -1, &charText, -1) <= 0) errln("utext_compareNativeLimit() failed, UTF8-based UText");
- UTEXT_SETNATIVEINDEX(&charText, 0);
- UTEXT_SETNATIVEINDEX(&test4, 0);
- if (utext_compareNativeLimit(&test4, -1, &charText, -1) >= 0) errln("utext_compareNativeLimit() failed, UTF8-based UText");
-
- // test utext_compare(), length
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test2, 0);
- if (utext_compare(&test1, -1, &test2, 4) != 0) errln("utext_compare() failed, one length");
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test2, 0);
- if (utext_compare(&test1, 5, &test2, 4) <= 0) errln("utext_compare() failed, both lengths");
-
- // test utext_compareNativeLimit(), limit
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test2, 0);
- if (utext_compareNativeLimit(&test1, -1, &test2, 4) != 0) errln("utext_compareNativeLimit() failed, one limit");
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test2, 0);
- if (utext_compareNativeLimit(&test1, 5, &test2, 4) <= 0) errln("utext_compareNativeLimit() failed, both limits");
-
- // test utext_compare(), both explicit offsets and lengths
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test2, 0);
- if (utext_compare(&test1, 14, &test2, 14) != 0) errln("utext_compare() failed, both explicit offsets and lengths");
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test3, 0);
- if (utext_compare(&test1, 14, &test3, 14) != 0) errln("utext_compare() failed, both explicit offsets and lengths");
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test4, 12);
- if (utext_compare(&test1, 14, &test4, 14) != 0) errln("utext_compare() failed, both explicit offsets and lengths");
- UTEXT_SETNATIVEINDEX(&test1, 10);
- UTEXT_SETNATIVEINDEX(&test2, 0);
- if (utext_compare(&test1, 4, &test2, 4) >= 0) errln("utext_compare() failed, both explicit offsets and lengths");
- UTEXT_SETNATIVEINDEX(&test1, 10);
- UTEXT_SETNATIVEINDEX(&test3, 22);
- if (utext_compare(&test1, 4, &test3, 9) <= 0) errln("utext_compare() failed, both explicit offsets and lengths");
- UTEXT_SETNATIVEINDEX(&test1, 10);
- UTEXT_SETNATIVEINDEX(&test4, 22);
- if (utext_compare(&test1, 4, &test4, 4) != 0) errln("utext_compare() failed, both explicit offsets and lengths");
-
- // test utext_compareNativeLimit(), both explicit offsets and limits
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test2, 0);
- if (utext_compareNativeLimit(&test1, 14, &test2, 14) != 0) errln("utext_compareNativeLimit() failed, both explicit offsets and limits");
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test3, 0);
- if (utext_compareNativeLimit(&test1, 14, &test3, 14) != 0) errln("utext_compareNativeLimit() failed, both explicit offsets and limits");
- UTEXT_SETNATIVEINDEX(&test1, 0);
- UTEXT_SETNATIVEINDEX(&test4, 12);
- if (utext_compareNativeLimit(&test1, 14, &test4, 26) != 0) errln("utext_compareNativeLimit() failed, both explicit offsets and limits");
- UTEXT_SETNATIVEINDEX(&test1, 10);
- UTEXT_SETNATIVEINDEX(&test2, 0);
- if (utext_compareNativeLimit(&test1, 14, &test2, 4) >= 0) errln("utext_compareNativeLimit() failed, both explicit offsets and limits");
- UTEXT_SETNATIVEINDEX(&test1, 10);
- UTEXT_SETNATIVEINDEX(&test3, 22);
- if (utext_compareNativeLimit(&test1, 14, &test3, 31) <= 0) errln("utext_compareNativeLimit() failed, both explicit offsets and limits");
- UTEXT_SETNATIVEINDEX(&test1, 10);
- UTEXT_SETNATIVEINDEX(&test4, 22);
- if (utext_compareNativeLimit(&test1, 14, &test4, 26) != 0) errln("utext_compareNativeLimit() failed, both explicit offsets and limits");
-
- /* test caseCompare() */
- {
- static const UChar
- _mixed[]= { 0x61, 0x42, 0x131, 0x3a3, 0xdf, 0x130, 0x49, 0xfb03, 0xd93f, 0xdfff, 0 },
- _otherDefault[]= { 0x41, 0x62, 0x131, 0x3c3, 0x73, 0x53, 0x69, 0x307, 0x69, 0x46, 0x66, 0x49, 0xd93f, 0xdfff, 0 },
- _otherExcludeSpecialI[]={ 0x41, 0x62, 0x131, 0x3c3, 0x53, 0x73, 0x69, 0x131, 0x66, 0x46, 0x69, 0xd93f, 0xdfff, 0 },
- _different[]= { 0x41, 0x62, 0x131, 0x3c3, 0x73, 0x53, 0x130, 0x49, 0x46, 0x66, 0x49, 0xd93f, 0xdffd, 0 };
-
- UText
- mixed = UTEXT_INITIALIZER,
- otherDefault = UTEXT_INITIALIZER,
- otherExcludeSpecialI = UTEXT_INITIALIZER,
- different = UTEXT_INITIALIZER;
-
- utext_openUChars(&mixed, _mixed, -1, &status);
- utext_openUChars(&otherDefault, _otherDefault, -1, &status);
- utext_openUChars(&otherExcludeSpecialI, _otherExcludeSpecialI, -1, &status);
- utext_openUChars(&different, _different, -1, &status);
-
- TEST_SUCCESS(status);
-
- int32_t result;
-
- /* test default options */
- UTEXT_SETNATIVEINDEX(&mixed, 0);
- UTEXT_SETNATIVEINDEX(&otherDefault, 0);
- result = utext_caseCompare(&mixed, -1, &otherDefault, -1, U_FOLD_CASE_DEFAULT, &status);
- if (0 != result || U_FAILURE(status)) {
- errln("error: utext_caseCompare (other, default) gives %ld (should be 0) (%s)\n", result, u_errorName(status));
- }
- UTEXT_SETNATIVEINDEX(&mixed, 0);
- UTEXT_SETNATIVEINDEX(&otherDefault, 0);
- result = utext_caseCompareNativeLimit(&mixed, -1, &otherDefault, -1, U_FOLD_CASE_DEFAULT, &status);
- if (0 != result || U_FAILURE(status)) {
- errln("error: utext_caseCompareNativeLimit (other, default) gives %ld (should be 0) (%s)\n", result, u_errorName(status));
- }
-
- /* test excluding special I */
- UTEXT_SETNATIVEINDEX(&mixed, 0);
- UTEXT_SETNATIVEINDEX(&otherExcludeSpecialI, 0);
- result = utext_caseCompare(&mixed, -1, &otherExcludeSpecialI, -1, U_FOLD_CASE_EXCLUDE_SPECIAL_I, &status);
- if (0 != result || U_FAILURE(status)) {
- errln("error: utext_caseCompare (otherExcludeSpecialI, U_FOLD_CASE_EXCLUDE_SPECIAL_I) gives %ld (should be 0) (%s)\n", result, u_errorName(status));
- }
- UTEXT_SETNATIVEINDEX(&mixed, 0);
- UTEXT_SETNATIVEINDEX(&otherExcludeSpecialI, 0);
- result = utext_caseCompareNativeLimit(&mixed, -1, &otherExcludeSpecialI, -1, U_FOLD_CASE_EXCLUDE_SPECIAL_I, &status);
- if (0 != result || U_FAILURE(status)) {
- errln("error: utext_caseCompareNativeLimit (otherExcludeSpecialI, U_FOLD_CASE_EXCLUDE_SPECIAL_I) gives %ld (should be 0) (%s)\n", result, u_errorName(status));
- }
- UTEXT_SETNATIVEINDEX(&mixed, 0);
- UTEXT_SETNATIVEINDEX(&otherDefault, 0);
- result = utext_caseCompare(&mixed, -1, &otherDefault, -1, U_FOLD_CASE_EXCLUDE_SPECIAL_I, &status);
- if (0 == result || U_FAILURE(status)) {
- errln("error: utext_caseCompare (other, U_FOLD_CASE_EXCLUDE_SPECIAL_I) gives %ld (should be nonzero) (%s)\n", result, u_errorName(status));
- }
- UTEXT_SETNATIVEINDEX(&mixed, 0);
- UTEXT_SETNATIVEINDEX(&otherDefault, 0);
- result = utext_caseCompareNativeLimit(&mixed, -1, &otherDefault, -1, U_FOLD_CASE_EXCLUDE_SPECIAL_I, &status);
- if (0 == result || U_FAILURE(status)) {
- errln("error: utext_caseCompareNativeLimit (other, U_FOLD_CASE_EXCLUDE_SPECIAL_I) gives %ld (should be nonzero) (%s)\n", result, u_errorName(status));
- }
-
- /* test against different string */
- UTEXT_SETNATIVEINDEX(&mixed, 0);
- UTEXT_SETNATIVEINDEX(&different, 0);
- result = utext_caseCompare(&mixed, -1, &different, -1, U_FOLD_CASE_DEFAULT, &status);
- if (0 >= result || U_FAILURE(status)) {
- errln("error: utext_caseCompare (different, default) gives %ld (should be positive) (%s)\n", result, u_errorName(status));
- }
- UTEXT_SETNATIVEINDEX(&mixed, 0);
- UTEXT_SETNATIVEINDEX(&different, 0);
- result = utext_caseCompareNativeLimit(&mixed, -1, &different, -1, U_FOLD_CASE_DEFAULT, &status);
- if (0 >= result || U_FAILURE(status)) {
- errln("error: utext_caseCompareNativeLimit (different, default) gives %ld (should be positive) (%s)\n", result, u_errorName(status));
- }
-
- /* test caseCompare() - include the folded sharp s (U+00df) with different lengths */
- UTEXT_SETNATIVEINDEX(&mixed, 1);
- UTEXT_SETNATIVEINDEX(&different, 1);
- result = utext_caseCompare(&mixed, 4, &different, 5, U_FOLD_CASE_DEFAULT, &status);
- if (0 != result || U_FAILURE(status)) {
- errln("error: utext_caseCompare (mixed[1-5), different[1-6), default) gives %ld (should be 0) (%s)\n", result, u_errorName(status));
- }
- UTEXT_SETNATIVEINDEX(&mixed, 1);
- UTEXT_SETNATIVEINDEX(&different, 1);
- result = utext_caseCompareNativeLimit(&mixed, 5, &different, 6, U_FOLD_CASE_DEFAULT, &status);
- if (0 != result || U_FAILURE(status)) {
- errln("error: utext_caseCompareNativeLimit (mixed[1-5), different[1-6), default) gives %ld (should be 0) (%s)\n", result, u_errorName(status));
- }
-
- /* test caseCompare() - stop in the middle of the sharp s (U+00df) */
- UTEXT_SETNATIVEINDEX(&mixed, 1);
- UTEXT_SETNATIVEINDEX(&different, 1);
- result = utext_caseCompare(&mixed, 4, &different, 4, U_FOLD_CASE_DEFAULT, &status);
- if (0 >= result || U_FAILURE(status)) {
- errln("error: utext_caseCompare (mixed[1-5), different[1-5), default) gives %ld (should be positive) (%s)\n", result, u_errorName(status));
- }
- UTEXT_SETNATIVEINDEX(&mixed, 1);
- UTEXT_SETNATIVEINDEX(&different, 1);
- result = utext_caseCompareNativeLimit(&mixed, 5, &different, 5, U_FOLD_CASE_DEFAULT, &status);
- if (0 >= result || U_FAILURE(status)) {
- errln("error: utext_caseCompareNativeLimit (mixed[1-5), different[1-5), default) gives %ld (should be positive) (%s)\n", result, u_errorName(status));
- }
- }
-
- /* test surrogates in comparison */
- {
- static const UChar
- _before[] = { 0x65, 0xd800, 0xd800, 0xdc01, 0x65, 0x00 },
- _after[] = { 0x65, 0xd800, 0xdc00, 0x65, 0x00 };
-
- UText
- before = UTEXT_INITIALIZER,
- after = UTEXT_INITIALIZER;
-
- utext_openUChars(&before, _before, -1, &status);
- utext_openUChars(&after, _after, -1, &status);
-
- TEST_SUCCESS(status);
- int32_t result;
-
- UTEXT_SETNATIVEINDEX(&before, 1);
- UTEXT_SETNATIVEINDEX(&after, 1);
- result = utext_compare(&before, -1, &after, -1);
- if (0 <= result || U_FAILURE(status)) {
- errln("error: utext_compare ({ 65, d800, 10001, 65 }, { 65, 10000, 65 }) gives %ld (should be negative) (%s)\n", result, u_errorName(status));
- }
-
- UTEXT_SETNATIVEINDEX(&before, 1);
- UTEXT_SETNATIVEINDEX(&after, 1);
- result = utext_compare(&before, 3, &after, 3);
- if (0 <= result || U_FAILURE(status)) {
- errln("error: utext_compare with lengths ({ 65, d800, 10001, 65 }, { 65, 10000, 65 }) gives %ld (should be negative) (%s)\n", result, u_errorName(status));
- }
-
- UTEXT_SETNATIVEINDEX(&before, 1);
- UTEXT_SETNATIVEINDEX(&after, 1);
- result = utext_caseCompare(&before, -1, &after, -1, U_FOLD_CASE_DEFAULT, &status);
- if (0 <= result || U_FAILURE(status)) {
- errln("error: utext_caseCompare ({ 65, d800, 10001, 65 }, { 65, 10000, 65 }) gives %ld (should be negative) (%s)\n", result, u_errorName(status));
- }
-
- UTEXT_SETNATIVEINDEX(&before, 1);
- UTEXT_SETNATIVEINDEX(&after, 1);
- result = utext_caseCompare(&before, 3, &after, 3, U_FOLD_CASE_DEFAULT, &status);
- if (0 <= result || U_FAILURE(status)) {
- errln("error: utext_caseCompare with lengths ({ 65, d800, 10001, 65 }, { 65, 10000, 65 }) gives %ld (should be negative) (%s)\n", result, u_errorName(status));
- }
-
- utext_close(&before);
- utext_close(&after);
- }
-
- /* test surrogates at end of string */
- {
- static const UChar
- _before[] = { 0x65, 0xd800, 0xd800, 0xdc01, 0x00 },
- _after[] = { 0x65, 0xd800, 0xdc00, 0x00 };
-
- UText
- before = UTEXT_INITIALIZER,
- after = UTEXT_INITIALIZER;
-
- utext_openUChars(&before, _before, -1, &status);
- utext_openUChars(&after, _after, -1, &status);
-
- TEST_SUCCESS(status);
- int32_t result;
-
- UTEXT_SETNATIVEINDEX(&before, 1);
- UTEXT_SETNATIVEINDEX(&after, 1);
- result = utext_compare(&before, -1, &after, -1);
- if (0 <= result || U_FAILURE(status)) {
- errln("error: utext_compare ({ 65, d800, 10001 }, { 65, 10000 }) gives %ld (should be negative) (%s)\n", result, u_errorName(status));
- }
-
- UTEXT_SETNATIVEINDEX(&before, 1);
- UTEXT_SETNATIVEINDEX(&after, 1);
- result = utext_caseCompare(&before, -1, &after, -1, U_FOLD_CASE_DEFAULT, &status);
- if (0 <= result || U_FAILURE(status)) {
- errln("error: utext_caseCompare ({ 65, d800, 10001 }, { 65, 10000 }) gives %ld (should be negative) (%s)\n", result, u_errorName(status));
- }
-
- utext_close(&before);
- utext_close(&after);
- }
-
- /* test empty strings */
- {
- UChar zero16 = 0;
- char zero8 = 0;
- UText emptyUChar = UTEXT_INITIALIZER;
- UText emptyUTF8 = UTEXT_INITIALIZER;
- UText nullUChar = UTEXT_INITIALIZER;
- UText nullUTF8 = UTEXT_INITIALIZER;
-
- utext_openUChars(&emptyUChar, &zero16, -1, &status);
- utext_openUTF8(&emptyUTF8, &zero8, -1, &status);
- utext_openUChars(&nullUChar, NULL, 0, &status);
- utext_openUTF8(&nullUTF8, NULL, 0, &status);
-
- if (utext_compare(&emptyUChar, -1, &emptyUTF8, -1) != 0) {
- errln("error: utext_compare(&emptyUChar, -1, &emptyUTF8, -1) != 0");
- }
- if (utext_compare(&emptyUChar, -1, &nullUChar, -1) != 0) {
- errln("error: utext_compare(&emptyUChar, -1, &nullUChar, -1) != 0");
- }
- if (utext_compare(&emptyUChar, -1, &nullUTF8, -1) != 0) {
- errln("error: utext_compare(&emptyUChar, -1, &nullUTF8, -1) != 0");
- }
- if (utext_compare(&emptyUTF8, -1, &nullUChar, -1) != 0) {
- errln("error: utext_compare(&emptyUTF8, -1, &nullUChar, -1) != 0");
- }
- if (utext_compare(&emptyUTF8, -1, &nullUTF8, -1) != 0) {
- errln("error: utext_compare(&emptyUTF8, -1, &nullUTF8, -1) != 0");
- }
- if (utext_compare(&nullUChar, -1, &nullUTF8, -1) != 0) {
- errln("error: utext_compare(&nullUChar, -1, &nullUTF8, -1) != 0");
- }
-
- if (utext_compareNativeLimit(&emptyUChar, -1, &emptyUTF8, -1) != 0) {
- errln("error: utext_compareNativeLimit(&emptyUChar, -1, &emptyUTF8, -1) != 0");
- }
- if (utext_compareNativeLimit(&emptyUChar, -1, &nullUChar, -1) != 0) {
- errln("error: utext_compareNativeLimit(&emptyUChar, -1, &nullUChar, -1) != 0");
- }
- if (utext_compareNativeLimit(&emptyUChar, -1, &nullUTF8, -1) != 0) {
- errln("error: utext_compareNativeLimit(&emptyUChar, -1, &nullUTF8, -1) != 0");
- }
- if (utext_compareNativeLimit(&emptyUTF8, -1, &nullUChar, -1) != 0) {
- errln("error: utext_compareNativeLimit(&emptyUTF8, -1, &nullUChar, -1) != 0");
- }
- if (utext_compareNativeLimit(&emptyUTF8, -1, &nullUTF8, -1) != 0) {
- errln("error: utext_compareNativeLimit(&emptyUTF8, -1, &nullUTF8, -1) != 0");
- }
- if (utext_compareNativeLimit(&nullUChar, -1, &nullUTF8, -1) != 0) {
- errln("error: utext_compareNativeLimit(&nullUChar, -1, &nullUTF8, -1) != 0");
- }
-
- if (utext_caseCompare(&emptyUChar, -1, &emptyUTF8, -1, 0, &status) != 0) {
- errln("error: utext_caseCompare(&emptyUChar, -1, &emptyUTF8, -1, 0, &status) != 0");
- }
- if (utext_caseCompare(&emptyUChar, -1, &nullUChar, -1, 0, &status) != 0) {
- errln("error: utext_caseCompare(&emptyUChar, -1, &nullUChar, -1, 0, &status) != 0");
- }
- if (utext_caseCompare(&emptyUChar, -1, &nullUTF8, -1, 0, &status) != 0) {
- errln("error: utext_caseCompare(&emptyUChar, -1, &nullUTF8, -1, 0, &status) != 0");
- }
- if (utext_caseCompare(&emptyUTF8, -1, &nullUChar, -1, 0, &status) != 0) {
- errln("error: utext_caseCompare(&emptyUTF8, -1, &nullUChar, -1, 0, &status) != 0");
- }
- if (utext_caseCompare(&emptyUTF8, -1, &nullUTF8, -1, 0, &status) != 0) {
- errln("error: utext_caseCompare(&emptyUTF8, -1, &nullUTF8, -1, 0, &status) != 0");
- }
- if (utext_caseCompare(&nullUChar, -1, &nullUTF8, -1, 0, &status) != 0) {
- errln("error: utext_caseCompare(&nullUChar, -1, &nullUTF8, -1, 0, &status) != 0");
- }
-
- if (utext_caseCompareNativeLimit(&emptyUChar, -1, &emptyUTF8, -1, 0, &status) != 0) {
- errln("error: utext_caseCompareNativeLimit(&emptyUChar, -1, &emptyUTF8, -1, 0, &status) != 0");
- }
- if (utext_caseCompareNativeLimit(&emptyUChar, -1, &nullUChar, -1, 0, &status) != 0) {
- errln("error: utext_caseCompareNativeLimit(&emptyUChar, -1, &nullUChar, -1, 0, &status) != 0");
- }
- if (utext_caseCompareNativeLimit(&emptyUChar, -1, &nullUTF8, -1, 0, &status) != 0) {
- errln("error: utext_caseCompareNativeLimit(&emptyUChar, -1, &nullUTF8, -1, 0, &status) != 0");
- }
- if (utext_caseCompareNativeLimit(&emptyUTF8, -1, &nullUChar, -1, 0, &status) != 0) {
- errln("error: utext_caseCompareNativeLimit(&emptyUTF8, -1, &nullUChar, -1, 0, &status) != 0");
- }
- if (utext_caseCompareNativeLimit(&emptyUTF8, -1, &nullUTF8, -1, 0, &status) != 0) {
- errln("error: utext_caseCompareNativeLimit(&emptyUTF8, -1, &nullUTF8, -1, 0, &status) != 0");
- }
- if (utext_caseCompareNativeLimit(&nullUChar, -1, &nullUTF8, -1, 0, &status) != 0) {
- errln("error: utext_caseCompareNativeLimit(&nullUChar, -1, &nullUTF8, -1, 0, &status) != 0");
- }
-
- utext_close(&emptyUChar);
- utext_close(&emptyUTF8);
- utext_close(&nullUChar);
- utext_close(&nullUTF8);
- utext_close(&charText);
- utext_close(&uniCharText);
- }
-}
-
-
-
//
// ErrorTest() Check various error and edge cases.
//