mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-3267 UniStr::toTitle(iter!=NULL) must set its text on iter
X-SVN-Rev: 13546
This commit is contained in:
parent
6c2f85f7cd
commit
87cd8a5be1
3 changed files with 44 additions and 41 deletions
|
@ -2366,6 +2366,7 @@ public:
|
|||
* that are to be titlecased.
|
||||
* If none is provided (0), then a standard titlecase
|
||||
* break iterator is opened.
|
||||
* Otherwise the provided iterator is set to the string's text.
|
||||
* @return A reference to this.
|
||||
* @stable ICU 2.1
|
||||
*/
|
||||
|
@ -2393,6 +2394,7 @@ public:
|
|||
* that are to be titlecased.
|
||||
* If none is provided (0), then a standard titlecase
|
||||
* break iterator is opened.
|
||||
* Otherwise the provided iterator is set to the string's text.
|
||||
* @param locale The locale to consider.
|
||||
* @return A reference to this.
|
||||
* @stable ICU 2.1
|
||||
|
|
|
@ -1165,18 +1165,19 @@ UnicodeString::caseMap(BreakIterator *titleIter,
|
|||
UBreakIterator *cTitleIter = 0;
|
||||
|
||||
if(toWhichCase == TO_TITLE) {
|
||||
errorCode = U_ZERO_ERROR;
|
||||
if(titleIter != 0) {
|
||||
cTitleIter = (UBreakIterator *)titleIter;
|
||||
ubrk_setText(cTitleIter, oldArray, oldLength, &errorCode);
|
||||
} else {
|
||||
errorCode = U_ZERO_ERROR;
|
||||
cTitleIter = ubrk_open(UBRK_WORD, locale.getName(),
|
||||
oldArray, oldLength,
|
||||
&errorCode);
|
||||
if(U_FAILURE(errorCode)) {
|
||||
uprv_free(bufferToDelete);
|
||||
setToBogus();
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
if(U_FAILURE(errorCode)) {
|
||||
uprv_free(bufferToDelete);
|
||||
setToBogus();
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -324,51 +324,51 @@ StringCaseTest::TestCaseConversion()
|
|||
|
||||
void
|
||||
StringCaseTest::TestTitleCasing() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UBreakIterator *iter;
|
||||
char cLocaleID[100];
|
||||
UnicodeString locale, input, result;
|
||||
int32_t type;
|
||||
TestLog myLog;
|
||||
TestDataModule *driver = TestDataModule::getTestDataModule("casing", myLog, status);
|
||||
if(U_SUCCESS(status)) {
|
||||
TestData *casingTest = driver->createTestData("titlecasing", status);
|
||||
const DataMap *myCase = NULL;
|
||||
while(casingTest->nextCase(myCase, status)) {
|
||||
locale = myCase->getString("Locale", status);
|
||||
locale.extract(0, 0x7fffffff, cLocaleID, sizeof(cLocaleID), "");
|
||||
type = myCase->getInt("Type", status);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UBreakIterator *iter;
|
||||
char cLocaleID[100];
|
||||
UnicodeString locale, input, result;
|
||||
int32_t type;
|
||||
TestLog myLog;
|
||||
TestDataModule *driver = TestDataModule::getTestDataModule("casing", myLog, status);
|
||||
if(U_SUCCESS(status)) {
|
||||
TestData *casingTest = driver->createTestData("titlecasing", status);
|
||||
const DataMap *myCase = NULL;
|
||||
while(casingTest->nextCase(myCase, status)) {
|
||||
locale = myCase->getString("Locale", status);
|
||||
locale.extract(0, 0x7fffffff, cLocaleID, sizeof(cLocaleID), "");
|
||||
type = myCase->getInt("Type", status);
|
||||
|
||||
|
||||
input = myCase->getString("Input", status);
|
||||
if(type<0) {
|
||||
iter=0;
|
||||
} else {
|
||||
iter=ubrk_open((UBreakIteratorType)type, cLocaleID, input.getBuffer(), input.length(), &status);
|
||||
}
|
||||
input = myCase->getString("Input", status);
|
||||
if(type<0) {
|
||||
iter=0;
|
||||
} else {
|
||||
iter=ubrk_open((UBreakIteratorType)type, cLocaleID, NULL, 0, &status);
|
||||
}
|
||||
|
||||
if(U_FAILURE(status)) {
|
||||
errln("error: TestTitleCasing() ubrk_open(%d) failed for test case from casing.res: %s", type, u_errorName(status));
|
||||
status = U_ZERO_ERROR;
|
||||
} else {
|
||||
result=input;
|
||||
result.toTitle((BreakIterator *)iter, Locale(cLocaleID));
|
||||
if(result!=myCase->getString("Output", status)) {
|
||||
errln("error: TestTitleCasing() got a wrong result for test case from casing.res");
|
||||
}
|
||||
}
|
||||
ubrk_close(iter);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("error: TestTitleCasing() ubrk_open(%d) failed for test case from casing.res: %s", type, u_errorName(status));
|
||||
status = U_ZERO_ERROR;
|
||||
} else {
|
||||
result=input;
|
||||
result.toTitle((BreakIterator *)iter, Locale(cLocaleID));
|
||||
if(result!=myCase->getString("Output", status)) {
|
||||
errln("error: TestTitleCasing() got a wrong result for test case from casing.res");
|
||||
}
|
||||
ubrk_close(iter);
|
||||
}
|
||||
}
|
||||
delete casingTest;
|
||||
}
|
||||
delete casingTest;
|
||||
}
|
||||
delete driver;
|
||||
delete driver;
|
||||
|
||||
// more tests for API coverage
|
||||
status=U_ZERO_ERROR;
|
||||
input=UNICODE_STRING_SIMPLE("sTrA\\u00dfE").unescape();
|
||||
(result=input).toTitle(NULL);
|
||||
if(result!=UNICODE_STRING_SIMPLE("Stra\\u00dfe").unescape()) {
|
||||
errln("UnicodeString::toTitle(BreakIterator *) failed");
|
||||
errln("UnicodeString::toTitle(NULL) failed");
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
|
Loading…
Add table
Reference in a new issue