else {
const UnicodeString *tmp;
tmp = &getConstSymbol(DecimalFormatSymbols::kExponentialSymbol);
- if (!text.caseCompare(position, tmp->length(), *tmp, U_FOLD_CASE_DEFAULT)) // error code is set below if !sawDigit
+ if (!text.compare(position, tmp->length(), *tmp)) // error code is set below if !sawDigit
{
// Parse sign, if present
int32_t pos = position + tmp->length();
case Formattable::kInt64:
return fValue.fInt64;
case Formattable::kDouble:
- if (fValue.fDouble > U_INT64_MAX) {
+ if (fValue.fDouble >= U_INT64_MAX) {
status = U_INVALID_FORMAT_ERROR;
return U_INT64_MAX;
- } else if (fValue.fDouble < U_INT64_MIN) {
+ } else if (fValue.fDouble <= U_INT64_MIN) {
status = U_INVALID_FORMAT_ERROR;
return U_INT64_MIN;
} else {
/*
*******************************************************************************
*
-* Copyright (C) 1998-2006, International Business Machines
+* Copyright (C) 1998-2010, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
return parsePos + skipped;
}
+#define UPRINTF_SYMBOL_BUFFER_SIZE 8
+
static int32_t
u_scanf_scientific_handler(UFILE *input,
u_scanf_spec_info *info,
int32_t parsePos = 0;
int32_t skipped;
UErrorCode status = U_ZERO_ERROR;
+ UChar srcExpBuf[UPRINTF_SYMBOL_BUFFER_SIZE];
+ int32_t srcLen, expLen;
+ UChar expBuf[UPRINTF_SYMBOL_BUFFER_SIZE];
/* skip all ws in the input */
if(format == 0)
return 0;
+ /* set the appropriate flags on the formatter */
+
+ srcLen = unum_getSymbol(format,
+ UNUM_EXPONENTIAL_SYMBOL,
+ srcExpBuf,
+ sizeof(srcExpBuf),
+ &status);
+
+ /* Upper/lower case the e */
+ if (info->fSpec == (UChar)0x65 /* e */) {
+ expLen = u_strToLower(expBuf, (int32_t)sizeof(expBuf),
+ srcExpBuf, srcLen,
+ input->str.fBundle.fLocale,
+ &status);
+ }
+ else {
+ expLen = u_strToUpper(expBuf, (int32_t)sizeof(expBuf),
+ srcExpBuf, srcLen,
+ input->str.fBundle.fLocale,
+ &status);
+ }
+
+ unum_setSymbol(format,
+ UNUM_EXPONENTIAL_SYMBOL,
+ expBuf,
+ expLen,
+ &status);
+
+
+
+
/* Skip the positive prefix. ICU normally can't handle this due to strict parsing. */
skipped += u_scanf_skip_leading_positive_sign(input, format, &status);
void addNumForTest(TestNode** root);
static void TestTextAttributeCrash(void);
static void TestNBSPInPattern(void);
+static void TestInt64Parse(void);
#define TESTCASE(x) addTest(root, &x, "tsformat/cnumtst/" #x)
TESTCASE(TestTextAttributeCrash);
TESTCASE(TestRBNFFormat);
TESTCASE(TestNBSPInPattern);
+ TESTCASE(TestInt64Parse);
}
/** copy src to dst with unicode-escapes for values < 0x20 and > 0x7e, null terminate if possible */
return (int32_t)(p - dst);
}
+/* test Parse int 64 */
+
+static void TestInt64Parse()
+{
+
+ UErrorCode st = U_ZERO_ERROR;
+ UErrorCode* status = &st;
+
+ char* st1 = "009223372036854775808";
+ const int size = 21;
+ const int textLength = size;
+ UChar text[21];
+
+
+ UNumberFormat* nf;
+
+ int64_t a;
+
+ u_charsToUChars(st1, text, size);
+ nf = unum_open(UNUM_DEFAULT, NULL, -1, NULL, NULL, status);
+
+ if(U_FAILURE(*status))
+ {
+ log_err("Error in unum_open() %s \n", myErrorName(*status));
+ return;
+ }
+
+ log_verbose("About to test unum_parseInt64() with out of range number\n");
+
+ a = unum_parseInt64(nf, text, size, 0, status);
+
+
+ if(!U_FAILURE(*status))
+ {
+ log_err("Error in unum_parseInt64(): %s \n", myErrorName(*status));
+ }
+ else
+ {
+ log_verbose("unum_parseInt64() successful\n");
+ }
+
+ unum_close(nf);
+ return;
+}
+
/* test Number Format API */
static void TestNumberFormat()
{
CASE(45,TestFormatAttributes);
CASE(46,TestFieldPositionIterator);
CASE(47,TestDecimal);
+ CASE(49,TestExponentParse);
default: name = ""; break;
}
}
}
+void NumberFormatTest::TestExponentParse() {
+
+ UErrorCode status = U_ZERO_ERROR;
+ Formattable result;
+ ParsePosition parsePos(0);
+
+ // set the exponent symbol
+ status = U_ZERO_ERROR;
+ DecimalFormatSymbols *symbols = new DecimalFormatSymbols(Locale::getDefault(), status);
+ if(U_FAILURE(status)) {
+ errln((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);
+ if(result.getType() != Formattable::kDouble &&
+ result.getDouble() != (double)123 &&
+ parsePos.getIndex() != 3
+ )
+ {
+ errln("ERROR: parse failed - expected 123.0, 3 - returned %d, %i",
+ result.getDouble(), parsePos);
+ }
+}
+
#endif /* #if !UCONFIG_NO_FORMATTING */
void TestDecimal();
+ void TestExponentParse();
+
private:
static UBool equalValue(const Formattable& a, const Formattable& b);