diff --git a/icu4c/source/io/uprntf_p.c b/icu4c/source/io/uprntf_p.c index 4facd6cc13a..6f6531efea6 100644 --- a/icu4c/source/io/uprntf_p.c +++ b/icu4c/source/io/uprntf_p.c @@ -260,16 +260,9 @@ u_printf_char_handler(const u_printf_stream_handler *handler, /* width = minimum # of characters to write */ /* precision = maximum # of characters to write */ + /* precision is ignored when handling a char */ - /* precision takes precedence over width */ - /* determine if the string should be truncated */ - if(info->fPrecision != -1 && len > info->fPrecision) { - written = handler->write(context, s, info->fPrecision); - } - else { - /* determine if the string should be padded */ - written = handler->pad_and_justify(context, info, s, len); - } + written = handler->pad_and_justify(context, info, s, len); return written; } @@ -781,20 +774,12 @@ u_printf_uchar_handler(const u_printf_stream_handler *handler, int32_t written = 0; UChar arg = (UChar)(args[0].int64Value); - /* width = minimum # of characters to write */ /* precision = maximum # of characters to write */ + /* precision is ignored when handling a uchar */ - /* precision takes precedence over width */ - /* determine if the char should be printed */ - if(info->fPrecision != -1 && info->fPrecision < 1) { - /* write nothing */ - written = 0; - } - else { - /* determine if the string should be padded */ - written = handler->pad_and_justify(context, info, &arg, 1); - } + /* determine if the string should be padded */ + written = handler->pad_and_justify(context, info, &arg, 1); return written; } diff --git a/icu4c/source/test/iotest/filetst.c b/icu4c/source/test/iotest/filetst.c index 4f8d0bcad5c..8585c8a93fd 100644 --- a/icu4c/source/test/iotest/filetst.c +++ b/icu4c/source/test/iotest/filetst.c @@ -1083,9 +1083,13 @@ static void TestFprintfFormat(void) { TestFPrintFormat("%8c", (char)'e', "%8c", (char)'e'); TestFPrintFormat("%-8c", (char)'e', "%-8c", (char)'e'); + TestFPrintFormat("%5.3c", (char)'e', "%5.3c", (char)'e'); + TestFPrintFormat("%-5.3c", (char)'e', "%-5.3c", (char)'e'); TestFPrintFormat("%8C", (UChar)0x65, "%8c", (char)'e'); TestFPrintFormat("%-8C", (UChar)0x65, "%-8c", (char)'e'); + TestFPrintFormat("%5.3C", (UChar)0x65, "%5.3c", (char)'e'); + TestFPrintFormat("%-5.3C", (UChar)0x65, "%-5.3c", (char)'e'); TestFPrintFormat("%f", 1.23456789, "%f", 1.23456789); TestFPrintFormat("%f", 12345.6789, "%f", 12345.6789); diff --git a/icu4c/source/test/iotest/strtst.c b/icu4c/source/test/iotest/strtst.c index 906f519d3c2..9bc6423906a 100644 --- a/icu4c/source/test/iotest/strtst.c +++ b/icu4c/source/test/iotest/strtst.c @@ -391,9 +391,13 @@ static void TestSprintfFormat(void) { TestSPrintFormat("%8c", (char)'e', "%8c", (char)'e'); TestSPrintFormat("%-8c", (char)'e', "%-8c", (char)'e'); + TestSPrintFormat("%5.3c", (char)'e', "%5.3c", (char)'e'); + TestSPrintFormat("%-5.3c", (char)'e', "%-5.3c", (char)'e'); TestSPrintFormat("%8C", (UChar)0x65, "%8c", (char)'e'); TestSPrintFormat("%-8C", (UChar)0x65, "%-8c", (char)'e'); + TestSPrintFormat("%5.3C", (UChar)0x65, "%5.3c", (char)'e'); + TestSPrintFormat("%-5.3C", (UChar)0x65, "%-5.3c", (char)'e'); TestSPrintFormat("%f", 1.23456789, "%f", 1.23456789); TestSPrintFormat("%f", 12345.6789, "%f", 12345.6789); diff --git a/icu4c/source/test/testdata/icuio.txt b/icu4c/source/test/testdata/icuio.txt index 621cec6d16d..e83fb3d5461 100644 --- a/icu4c/source/test/testdata/icuio.txt +++ b/icu4c/source/test/testdata/icuio.txt @@ -48,6 +48,9 @@ icuio { { "%-5.3s", "abc ", "s", "abcdef" } { "%5.3s", " a", "s", "a" } { "%-5.3s", "a ", "s", "a" } + { "%5.3C", " a", "2", "61" } + { "%-5.3C", "a ", "2", "61" } + { "%-5.0C", "a ", "2", "61" } // Make sure that the precision is ignored. { "%.3P", "120.000%", "d", "1.2" } { "%.0P", "120%", "d", "1.2" } { "%.3P", "1.200%", "d", "0.012" }