ICU-4384 Make sure u_snprintf and similar functions conform to POSIX snprintf and change test to reflect this.
X-SVN-Rev: 22878
This commit is contained in:
parent
88f2f061d7
commit
bd5dc8355d
@ -1,7 +1,7 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2001-2004, International Business Machines
|
||||
* Copyright (C) 2001-2007, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
******************************************************************************
|
||||
@ -54,6 +54,7 @@ u_sprintf_pad_and_justify(void *context,
|
||||
{
|
||||
u_localized_print_string *output = (u_localized_print_string *)context;
|
||||
int32_t written = 0;
|
||||
int32_t lengthOfResult = resultLen;
|
||||
|
||||
resultLen = ufmt_min(resultLen, output->available);
|
||||
|
||||
@ -88,6 +89,10 @@ u_sprintf_pad_and_justify(void *context,
|
||||
else {
|
||||
written = u_sprintf_write(output, result, resultLen);
|
||||
}
|
||||
|
||||
if (written >= 0 && lengthOfResult > written) {
|
||||
return lengthOfResult;
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1998-2006, International Business Machines
|
||||
* Copyright (C) 1998-2007, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
******************************************************************************
|
||||
@ -1059,7 +1059,7 @@ u_printf_parse(const u_printf_stream_handler *streamHandler,
|
||||
const UChar *lastAlias;
|
||||
|
||||
/* iterate through the pattern */
|
||||
while(!locStringContext || locStringContext->available > 0) {
|
||||
while(!locStringContext || locStringContext->available >= 0) {
|
||||
|
||||
/* find the next '%' */
|
||||
lastAlias = alias;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 2004-2006, International Business Machines
|
||||
* Copyright (C) 2004-2007, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* file name: strtst.c
|
||||
@ -330,26 +330,26 @@ static void TestSnprintf(void) {
|
||||
char cTestResult[256];
|
||||
int32_t size;
|
||||
|
||||
Test_u_snprintf(0, "%d", 123, 0, "xxxxxxxxxxxxxx");
|
||||
Test_u_snprintf(2, "%d", 123, 2, "12xxxxxxxxxxxx");
|
||||
Test_u_snprintf(0, "%d", 123, 3, "xxxxxxxxxxxxxx");
|
||||
Test_u_snprintf(2, "%d", 123, 3, "12xxxxxxxxxxxx");
|
||||
Test_u_snprintf(3, "%d", 123, 3, "123xxxxxxxxxxx");
|
||||
Test_u_snprintf(4, "%d", 123, 3, "123");
|
||||
|
||||
Test_u_snprintf(0, "%s", "abcd", 0, "xxxxxxxxxxxxxx");
|
||||
Test_u_snprintf(3, "%s", "abcd", 3, "abcxxxxxxxxxxx");
|
||||
Test_u_snprintf(0, "%s", "abcd", 4, "xxxxxxxxxxxxxx");
|
||||
Test_u_snprintf(3, "%s", "abcd", 4, "abcxxxxxxxxxxx");
|
||||
Test_u_snprintf(4, "%s", "abcd", 4, "abcdxxxxxxxxxx");
|
||||
Test_u_snprintf(5, "%s", "abcd", 4, "abcd");
|
||||
|
||||
Test_u_snprintf(0, "%e", 12.34, 0, "xxxxxxxxxxxxxx");
|
||||
Test_u_snprintf(1, "%e", 12.34, 1, "1xxxxxxxxxxxxx");
|
||||
Test_u_snprintf(2, "%e", 12.34, 2, "1.xxxxxxxxxxxx");
|
||||
Test_u_snprintf(3, "%e", 12.34, 3, "1.2xxxxxxxxxxx");
|
||||
Test_u_snprintf(5, "%e", 12.34, 5, "1.234xxxxxxxxx");
|
||||
Test_u_snprintf(6, "%e", 12.34, 6, "1.2340xxxxxxxx");
|
||||
Test_u_snprintf(8, "%e", 12.34, 8, "1.234000xxxxxx");
|
||||
Test_u_snprintf(9, "%e", 12.34, 9, "1.234000exxxxx");
|
||||
Test_u_snprintf(10, "%e", 12.34, 10, "1.234000e+xxxx");
|
||||
Test_u_snprintf(11, "%e", 12.34, 11, "1.234000e+0xxx");
|
||||
Test_u_snprintf(0, "%e", 12.34, 13, "xxxxxxxxxxxxxx");
|
||||
Test_u_snprintf(1, "%e", 12.34, 13, "1xxxxxxxxxxxxx");
|
||||
Test_u_snprintf(2, "%e", 12.34, 13, "1.xxxxxxxxxxxx");
|
||||
Test_u_snprintf(3, "%e", 12.34, 13, "1.2xxxxxxxxxxx");
|
||||
Test_u_snprintf(5, "%e", 12.34, 13, "1.234xxxxxxxxx");
|
||||
Test_u_snprintf(6, "%e", 12.34, 13, "1.2340xxxxxxxx");
|
||||
Test_u_snprintf(8, "%e", 12.34, 13, "1.234000xxxxxx");
|
||||
Test_u_snprintf(9, "%e", 12.34, 13, "1.234000exxxxx");
|
||||
Test_u_snprintf(10, "%e", 12.34, 13, "1.234000e+xxxx");
|
||||
Test_u_snprintf(11, "%e", 12.34, 13, "1.234000e+0xxx");
|
||||
Test_u_snprintf(13, "%e", 12.34, 13, "1.234000e+001x");
|
||||
Test_u_snprintf(14, "%e", 12.34, 13, "1.234000e+001");
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user