ICU-5025 %f, %e and %g for scanf should expect a float by default.
X-SVN-Rev: 19457
This commit is contained in:
parent
9460da6828
commit
83097bf105
@ -411,7 +411,12 @@ u_scanf_double_handler(UFILE *input,
|
||||
num = unum_parseDouble(format, input->str.fPos, len, &parsePos, &status);
|
||||
|
||||
if (!info->fSkipArg) {
|
||||
*(double*)(args[0].ptrValue) = num;
|
||||
if (info->fIsLong)
|
||||
*(double*)(args[0].ptrValue) = num;
|
||||
else if (info->fIsLongDouble)
|
||||
*(long double*)(args[0].ptrValue) = num;
|
||||
else
|
||||
*(float*)(args[0].ptrValue) = (float)num;
|
||||
}
|
||||
|
||||
/* mask off any necessary bits */
|
||||
@ -465,7 +470,12 @@ u_scanf_scientific_handler(UFILE *input,
|
||||
num = unum_parseDouble(format, input->str.fPos, len, &parsePos, &status);
|
||||
|
||||
if (!info->fSkipArg) {
|
||||
*(double*)(args[0].ptrValue) = num;
|
||||
if (info->fIsLong)
|
||||
*(double*)(args[0].ptrValue) = num;
|
||||
else if (info->fIsLongDouble)
|
||||
*(long double*)(args[0].ptrValue) = num;
|
||||
else
|
||||
*(float*)(args[0].ptrValue) = (float)num;
|
||||
}
|
||||
|
||||
/* mask off any necessary bits */
|
||||
@ -549,7 +559,12 @@ u_scanf_scidbl_handler(UFILE *input,
|
||||
input->str.fPos += parsePos;
|
||||
|
||||
if (!info->fSkipArg) {
|
||||
*(double*)(args[0].ptrValue) = num;
|
||||
if (info->fIsLong)
|
||||
*(double*)(args[0].ptrValue) = num;
|
||||
else if (info->fIsLongDouble)
|
||||
*(long double*)(args[0].ptrValue) = num;
|
||||
else
|
||||
*(float*)(args[0].ptrValue) = (float)num;
|
||||
}
|
||||
|
||||
/* mask off any necessary bits */
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 2004-2005, International Business Machines
|
||||
* Copyright (C) 2004-2006, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* file name: filetst.c
|
||||
@ -163,27 +163,27 @@ static void TestFileFromICU(UFILE *myFile) {
|
||||
log_err("%%X Got: %X, Expected: %X\n", *newValuePtr, *n);
|
||||
}
|
||||
*newDoubleValuePtr = -1.0;
|
||||
u_fscanf(myFile, "Float %%f: %f\n", newDoubleValuePtr);
|
||||
u_fscanf(myFile, "Float %%f: %lf\n", newDoubleValuePtr);
|
||||
if (myFloat != *newDoubleValuePtr) {
|
||||
log_err("%%f Got: %f, Expected: %f\n", *newDoubleValuePtr, myFloat);
|
||||
}
|
||||
*newDoubleValuePtr = -1.0;
|
||||
u_fscanf(myFile, "Lowercase float %%e: %e\n", newDoubleValuePtr);
|
||||
u_fscanf(myFile, "Lowercase float %%e: %le\n", newDoubleValuePtr);
|
||||
if (myFloat != *newDoubleValuePtr) {
|
||||
log_err("%%e Got: %e, Expected: %e\n", *newDoubleValuePtr, myFloat);
|
||||
}
|
||||
*newDoubleValuePtr = -1.0;
|
||||
u_fscanf(myFile, "Uppercase float %%E: %E\n", newDoubleValuePtr);
|
||||
u_fscanf(myFile, "Uppercase float %%E: %lE\n", newDoubleValuePtr);
|
||||
if (myFloat != *newDoubleValuePtr) {
|
||||
log_err("%%E Got: %E, Expected: %E\n", *newDoubleValuePtr, myFloat);
|
||||
}
|
||||
*newDoubleValuePtr = -1.0;
|
||||
u_fscanf(myFile, "Lowercase float %%g: %g\n", newDoubleValuePtr);
|
||||
u_fscanf(myFile, "Lowercase float %%g: %lg\n", newDoubleValuePtr);
|
||||
if (myFloat != *newDoubleValuePtr) {
|
||||
log_err("%%g Got: %g, Expected: %g\n", *newDoubleValuePtr, myFloat);
|
||||
}
|
||||
*newDoubleValuePtr = -1.0;
|
||||
u_fscanf(myFile, "Uppercase float %%G: %G\n", newDoubleValuePtr);
|
||||
u_fscanf(myFile, "Uppercase float %%G: %lG\n", newDoubleValuePtr);
|
||||
if (myFloat != *newDoubleValuePtr) {
|
||||
log_err("%%G Got: %G, Expected: %G\n", *newDoubleValuePtr, myFloat);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 2002-2005, International Business Machines
|
||||
* Copyright (C) 2002-2006, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* file name: iotest.cpp
|
||||
@ -361,6 +361,7 @@ static void U_CALLCONV DataDrivenScanf(void)
|
||||
int32_t i32, expected32;
|
||||
int64_t i64, expected64;
|
||||
double dbl, expectedDbl;
|
||||
float flt, expectedFlt;
|
||||
int32_t uBufferLenReturned;
|
||||
|
||||
//const char *fileLocale = "en_US_POSIX";
|
||||
@ -410,6 +411,15 @@ static void U_CALLCONV DataDrivenScanf(void)
|
||||
i, dbl, expectedDbl);
|
||||
}
|
||||
break;
|
||||
case 0x66: // 'f' float
|
||||
expectedFlt = (float)atof(u_austrcpy(cBuffer, expectedResult));
|
||||
uBufferLenReturned = u_sscanf_u(argument, format, &flt);
|
||||
//uFileBufferLenReturned = u_fscanf_u(testFile, format, flt);
|
||||
if (flt != expectedFlt) {
|
||||
log_err("error in scanf test case[%d] Got: %f Exp: %f\n",
|
||||
i, flt, expectedFlt);
|
||||
}
|
||||
break;
|
||||
case 0x31: // '1' int8_t
|
||||
expected8 = (int8_t)uto64(expectedResult);
|
||||
uBufferLenReturned = u_sscanf_u(argument, format, &i8);
|
||||
|
@ -93,35 +93,35 @@ static void TestString(void) {
|
||||
|
||||
u_sprintf(uStringBuf, "Float f: %f", myFloat);
|
||||
*newDoubleValuePtr = -1.0;
|
||||
u_sscanf(uStringBuf, "Float f: %f", newDoubleValuePtr);
|
||||
u_sscanf(uStringBuf, "Float f: %lf", newDoubleValuePtr);
|
||||
if (myFloat != *newDoubleValuePtr) {
|
||||
log_err("%%f Got: %f, Expected: %f\n", *newDoubleValuePtr, myFloat);
|
||||
}
|
||||
|
||||
u_sprintf(uStringBuf, "Lowercase float e: %e", myFloat);
|
||||
*newDoubleValuePtr = -1.0;
|
||||
u_sscanf(uStringBuf, "Lowercase float e: %e", newDoubleValuePtr);
|
||||
u_sscanf(uStringBuf, "Lowercase float e: %le", newDoubleValuePtr);
|
||||
if (myFloat != *newDoubleValuePtr) {
|
||||
log_err("%%e Got: %e, Expected: %e\n", *newDoubleValuePtr, myFloat);
|
||||
}
|
||||
|
||||
u_sprintf(uStringBuf, "Uppercase float E: %E", myFloat);
|
||||
*newDoubleValuePtr = -1.0;
|
||||
u_sscanf(uStringBuf, "Uppercase float E: %E", newDoubleValuePtr);
|
||||
u_sscanf(uStringBuf, "Uppercase float E: %lE", newDoubleValuePtr);
|
||||
if (myFloat != *newDoubleValuePtr) {
|
||||
log_err("%%E Got: %E, Expected: %E\n", *newDoubleValuePtr, myFloat);
|
||||
}
|
||||
|
||||
u_sprintf(uStringBuf, "Lowercase float g: %g", myFloat);
|
||||
*newDoubleValuePtr = -1.0;
|
||||
u_sscanf(uStringBuf, "Lowercase float g: %g", newDoubleValuePtr);
|
||||
u_sscanf(uStringBuf, "Lowercase float g: %lg", newDoubleValuePtr);
|
||||
if (myFloat != *newDoubleValuePtr) {
|
||||
log_err("%%g Got: %g, Expected: %g\n", *newDoubleValuePtr, myFloat);
|
||||
}
|
||||
|
||||
u_sprintf(uStringBuf, "Uppercase float G: %G", myFloat);
|
||||
*newDoubleValuePtr = -1.0;
|
||||
u_sscanf(uStringBuf, "Uppercase float G: %G", newDoubleValuePtr);
|
||||
u_sscanf(uStringBuf, "Uppercase float G: %lG", newDoubleValuePtr);
|
||||
if (myFloat != *newDoubleValuePtr) {
|
||||
log_err("%%G Got: %G, Expected: %G\n", *newDoubleValuePtr, myFloat);
|
||||
}
|
||||
|
22
icu4c/source/test/testdata/icuio.txt
vendored
22
icu4c/source/test/testdata/icuio.txt
vendored
@ -1,6 +1,6 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (C) 2004-2005, International Business Machines
|
||||
// Copyright (C) 2004-2006, International Business Machines
|
||||
// Corporation and others. All Rights Reserved.
|
||||
//
|
||||
// file name: icuio.txt
|
||||
@ -24,6 +24,7 @@ icuio:table(nofallback) {
|
||||
|
||||
"argumentType:\n"
|
||||
"\td: double\n"
|
||||
"\tf: float\n"
|
||||
"\t1: int8_t (hexadecimal)\n"
|
||||
"\t2: int16_t (hexadecimal)\n"
|
||||
"\t4: int32_t (hexadecimal)\n"
|
||||
@ -117,8 +118,8 @@ icuio:table(nofallback) {
|
||||
scanf {
|
||||
Headers { "format", "argument", "argumentType", "result" }
|
||||
Cases {
|
||||
{ "%e", "1.200000e+000", "d", "1.2" }
|
||||
{ "%*e%e", "1.200000e+000 4.825000e+000", "d", "4.825" }
|
||||
{ "%e", "1.200000e+000", "f", "1.2" }
|
||||
{ "%*e%e", "1.200000e+000 4.825000e+000", "f", "4.825" }
|
||||
{ "%C", "1234", "2", "31" }
|
||||
{ "%*C%C", "1234", "2", "32" }
|
||||
{ "%S", "1234 5678", "S", "1234" }
|
||||
@ -132,12 +133,15 @@ icuio:table(nofallback) {
|
||||
{ "%4d", "123", "4", "7B" }
|
||||
{ "%2d", "123", "4", "C" }
|
||||
{ "%40d", "123", "4", "7B" }
|
||||
{ "%2e", "1.25", "d", "1" }
|
||||
{ "%2f", "1.25", "d", "1" }
|
||||
{ "%2g", "1.25", "d", "1" }
|
||||
{ "%*2e%2e", "1.25", "d", "25" }
|
||||
{ "%*2f%2f", "1.25", "d", "25" }
|
||||
{ "%*2g%2g", "1.25", "d", "25" }
|
||||
{ "%2e", "1.25", "f", "1" }
|
||||
{ "%2f", "1.25", "f", "1" }
|
||||
{ "%2g", "1.25", "f", "1" }
|
||||
{ "%2le", "1.25", "d", "1" }
|
||||
{ "%2lf", "1.25", "d", "1" }
|
||||
{ "%2lg", "1.25", "d", "1" }
|
||||
{ "%*2e%2e", "1.25", "f", "25" }
|
||||
{ "%*2f%2f", "1.25", "f", "25" }
|
||||
{ "%*2g%2g", "1.25", "f", "25" }
|
||||
{ "%*d%d", "1234 5678", "4", "162E" }
|
||||
{ "%x", "abcd ef01", "4", "abcd" }
|
||||
{ "%3x", "abcd ef01", "4", "abc" }
|
||||
|
Loading…
Reference in New Issue
Block a user