1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *****************************************************************************************
5 * Copyright (C) 2015-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *****************************************************************************************
10 #ifndef ULISTFORMATTER_H
11 #define ULISTFORMATTER_H
13 #include "unicode/utypes.h"
15 #if !UCONFIG_NO_FORMATTING
17 #include "unicode/localpointer.h"
21 * \brief C API: Format a list in a locale-appropriate way.
23 * A UListFormatter is used to format a list of items in a locale-appropriate way,
24 * using data from CLDR.
25 * Example: Input data ["Alice", "Bob", "Charlie", "Delta"] will be formatted
26 * as "Alice, Bob, Charlie, and Delta" in English.
30 * Opaque UListFormatter object for use in C
33 struct UListFormatter
;
34 typedef struct UListFormatter UListFormatter
; /**< C typedef for struct UListFormatter. @stable ICU 55 */
37 * Open a new UListFormatter object using the rules for a given locale.
39 * The locale whose rules should be used; may be NULL for
42 * A pointer to a standard ICU UErrorCode (input/output parameter).
43 * Its input value must pass the U_SUCCESS() test, or else the
44 * function returns immediately. The caller should check its output
45 * value with U_FAILURE(), or use with function chaining (see User
48 * A pointer to a UListFormatter object for the specified locale,
49 * or NULL if an error occurred.
52 U_CAPI UListFormatter
* U_EXPORT2
53 ulistfmt_open(const char* locale
,
57 * Close a UListFormatter object. Once closed it may no longer be used.
59 * The UListFormatter object to close.
63 ulistfmt_close(UListFormatter
*listfmt
);
66 #if U_SHOW_CPLUSPLUS_API
71 * \class LocalUListFormatterPointer
72 * "Smart pointer" class, closes a UListFormatter via ulistfmt_close().
73 * For most methods see the LocalPointerBase base class.
75 * @see LocalPointerBase
79 U_DEFINE_LOCAL_OPEN_POINTER(LocalUListFormatterPointer
, UListFormatter
, ulistfmt_close
);
83 #endif // U_SHOW_CPLUSPLUS_API
86 * Formats a list of strings using the conventions established for the
87 * UListFormatter object.
89 * The UListFormatter object specifying the list conventions.
91 * An array of pointers to UChar strings; the array length is
92 * specified by stringCount. Must be non-NULL if stringCount > 0.
93 * @param stringLengths
94 * An array of string lengths corresponding to the strings[]
95 * parameter; any individual length value may be negative to indicate
96 * that the corresponding strings[] entry is 0-terminated, or
97 * stringLengths itself may be NULL if all of the strings are
98 * 0-terminated. If non-NULL, the stringLengths array must have
99 * stringCount entries.
101 * the number of entries in strings[], and the number of entries
102 * in the stringLengths array if it is not NULL. Must be >= 0.
104 * A pointer to a buffer to receive the formatted list.
105 * @param resultCapacity
106 * The maximum size of result.
108 * A pointer to a standard ICU UErrorCode (input/output parameter).
109 * Its input value must pass the U_SUCCESS() test, or else the
110 * function returns immediately. The caller should check its output
111 * value with U_FAILURE(), or use with function chaining (see User
112 * Guide for details).
114 * The total buffer size needed; if greater than resultLength, the
115 * output was truncated. May be <=0 if unable to determine the
116 * total buffer size needed (e.g. for illegal arguments).
119 U_CAPI
int32_t U_EXPORT2
120 ulistfmt_format(const UListFormatter
* listfmt
,
121 const UChar
* const strings
[],
122 const int32_t * stringLengths
,
125 int32_t resultCapacity
,
128 #endif /* #if !UCONFIG_NO_FORMATTING */