diff --git a/intl/unicharutil/src/nsCaseConversionImp2.cpp b/intl/unicharutil/src/nsCaseConversionImp2.cpp index 3dde88b618c..d67f01e5471 100644 --- a/intl/unicharutil/src/nsCaseConversionImp2.cpp +++ b/intl/unicharutil/src/nsCaseConversionImp2.cpp @@ -246,6 +246,18 @@ nsresult nsCaseConversionImp2::ToTitle( } else { + // First check for uppercase characters whose titlecase mapping is + // different, like U+01F1 DZ: they must remain unchanged. + if( 0x01C0 == ( aChar & 0xFFC0)) // 0x01Cx - 0x01Fx + { + for(PRUint32 i = 0 ; i < gUpperToTitleItems; i++) { + if ( aChar == gUpperToTitle[(i*2)+kUpperIdx]) { + *aReturn = aChar; + return NS_OK; + } + } + } + PRUnichar upper; upper = gUpperMap->Map(aChar); @@ -323,7 +335,7 @@ nsresult nsCaseConversionImp2::ToTitle( PRBool bLastIsSpace = IS_ASCII_SPACE(anArray[0]); if(aStartInWordBoundary) { - this->ToTitle(aReturn[0], &aReturn[0]); + this->ToTitle(anArray[0], &aReturn[0]); } PRUint32 i; @@ -331,7 +343,11 @@ nsresult nsCaseConversionImp2::ToTitle( { if(bLastIsSpace) { - this->ToTitle(aReturn[i], &aReturn[i]); + this->ToTitle(anArray[i], &aReturn[i]); + } + else + { + aReturn[i] = anArray[i]; } bLastIsSpace = IS_ASCII_SPACE(aReturn[i]); diff --git a/intl/unicharutil/tests/UnicharSelfTest.cpp b/intl/unicharutil/tests/UnicharSelfTest.cpp index d77d76094f9..cc82d141bfb 100644 --- a/intl/unicharutil/tests/UnicharSelfTest.cpp +++ b/intl/unicharutil/tests/UnicharSelfTest.cpp @@ -197,7 +197,7 @@ static PRUnichar t3result[T3LEN+1] = { 0x00 }; // test data for ToTitle -static PRUnichar t4data [T4LEN+1] = { +static PRUnichar t4data [T4LEN+2] = { 0x0031 , // 0 0x0019 , // 1 0x0043 , // 2 @@ -227,10 +227,11 @@ static PRUnichar t4data [T4LEN+1] = { 0x01F1 , // 26 0x01F2 , // 27 0x01F3 , // 28 + 0x0041 , // Dummy entry to prevent overflow 0x00 }; // expected result for ToTitle -static PRUnichar t4result[T4LEN+1] = { +static PRUnichar t4result[T4LEN+2] = { 0x0031 , // 0 0x0019 , // 1 0x0043 , // 2 @@ -238,7 +239,7 @@ static PRUnichar t4result[T4LEN+1] = { 0x00C8 , // 4 0x00C9 , // 5 0x0147 , // 6 - 0x01C5 , // 7 + 0x01C4 , // 7 0x01C5 , // 8 0x01C5 , // 9 0x03A0 , // 10 @@ -251,15 +252,16 @@ static PRUnichar t4result[T4LEN+1] = { 0x5189 , // 17 0xC013 , // 18 0xFF32 , // 19 - 0x01C8 , // 20 + 0x01C7 , // 20 0x01C8 , // 21 0x01C8 , // 22 - 0x01CB , // 23 + 0x01CA , // 23 0x01CB , // 24 0x01CB , // 25 - 0x01F2 , // 26 + 0x01F1 , // 26 0x01F2 , // 27 0x01F2 , // 28 + 0x0041 , // Dummy entry to prevent overflow 0x00 }; @@ -357,8 +359,28 @@ void TestCaseConversion() } } + /* + * It would be pointless to test ToTitle() with the whole buffer, since + * the expected result would be that only the first character would be + * transformed. Instead, pass a series of 2-character buffers starting + * with each character of the test cases, and check that the first + * character is transformed as expected and the second remains unchanged + */ printf("Test 7 - ToTitle(PRUnichar*, PRUnichar*, PRUint32):\n"); - printf("!!! To Be Implemented !!!\n"); + for (i = 0; i < T4LEN; i++) + { + PRUnichar* titleTest = t4data + i; + res = t->ToTitle(titleTest, buf, 2); + if(NS_FAILED(res)) { + printf("\tFailed!! return value != NS_OK\n"); + } else { + if (buf[0] != t4result[i] || buf[1] != t4data[i + 1]) + { + printf("\tFailed!! result unexpected %d\n", i); + break; + } + } + } NS_RELEASE(t); }