uprintf.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #ifndef UPRINTF_H
  21. #define UPRINTF_H
  22. #include "unicode/utypes.h"
  23. #if !UCONFIG_NO_FORMATTING
  24. #include "unicode/ustdio.h"
  25. #include "ufmt_cmn.h"
  26. #include "locbund.h"
  27. /**
  28. * Struct encapsulating a single uprintf format specification.
  29. */
  30. typedef struct u_printf_spec_info {
  31. int32_t fPrecision; /* Precision */
  32. int32_t fWidth; /* Width */
  33. UChar fOrigSpec; /* Conversion specification */
  34. UChar fSpec; /* Conversion specification */
  35. UChar fPadChar; /* Padding character */
  36. UBool fAlt; /* # flag */
  37. UBool fSpace; /* Space flag */
  38. UBool fLeft; /* - flag */
  39. UBool fShowSign; /* + flag */
  40. UBool fZero; /* 0 flag */
  41. UBool fIsLongDouble; /* L flag */
  42. UBool fIsShort; /* h flag */
  43. UBool fIsLong; /* l flag */
  44. UBool fIsLongLong; /* ll flag */
  45. } u_printf_spec_info;
  46. typedef int32_t U_EXPORT2
  47. u_printf_write_stream(void *context,
  48. const UChar *str,
  49. int32_t count);
  50. typedef int32_t U_EXPORT2
  51. u_printf_pad_and_justify_stream(void *context,
  52. const u_printf_spec_info *info,
  53. const UChar *result,
  54. int32_t resultLen);
  55. typedef struct u_printf_stream_handler {
  56. u_printf_write_stream *write;
  57. u_printf_pad_and_justify_stream *pad_and_justify;
  58. } u_printf_stream_handler;
  59. /* Used by sprintf */
  60. typedef struct u_localized_print_string {
  61. UChar *str; /* Place to write the string */
  62. int32_t available;/* Number of codeunits available to write to */
  63. int32_t len; /* Maximum number of code units that can be written to output */
  64. ULocaleBundle fBundle; /* formatters */
  65. } u_localized_print_string;
  66. #define UP_PERCENT 0x0025
  67. /**
  68. * Parse a single u_printf format string.
  69. * @param fmt A pointer to a '%' character in a u_printf format specification.
  70. * @param spec A pointer to a <TT>u_printf_spec</TT> to receive the parsed
  71. * format specifier.
  72. * @param locStringContext If present, will make sure that it will only write
  73. * to the buffer when space is available. It's done this way because
  74. * va_list sometimes can't be passed by pointer.
  75. * @return The number of characters contained in this specifier.
  76. */
  77. U_CFUNC int32_t
  78. u_printf_parse(const u_printf_stream_handler *streamHandler,
  79. const UChar *fmt,
  80. void *context,
  81. u_localized_print_string *locStringContext,
  82. ULocaleBundle *formatBundle,
  83. int32_t *written,
  84. va_list ap);
  85. #endif /* #if !UCONFIG_NO_FORMATTING */
  86. #endif