ulistformatter.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. *****************************************************************************************
  3. * Copyright (C) 2015, International Business Machines
  4. * Corporation and others. All Rights Reserved.
  5. *****************************************************************************************
  6. */
  7. #ifndef ULISTFORMATTER_H
  8. #define ULISTFORMATTER_H
  9. #include "unicode/utypes.h"
  10. #if !UCONFIG_NO_FORMATTING
  11. #ifndef U_HIDE_DRAFT_API
  12. #include "unicode/localpointer.h"
  13. /**
  14. * \file
  15. * \brief C API: Format a list in a locale-appropriate way.
  16. *
  17. * A UListFormatter is used to format a list of items in a locale-appropriate way,
  18. * using data from CLDR.
  19. * Example: Input data ["Alice", "Bob", "Charlie", "Delta"] will be formatted
  20. * as "Alice, Bob, Charlie, and Delta" in English.
  21. */
  22. /**
  23. * Opaque UListFormatter object for use in C
  24. * @draft ICU 55
  25. */
  26. struct UListFormatter;
  27. typedef struct UListFormatter UListFormatter; /**< C typedef for struct UListFormatter. @draft ICU 55 */
  28. /**
  29. * Open a new UListFormatter object using the rules for a given locale.
  30. * @param locale
  31. * The locale whose rules should be used; may be NULL for
  32. * default locale.
  33. * @param status
  34. * A pointer to a standard ICU UErrorCode (input/output parameter).
  35. * Its input value must pass the U_SUCCESS() test, or else the
  36. * function returns immediately. The caller should check its output
  37. * value with U_FAILURE(), or use with function chaining (see User
  38. * Guide for details).
  39. * @return
  40. * A pointer to a UListFormatter object for the specified locale,
  41. * or NULL if an error occurred.
  42. * @draft ICU 55
  43. */
  44. U_DRAFT UListFormatter* U_EXPORT2
  45. ulistfmt_open(const char* locale,
  46. UErrorCode* status);
  47. /**
  48. * Close a UListFormatter object. Once closed it may no longer be used.
  49. * @param listfmt
  50. * The UListFormatter object to close.
  51. * @draft ICU 55
  52. */
  53. U_DRAFT void U_EXPORT2
  54. ulistfmt_close(UListFormatter *listfmt);
  55. #if U_SHOW_CPLUSPLUS_API
  56. U_NAMESPACE_BEGIN
  57. /**
  58. * \class LocalUListFormatterPointer
  59. * "Smart pointer" class, closes a UListFormatter via ulistfmt_close().
  60. * For most methods see the LocalPointerBase base class.
  61. *
  62. * @see LocalPointerBase
  63. * @see LocalPointer
  64. * @draft ICU 55
  65. */
  66. U_DEFINE_LOCAL_OPEN_POINTER(LocalUListFormatterPointer, UListFormatter, ulistfmt_close);
  67. U_NAMESPACE_END
  68. #endif
  69. /**
  70. * Formats a list of strings using the conventions established for the
  71. * UListFormatter object.
  72. * @param listfmt
  73. * The UListFormatter object specifying the list conventions.
  74. * @param strings
  75. * An array of pointers to UChar strings; the array length is
  76. * specified by stringCount. Must be non-NULL if stringCount > 0.
  77. * @param stringLengths
  78. * An array of string lengths corresponding to the strings[]
  79. * parameter; any individual length value may be negative to indicate
  80. * that the corresponding strings[] entry is 0-terminated, or
  81. * stringLengths itself may be NULL if all of the strings are
  82. * 0-terminated. If non-NULL, the stringLengths array must have
  83. * stringCount entries.
  84. * @param stringCount
  85. * the number of entries in strings[], and the number of entries
  86. * in the stringLengths array if it is not NULL. Must be >= 0.
  87. * @param result
  88. * A pointer to a buffer to receive the formatted list.
  89. * @param resultCapacity
  90. * The maximum size of result.
  91. * @param status
  92. * A pointer to a standard ICU UErrorCode (input/output parameter).
  93. * Its input value must pass the U_SUCCESS() test, or else the
  94. * function returns immediately. The caller should check its output
  95. * value with U_FAILURE(), or use with function chaining (see User
  96. * Guide for details).
  97. * @return
  98. * The total buffer size needed; if greater than resultLength, the
  99. * output was truncated. May be <=0 if unable to determine the
  100. * total buffer size needed (e.g. for illegal arguments).
  101. * @draft ICU 55
  102. */
  103. U_DRAFT int32_t U_EXPORT2
  104. ulistfmt_format(const UListFormatter* listfmt,
  105. const UChar* const strings[],
  106. const int32_t * stringLengths,
  107. int32_t stringCount,
  108. UChar* result,
  109. int32_t resultCapacity,
  110. UErrorCode* status);
  111. #endif /* U_HIDE_DRAFT_API */
  112. #endif /* #if !UCONFIG_NO_FORMATTING */
  113. #endif