2 ******************************************************************************
4 * Copyright (C) 1998-2004, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 ******************************************************************************
11 * Modification History:
13 * Date Name Description
14 * 11/19/98 stephen Creation.
15 * 03/12/99 stephen Modified for new C API.
16 * Added conversion from default codepage.
17 * 08/07/2003 george Reunify printf implementations
18 ******************************************************************************
21 #include "unicode/utypes.h"
23 #if !UCONFIG_NO_FORMATTING
25 #include "unicode/ustdio.h"
26 #include "unicode/ustring.h"
27 #include "unicode/unum.h"
28 #include "unicode/udat.h"
29 #include "unicode/putil.h"
37 static int32_t U_EXPORT2
38 u_printf_write(void *context
,
42 return u_file_write(str
, count
, (UFILE
*)context
);
46 u_printf_pad_and_justify(void *context
,
47 const u_printf_spec_info
*info
,
51 UFILE
*output
= (UFILE
*)context
;
54 /* pad and justify, if needed */
55 if(info
->fWidth
!= -1 && resultLen
< info
->fWidth
) {
58 written
= u_file_write(result
, resultLen
, output
);
59 for(i
= 0; i
< info
->fWidth
- resultLen
; ++i
) {
60 written
+= u_file_write(&info
->fPadChar
, 1, output
);
66 for(i
= 0; i
< info
->fWidth
- resultLen
; ++i
) {
67 written
+= u_file_write(&info
->fPadChar
, 1, output
);
69 written
+= u_file_write(result
, resultLen
, output
);
72 /* just write the formatted output */
74 written
= u_file_write(result
, resultLen
, output
);
80 U_CAPI
int32_t U_EXPORT2
82 const char *patternSpecification
,
88 va_start(ap
, patternSpecification
);
89 count
= u_vfprintf(f
, patternSpecification
, ap
);
95 U_CAPI
int32_t U_EXPORT2
96 u_fprintf_u( UFILE
*f
,
97 const UChar
*patternSpecification
,
103 va_start(ap
, patternSpecification
);
104 count
= u_vfprintf_u(f
, patternSpecification
, ap
);
110 U_CAPI
int32_t U_EXPORT2
/* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
111 u_vfprintf( UFILE
*f
,
112 const char *patternSpecification
,
117 UChar buffer
[UFMT_DEFAULT_BUFFER_SIZE
];
118 int32_t size
= (int32_t)strlen(patternSpecification
) + 1;
120 /* convert from the default codepage to Unicode */
121 if (size
>= MAX_UCHAR_BUFFER_SIZE(buffer
)) {
122 pattern
= (UChar
*)uprv_malloc(size
* sizeof(UChar
));
130 u_charsToUChars(patternSpecification
, pattern
, size
);
133 count
= u_vfprintf_u(f
, pattern
, ap
);
136 if (pattern
!= buffer
) {
143 static const u_printf_stream_handler g_stream_handler
= {
145 u_printf_pad_and_justify
148 U_CAPI
int32_t U_EXPORT2
/* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
149 u_vfprintf_u( UFILE
*f
,
150 const UChar
*patternSpecification
,
153 int32_t written
= 0; /* haven't written anything yet */
155 /* parse and print the whole format string */
156 u_printf_parse(&g_stream_handler
, patternSpecification
, f
, NULL
, &f
->str
.fBundle
, &written
, ap
);
158 /* return # of UChars written */
162 #endif /* #if !UCONFIG_NO_FORMATTING */