ICU-6153 Fix for Windows versus non-Windows differences.

X-SVN-Rev: 23285
This commit is contained in:
George Rhoten 2008-01-22 00:11:43 +00:00
parent 32d24c4fca
commit 5391e72e09
2 changed files with 19 additions and 16 deletions

View File

@ -231,7 +231,6 @@ ChoiceFormat::dtos(double value,
char temp[DBL_DIG + 16];
char *itrPtr = temp;
char *expPtr;
char *startPtr;
sprintf(temp, "%.*g", DBL_DIG, value);
@ -251,23 +250,27 @@ ChoiceFormat::dtos(double value,
while (*itrPtr && *itrPtr != 'e') {
itrPtr++;
}
/* Verify the exponent sign */
if (*itrPtr == '+' || *itrPtr == '-') {
if (*itrPtr == 'e') {
itrPtr++;
}
/* Remove leading zeros. You will see this on non-Windows machines. */
expPtr = itrPtr;
while (*itrPtr && *itrPtr == '0') {
itrPtr++;
}
if (*itrPtr && expPtr != itrPtr) {
/* Shift the exponent without zeros. */
while (*itrPtr) {
*(expPtr++) = *(itrPtr++);
/* Verify the exponent sign */
if (*itrPtr == '+' || *itrPtr == '-') {
itrPtr++;
}
/* Remove leading zeros. You will see this on Windows machines. */
expPtr = itrPtr;
while (*itrPtr == '0') {
itrPtr++;
}
if (*itrPtr && expPtr != itrPtr) {
/* Shift the exponent without zeros. */
while (*itrPtr) {
*(expPtr++) = *(itrPtr++);
}
// NULL terminate
*expPtr = 0;
}
// NULL terminate
*itrPtr = 0;
}
string = UnicodeString(temp, -1, US_INV); /* invariant codepage */
return string;
}

View File

@ -621,7 +621,7 @@ void TestChoiceFormat::TestChoiceFormatToPatternOverflow()
static const double limits[] = {0.1e-78, 1e13, 0.1e78};
UnicodeString monthNames[] = { "one", "two", "three" };
ChoiceFormat fmt(limits, monthNames, sizeof(limits)/sizeof(limits[0]));
UnicodeString patStr, expectedPattern("1e-079#one|10000000000000#two|1e+077#three");
UnicodeString patStr, expectedPattern("1e-79#one|10000000000000#two|1e+77#three");
fmt.toPattern(patStr);
if (patStr != expectedPattern) {
errln("ChoiceFormat returned \"" + patStr + "\" instead of \"" + expectedPattern + "\"");