From 206c94626776904e22a24f2f032c29e0410d33ab Mon Sep 17 00:00:00 2001 From: Eric Mader Date: Mon, 7 Mar 2011 20:02:28 +0000 Subject: [PATCH] ICU-8407 Use a case-insensitive compare when matching the exponent symbol. X-SVN-Rev: 29551 --- icu4c/source/i18n/decimfmt.cpp | 2 +- icu4c/source/test/cintltst/cnumtst.c | 11 ++++++++++- icu4c/source/test/intltest/numfmtst.cpp | 15 +++++++-------- icu4c/source/test/intltest/tsnmfmt.cpp | 10 +++++++++- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/icu4c/source/i18n/decimfmt.cpp b/icu4c/source/i18n/decimfmt.cpp index b594a500178..9209e6db383 100644 --- a/icu4c/source/i18n/decimfmt.cpp +++ b/icu4c/source/i18n/decimfmt.cpp @@ -1961,7 +1961,7 @@ UBool DecimalFormat::subparse(const UnicodeString& text, else { const UnicodeString *tmp; tmp = &getConstSymbol(DecimalFormatSymbols::kExponentialSymbol); - if (!text.compare(position, tmp->length(), *tmp)) // error code is set below if !sawDigit + if (!text.caseCompare(position, tmp->length(), *tmp, U_FOLD_CASE_DEFAULT)) // error code is set below if !sawDigit { // Parse sign, if present int32_t pos = position + tmp->length(); diff --git a/icu4c/source/test/cintltst/cnumtst.c b/icu4c/source/test/cintltst/cnumtst.c index f0f0661c454..10e5428cc00 100644 --- a/icu4c/source/test/cintltst/cnumtst.c +++ b/icu4c/source/test/cintltst/cnumtst.c @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2010, International Business Machines Corporation and + * Copyright (c) 1997-2011, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /******************************************************************************** @@ -1306,6 +1306,15 @@ static void TestInt64Format() { } else if (!withinErr(valDouble, doubleBig, 1e-15)) { log_err("parseDouble returned incorrect value, got: %g\n", valDouble); } + } + + u_uastrcpy(result, "5.06e-27"); + parsepos = 0; + valDouble = unum_parseDouble(fmt, result, u_strlen(result), &parsepos, &status); + if (U_FAILURE(status)) { + log_err("parseDouble() returned error: %s\n", myErrorName(status)); + } else if (!withinErr(valDouble, 5.06e-27, 1e-15)) { + log_err("parseDouble() returned incorrect value, got: %g\n", valDouble); } } unum_close(fmt); diff --git a/icu4c/source/test/intltest/numfmtst.cpp b/icu4c/source/test/intltest/numfmtst.cpp index 91909bb418d..bba6c694b18 100644 --- a/icu4c/source/test/intltest/numfmtst.cpp +++ b/icu4c/source/test/intltest/numfmtst.cpp @@ -6203,24 +6203,23 @@ void NumberFormatTest::TestExponentParse() { dataerrln((UnicodeString)"ERROR: Could not create DecimalFormatSymbols (Default)"); return; } - symbols->setSymbol(DecimalFormatSymbols::kExponentialSymbol,"e"); - + // create format instance status = U_ZERO_ERROR; DecimalFormat fmt("#####", symbols, status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: Could not create DecimalFormat (pattern, symbols*)"); } - + // parse the text - fmt.parse("123E4", result, parsePos); + fmt.parse("5.06e-27", result, parsePos); if(result.getType() != Formattable::kDouble && - result.getDouble() != (double)123 && - parsePos.getIndex() != 3 + result.getDouble() != 5.06E-27 && + parsePos.getIndex() != 8 ) { - errln("ERROR: parse failed - expected 123.0, 3 - returned %d, %i", - result.getDouble(), parsePos.getIndex()); + errln("ERROR: parse failed - expected 5.06E-27, 8 - returned %d, %i", + result.getDouble(), parsePos.getIndex()); } } diff --git a/icu4c/source/test/intltest/tsnmfmt.cpp b/icu4c/source/test/intltest/tsnmfmt.cpp index a04a2bd3f3b..479113e015e 100644 --- a/icu4c/source/test/intltest/tsnmfmt.cpp +++ b/icu4c/source/test/intltest/tsnmfmt.cpp @@ -1,6 +1,6 @@ /*********************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2009, International Business Machines Corporation + * Copyright (c) 1997-2011, International Business Machines Corporation * and others. All Rights Reserved. ***********************************************************************/ @@ -93,6 +93,12 @@ IntlTestNumberFormat::testLocale(/* char* par, */const Locale& locale, const Uni fStatus = U_ZERO_ERROR; fFormat = NumberFormat::createPercentInstance(locale, fStatus); testFormat(/* par */); + + name = "Scientific test"; + logln((UnicodeString)name + " (" + localeName + ")"); + fStatus = U_ZERO_ERROR; + fFormat = NumberFormat::createScientificInstance(locale, fStatus); + testFormat(/* par */); } double IntlTestNumberFormat::randDouble() @@ -210,6 +216,8 @@ IntlTestNumberFormat::testFormat(/* char* par */) tryIt(1.234e-50); tryIt(9.99999999999996); tryIt(9.999999999999996); + + tryIt(5.06e-27); tryIt((int32_t)INT32_MIN); tryIt((int32_t)INT32_MAX);