ulistformatter.h 4.4 KB

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