1// © 2016 and later: Unicode, Inc. and others. 2// License & terms of use: http://www.unicode.org/copyright.html 3/* 4****************************************************************************** 5* 6* Copyright (C) 1998-2006, International Business Machines 7* Corporation and others. All Rights Reserved. 8* 9****************************************************************************** 10* 11* File uprintf.h 12* 13* Modification History: 14* 15* Date Name Description 16* 11/19/98 stephen Creation. 17* 03/12/99 stephen Modified for new C API. 18****************************************************************************** 19*/ 20 21#ifndef UPRINTF_H 22#define UPRINTF_H 23 24#include "unicode/utypes.h" 25 26#if !UCONFIG_NO_FORMATTING 27 28#include "unicode/ustdio.h" 29#include "ufmt_cmn.h" 30#include "locbund.h" 31 32/** 33 * Struct encapsulating a single uprintf format specification. 34 */ 35typedef struct u_printf_spec_info { 36 int32_t fPrecision; /* Precision */ 37 int32_t fWidth; /* Width */ 38 39 UChar fOrigSpec; /* Conversion specification */ 40 UChar fSpec; /* Conversion specification */ 41 UChar fPadChar; /* Padding character */ 42 43 UBool fAlt; /* # flag */ 44 UBool fSpace; /* Space flag */ 45 UBool fLeft; /* - flag */ 46 UBool fShowSign; /* + flag */ 47 UBool fZero; /* 0 flag */ 48 49 UBool fIsLongDouble; /* L flag */ 50 UBool fIsShort; /* h flag */ 51 UBool fIsLong; /* l flag */ 52 UBool fIsLongLong; /* ll flag */ 53} u_printf_spec_info; 54 55typedef int32_t U_EXPORT2 56u_printf_write_stream(void *context, 57 const UChar *str, 58 int32_t count); 59 60typedef int32_t U_EXPORT2 61u_printf_pad_and_justify_stream(void *context, 62 const u_printf_spec_info *info, 63 const UChar *result, 64 int32_t resultLen); 65 66typedef struct u_printf_stream_handler { 67 u_printf_write_stream *write; 68 u_printf_pad_and_justify_stream *pad_and_justify; 69} u_printf_stream_handler; 70 71/* Used by sprintf */ 72typedef struct u_localized_print_string { 73 UChar *str; /* Place to write the string */ 74 int32_t available;/* Number of codeunits available to write to */ 75 int32_t len; /* Maximum number of code units that can be written to output */ 76 77 ULocaleBundle fBundle; /* formatters */ 78} u_localized_print_string; 79 80#define UP_PERCENT 0x0025 81 82/** 83 * Parse a single u_printf format string. 84 * @param fmt A pointer to a '%' character in a u_printf format specification. 85 * @param spec A pointer to a <TT>u_printf_spec</TT> to receive the parsed 86 * format specifier. 87 * @param locStringContext If present, will make sure that it will only write 88 * to the buffer when space is available. It's done this way because 89 * va_list sometimes can't be passed by pointer. 90 * @return The number of characters contained in this specifier. 91 */ 92U_CFUNC int32_t 93u_printf_parse(const u_printf_stream_handler *streamHandler, 94 const UChar *fmt, 95 void *context, 96 u_localized_print_string *locStringContext, 97 ULocaleBundle *formatBundle, 98 int32_t *written, 99 va_list ap); 100 101#endif /* #if !UCONFIG_NO_FORMATTING */ 102 103#endif 104