ICU-463 extract with a NULL destination works properly now.
X-SVN-Rev: 2411
This commit is contained in:
parent
6c4991a04d
commit
5be423fddd
@ -1260,18 +1260,20 @@ UnicodeString::extract(UTextOffset start,
|
||||
&mySource, mySourceLimit, 0, TRUE, &status);
|
||||
} else {
|
||||
/* Find out the size of the target needed for the current codepage */
|
||||
char target = 0;
|
||||
char targetCh = 0;
|
||||
int32_t size = 0;
|
||||
|
||||
myTargetLimit = &target + sizeof(char);
|
||||
while (mySource < mySourceLimit && U_SUCCESS(status)) {
|
||||
myTarget = ⌖
|
||||
myTargetLimit = &targetCh + sizeof(char);
|
||||
status = U_BUFFER_OVERFLOW_ERROR;
|
||||
while (mySource < mySourceLimit && status == U_BUFFER_OVERFLOW_ERROR) {
|
||||
myTarget = &targetCh;
|
||||
status = U_ZERO_ERROR;
|
||||
ucnv_fromUnicode(converter, &myTarget, myTargetLimit,
|
||||
&mySource, mySourceLimit, 0, TRUE, &status);
|
||||
size += sizeof(char);
|
||||
}
|
||||
/* Use the close at the end of the function */
|
||||
myTarget = target + (char *)size;
|
||||
myTarget = target + size;
|
||||
}
|
||||
|
||||
// close the converter
|
||||
|
@ -185,20 +185,36 @@ UnicodeStringTest::TestCompare()
|
||||
void
|
||||
UnicodeStringTest::TestExtract()
|
||||
{
|
||||
UnicodeString test1("Now is the time for all good men to come to the aid of their country.");
|
||||
UnicodeString test2;
|
||||
UChar test3[13];
|
||||
char test4[13];
|
||||
UnicodeString test5;
|
||||
UnicodeString test1("Now is the time for all good men to come to the aid of their country.");
|
||||
UnicodeString test2;
|
||||
UChar test3[13] = {1, 2, 3, 4, 5, 6, 7, 8, 8, 10, 11, 12, 13};
|
||||
char test4[13] = {1, 2, 3, 4, 5, 6, 7, 8, 8, 10, 11, 12, 13};
|
||||
UnicodeString test5;
|
||||
char test6[13] = {1, 2, 3, 4, 5, 6, 7, 8, 8, 10, 11, 12, 13};
|
||||
|
||||
test1.extract(11, 12, test2);
|
||||
test1.extract(11, 12, test3);
|
||||
test1.extract(11, 12, test4);
|
||||
if (test1.extract(11, 12, test4) != 12 || test4[12] != 13) {
|
||||
errln("UnicodeString.extract(char *) failed to return the correct size of destination buffer.");
|
||||
}
|
||||
test1.extractBetween(11, 23, test5);
|
||||
if (test1.extract(60, 71, test6) != 9) {
|
||||
errln("UnicodeString.extract() failed to return the correct size of destination buffer for end of buffer.");
|
||||
}
|
||||
if (test1.extract(11, 12, test6) != 12) {
|
||||
errln("UnicodeString.extract() failed to return the correct size of destination buffer.");
|
||||
}
|
||||
|
||||
// convert test4 back to Unicode for comparison
|
||||
UnicodeString test4b(test4, 12);
|
||||
|
||||
if (test1.extract(11, 12, (char *)NULL) != 12) {
|
||||
errln("UnicodeString.extract(NULL) failed to return the correct size of destination buffer.");
|
||||
}
|
||||
if (test1.extract(11, -1, test6) != 0) {
|
||||
errln("UnicodeString.extract(-1) failed to stop reading the string.");
|
||||
}
|
||||
|
||||
for (UTextOffset i = 0; i < 12; i++) {
|
||||
if (test1[(UTextOffset)(11 + i)] != test2[i]) {
|
||||
errln(UnicodeString("extracting into a UnicodeString failed at position ") + i);
|
||||
|
Loading…
Reference in New Issue
Block a user