mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-10 07:39:16 +00:00
ICU-4527 Fix "%.*G" for printf
X-SVN-Rev: 19692
This commit is contained in:
parent
7f2f9e4c63
commit
ad959a3e4d
4 changed files with 14 additions and 13 deletions
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1998-2004, International Business Machines
|
||||
* Copyright (C) 1998-2006, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
******************************************************************************
|
||||
|
@ -34,6 +34,7 @@ typedef struct u_printf_spec_info {
|
|||
int32_t fPrecision; /* Precision */
|
||||
int32_t fWidth; /* Width */
|
||||
|
||||
UChar fOrigSpec; /* Conversion specification */
|
||||
UChar fSpec; /* Conversion specification */
|
||||
UChar fPadChar; /* Padding character */
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1998-2005, International Business Machines
|
||||
* Copyright (C) 1998-2006, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
******************************************************************************
|
||||
|
@ -615,7 +615,13 @@ u_printf_scientific_handler(const u_printf_stream_handler *handler,
|
|||
/* set the appropriate flags and number of decimal digits on the formatter */
|
||||
if(info->fPrecision != -1) {
|
||||
/* set the # of decimal digits */
|
||||
unum_setAttribute(format, UNUM_FRACTION_DIGITS, info->fPrecision);
|
||||
if (info->fOrigSpec == (UChar)0x65 /* e */ || info->fOrigSpec == (UChar)0x45 /* E */) {
|
||||
unum_setAttribute(format, UNUM_FRACTION_DIGITS, info->fPrecision);
|
||||
}
|
||||
else {
|
||||
unum_setAttribute(format, UNUM_MIN_FRACTION_DIGITS, 1);
|
||||
unum_setAttribute(format, UNUM_MAX_FRACTION_DIGITS, info->fPrecision);
|
||||
}
|
||||
}
|
||||
else if(info->fAlt) {
|
||||
/* '#' means always show decimal point */
|
||||
|
@ -1076,19 +1082,10 @@ u_printf_parse(const u_printf_stream_handler *streamHandler,
|
|||
spec.fPrecisionPos = -1;
|
||||
spec.fArgPos = -1;
|
||||
|
||||
uprv_memset(info, 0, sizeof(*info));
|
||||
info->fPrecision = -1;
|
||||
info->fWidth = -1;
|
||||
info->fSpec = 0x0000;
|
||||
info->fPadChar = 0x0020;
|
||||
info->fAlt = FALSE;
|
||||
info->fSpace = FALSE;
|
||||
info->fLeft = FALSE;
|
||||
info->fShowSign = FALSE;
|
||||
info->fZero = FALSE;
|
||||
info->fIsLongDouble = FALSE;
|
||||
info->fIsShort = FALSE;
|
||||
info->fIsLong = FALSE;
|
||||
info->fIsLongLong = FALSE;
|
||||
|
||||
/* skip over the initial '%' */
|
||||
alias++;
|
||||
|
@ -1287,6 +1284,7 @@ u_printf_parse(const u_printf_stream_handler *streamHandler,
|
|||
|
||||
/* finally, get the specifier letter */
|
||||
info->fSpec = *alias++;
|
||||
info->fOrigSpec = info->fSpec;
|
||||
|
||||
/* fill in the precision and width, if specified out of line */
|
||||
|
||||
|
|
|
@ -1110,6 +1110,7 @@ static void TestFprintfFormat(void) {
|
|||
TestFPrintFormat("%-10g", 1.23456789, "%-10g", 1.23456789);
|
||||
TestFPrintFormat("%10g", 123.456789, "%10g", 123.456789);
|
||||
TestFPrintFormat("%-10g", 123.456789, "%-10g", 123.456789);
|
||||
TestFPrintFormat("%.14G", 1.7e64, "%.14G", 1.7e64);
|
||||
|
||||
TestFPrintFormat("%8x", 123456, "%8x", 123456);
|
||||
TestFPrintFormat("%-8x", 123456, "%-8x", 123456);
|
||||
|
|
|
@ -418,6 +418,7 @@ static void TestSprintfFormat(void) {
|
|||
TestSPrintFormat("%-10g", 1.23456789, "%-10g", 1.23456789);
|
||||
TestSPrintFormat("%10g", 123.456789, "%10g", 123.456789);
|
||||
TestSPrintFormat("%-10g", 123.456789, "%-10g", 123.456789);
|
||||
TestSPrintFormat("%.14G", 1.7e64, "%.14G", 1.7e64);
|
||||
|
||||
TestSPrintFormat("%8x", 123456, "%8x", 123456);
|
||||
TestSPrintFormat("%-8x", 123456, "%-8x", 123456);
|
||||
|
|
Loading…
Add table
Reference in a new issue