michael@0: /* michael@0: ****************************************************************************** michael@0: * michael@0: * Copyright (C) 1998-2006, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ****************************************************************************** michael@0: * michael@0: * File uprintf.h michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 11/19/98 stephen Creation. michael@0: * 03/12/99 stephen Modified for new C API. michael@0: ****************************************************************************** michael@0: */ michael@0: michael@0: #ifndef UPRINTF_H michael@0: #define UPRINTF_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/ustdio.h" michael@0: #include "ufmt_cmn.h" michael@0: #include "locbund.h" michael@0: michael@0: /** michael@0: * Struct encapsulating a single uprintf format specification. michael@0: */ michael@0: typedef struct u_printf_spec_info { michael@0: int32_t fPrecision; /* Precision */ michael@0: int32_t fWidth; /* Width */ michael@0: michael@0: UChar fOrigSpec; /* Conversion specification */ michael@0: UChar fSpec; /* Conversion specification */ michael@0: UChar fPadChar; /* Padding character */ michael@0: michael@0: UBool fAlt; /* # flag */ michael@0: UBool fSpace; /* Space flag */ michael@0: UBool fLeft; /* - flag */ michael@0: UBool fShowSign; /* + flag */ michael@0: UBool fZero; /* 0 flag */ michael@0: michael@0: UBool fIsLongDouble; /* L flag */ michael@0: UBool fIsShort; /* h flag */ michael@0: UBool fIsLong; /* l flag */ michael@0: UBool fIsLongLong; /* ll flag */ michael@0: } u_printf_spec_info; michael@0: michael@0: typedef int32_t U_EXPORT2 michael@0: u_printf_write_stream(void *context, michael@0: const UChar *str, michael@0: int32_t count); michael@0: michael@0: typedef int32_t U_EXPORT2 michael@0: u_printf_pad_and_justify_stream(void *context, michael@0: const u_printf_spec_info *info, michael@0: const UChar *result, michael@0: int32_t resultLen); michael@0: michael@0: typedef struct u_printf_stream_handler { michael@0: u_printf_write_stream *write; michael@0: u_printf_pad_and_justify_stream *pad_and_justify; michael@0: } u_printf_stream_handler; michael@0: michael@0: /* Used by sprintf */ michael@0: typedef struct u_localized_print_string { michael@0: UChar *str; /* Place to write the string */ michael@0: int32_t available;/* Number of codeunits available to write to */ michael@0: int32_t len; /* Maximum number of code units that can be written to output */ michael@0: michael@0: ULocaleBundle fBundle; /* formatters */ michael@0: } u_localized_print_string; michael@0: michael@0: #define UP_PERCENT 0x0025 michael@0: michael@0: /** michael@0: * Parse a single u_printf format string. michael@0: * @param fmt A pointer to a '%' character in a u_printf format specification. michael@0: * @param spec A pointer to a u_printf_spec to receive the parsed michael@0: * format specifier. michael@0: * @param locStringContext If present, will make sure that it will only write michael@0: * to the buffer when space is available. It's done this way because michael@0: * va_list sometimes can't be passed by pointer. michael@0: * @return The number of characters contained in this specifier. michael@0: */ michael@0: U_CFUNC int32_t michael@0: u_printf_parse(const u_printf_stream_handler *streamHandler, michael@0: const UChar *fmt, michael@0: void *context, michael@0: u_localized_print_string *locStringContext, michael@0: ULocaleBundle *formatBundle, michael@0: int32_t *written, michael@0: va_list ap); michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: michael@0: #endif