ulistformatter.h 4.5 KB

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