xref: /aosp_15_r20/external/icu/libandroidicu/include/unicode/uenum.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker *******************************************************************************
5*0e209d39SAndroid Build Coastguard Worker *
6*0e209d39SAndroid Build Coastguard Worker *   Copyright (C) 2002-2013, International Business Machines
7*0e209d39SAndroid Build Coastguard Worker *   Corporation and others.  All Rights Reserved.
8*0e209d39SAndroid Build Coastguard Worker *
9*0e209d39SAndroid Build Coastguard Worker *******************************************************************************
10*0e209d39SAndroid Build Coastguard Worker *   file name:  uenum.h
11*0e209d39SAndroid Build Coastguard Worker *   encoding:   UTF-8
12*0e209d39SAndroid Build Coastguard Worker *   tab size:   8 (not used)
13*0e209d39SAndroid Build Coastguard Worker *   indentation:2
14*0e209d39SAndroid Build Coastguard Worker *
15*0e209d39SAndroid Build Coastguard Worker *   created on: 2002jul08
16*0e209d39SAndroid Build Coastguard Worker *   created by: Vladimir Weinstein
17*0e209d39SAndroid Build Coastguard Worker */
18*0e209d39SAndroid Build Coastguard Worker 
19*0e209d39SAndroid Build Coastguard Worker #ifndef __UENUM_H
20*0e209d39SAndroid Build Coastguard Worker #define __UENUM_H
21*0e209d39SAndroid Build Coastguard Worker 
22*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
23*0e209d39SAndroid Build Coastguard Worker 
24*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
25*0e209d39SAndroid Build Coastguard Worker #include "unicode/localpointer.h"
26*0e209d39SAndroid Build Coastguard Worker 
27*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
28*0e209d39SAndroid Build Coastguard Worker class StringEnumeration;
29*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
30*0e209d39SAndroid Build Coastguard Worker #endif   // U_SHOW_CPLUSPLUS_API
31*0e209d39SAndroid Build Coastguard Worker 
32*0e209d39SAndroid Build Coastguard Worker /**
33*0e209d39SAndroid Build Coastguard Worker  * \file
34*0e209d39SAndroid Build Coastguard Worker  * \brief C API: String Enumeration
35*0e209d39SAndroid Build Coastguard Worker  */
36*0e209d39SAndroid Build Coastguard Worker 
37*0e209d39SAndroid Build Coastguard Worker /**
38*0e209d39SAndroid Build Coastguard Worker  * An enumeration object.
39*0e209d39SAndroid Build Coastguard Worker  * For usage in C programs.
40*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.2
41*0e209d39SAndroid Build Coastguard Worker  */
42*0e209d39SAndroid Build Coastguard Worker struct UEnumeration;
43*0e209d39SAndroid Build Coastguard Worker /** structure representing an enumeration object instance @stable ICU 2.2 */
44*0e209d39SAndroid Build Coastguard Worker typedef struct UEnumeration UEnumeration;
45*0e209d39SAndroid Build Coastguard Worker 
46*0e209d39SAndroid Build Coastguard Worker /**
47*0e209d39SAndroid Build Coastguard Worker  * Disposes of resources in use by the iterator.  If en is NULL,
48*0e209d39SAndroid Build Coastguard Worker  * does nothing.  After this call, any char* or UChar* pointer
49*0e209d39SAndroid Build Coastguard Worker  * returned by uenum_unext() or uenum_next() is invalid.
50*0e209d39SAndroid Build Coastguard Worker  * @param en UEnumeration structure pointer
51*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.2
52*0e209d39SAndroid Build Coastguard Worker  */
53*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
54*0e209d39SAndroid Build Coastguard Worker uenum_close(UEnumeration* en);
55*0e209d39SAndroid Build Coastguard Worker 
56*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
57*0e209d39SAndroid Build Coastguard Worker 
58*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
59*0e209d39SAndroid Build Coastguard Worker 
60*0e209d39SAndroid Build Coastguard Worker /**
61*0e209d39SAndroid Build Coastguard Worker  * \class LocalUEnumerationPointer
62*0e209d39SAndroid Build Coastguard Worker  * "Smart pointer" class, closes a UEnumeration via uenum_close().
63*0e209d39SAndroid Build Coastguard Worker  * For most methods see the LocalPointerBase base class.
64*0e209d39SAndroid Build Coastguard Worker  *
65*0e209d39SAndroid Build Coastguard Worker  * @see LocalPointerBase
66*0e209d39SAndroid Build Coastguard Worker  * @see LocalPointer
67*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 4.4
68*0e209d39SAndroid Build Coastguard Worker  */
69*0e209d39SAndroid Build Coastguard Worker U_DEFINE_LOCAL_OPEN_POINTER(LocalUEnumerationPointer, UEnumeration, uenum_close);
70*0e209d39SAndroid Build Coastguard Worker 
71*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
72*0e209d39SAndroid Build Coastguard Worker 
73*0e209d39SAndroid Build Coastguard Worker #endif
74*0e209d39SAndroid Build Coastguard Worker 
75*0e209d39SAndroid Build Coastguard Worker /**
76*0e209d39SAndroid Build Coastguard Worker  * Returns the number of elements that the iterator traverses.  If
77*0e209d39SAndroid Build Coastguard Worker  * the iterator is out-of-sync with its service, status is set to
78*0e209d39SAndroid Build Coastguard Worker  * U_ENUM_OUT_OF_SYNC_ERROR.
79*0e209d39SAndroid Build Coastguard Worker  * This is a convenience function. It can end up being very
80*0e209d39SAndroid Build Coastguard Worker  * expensive as all the items might have to be pre-fetched (depending
81*0e209d39SAndroid Build Coastguard Worker  * on the type of data being traversed). Use with caution and only
82*0e209d39SAndroid Build Coastguard Worker  * when necessary.
83*0e209d39SAndroid Build Coastguard Worker  * @param en UEnumeration structure pointer
84*0e209d39SAndroid Build Coastguard Worker  * @param status error code, can be U_ENUM_OUT_OF_SYNC_ERROR if the
85*0e209d39SAndroid Build Coastguard Worker  *               iterator is out of sync.
86*0e209d39SAndroid Build Coastguard Worker  * @return number of elements in the iterator
87*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.2
88*0e209d39SAndroid Build Coastguard Worker  */
89*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
90*0e209d39SAndroid Build Coastguard Worker uenum_count(UEnumeration* en, UErrorCode* status);
91*0e209d39SAndroid Build Coastguard Worker 
92*0e209d39SAndroid Build Coastguard Worker /**
93*0e209d39SAndroid Build Coastguard Worker  * Returns the next element in the iterator's list.  If there are
94*0e209d39SAndroid Build Coastguard Worker  * no more elements, returns NULL.  If the iterator is out-of-sync
95*0e209d39SAndroid Build Coastguard Worker  * with its service, status is set to U_ENUM_OUT_OF_SYNC_ERROR and
96*0e209d39SAndroid Build Coastguard Worker  * NULL is returned.  If the native service string is a char* string,
97*0e209d39SAndroid Build Coastguard Worker  * it is converted to UChar* with the invariant converter.
98*0e209d39SAndroid Build Coastguard Worker  * The result is terminated by (UChar)0.
99*0e209d39SAndroid Build Coastguard Worker  * @param en the iterator object
100*0e209d39SAndroid Build Coastguard Worker  * @param resultLength pointer to receive the length of the result
101*0e209d39SAndroid Build Coastguard Worker  *                     (not including the terminating \\0).
102*0e209d39SAndroid Build Coastguard Worker  *                     If the pointer is NULL it is ignored.
103*0e209d39SAndroid Build Coastguard Worker  * @param status the error code, set to U_ENUM_OUT_OF_SYNC_ERROR if
104*0e209d39SAndroid Build Coastguard Worker  *               the iterator is out of sync with its service.
105*0e209d39SAndroid Build Coastguard Worker  * @return a pointer to the string.  The string will be
106*0e209d39SAndroid Build Coastguard Worker  *         zero-terminated.  The return pointer is owned by this iterator
107*0e209d39SAndroid Build Coastguard Worker  *         and must not be deleted by the caller.  The pointer is valid
108*0e209d39SAndroid Build Coastguard Worker  *         until the next call to any uenum_... method, including
109*0e209d39SAndroid Build Coastguard Worker  *         uenum_next() or uenum_unext().  When all strings have been
110*0e209d39SAndroid Build Coastguard Worker  *         traversed, returns NULL.
111*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.2
112*0e209d39SAndroid Build Coastguard Worker  */
113*0e209d39SAndroid Build Coastguard Worker U_CAPI const UChar* U_EXPORT2
114*0e209d39SAndroid Build Coastguard Worker uenum_unext(UEnumeration* en,
115*0e209d39SAndroid Build Coastguard Worker             int32_t* resultLength,
116*0e209d39SAndroid Build Coastguard Worker             UErrorCode* status);
117*0e209d39SAndroid Build Coastguard Worker 
118*0e209d39SAndroid Build Coastguard Worker /**
119*0e209d39SAndroid Build Coastguard Worker  * Returns the next element in the iterator's list.  If there are
120*0e209d39SAndroid Build Coastguard Worker  * no more elements, returns NULL.  If the iterator is out-of-sync
121*0e209d39SAndroid Build Coastguard Worker  * with its service, status is set to U_ENUM_OUT_OF_SYNC_ERROR and
122*0e209d39SAndroid Build Coastguard Worker  * NULL is returned.  If the native service string is a UChar*
123*0e209d39SAndroid Build Coastguard Worker  * string, it is converted to char* with the invariant converter.
124*0e209d39SAndroid Build Coastguard Worker  * The result is terminated by (char)0.  If the conversion fails
125*0e209d39SAndroid Build Coastguard Worker  * (because a character cannot be converted) then status is set to
126*0e209d39SAndroid Build Coastguard Worker  * U_INVARIANT_CONVERSION_ERROR and the return value is undefined
127*0e209d39SAndroid Build Coastguard Worker  * (but non-NULL).
128*0e209d39SAndroid Build Coastguard Worker  * @param en the iterator object
129*0e209d39SAndroid Build Coastguard Worker  * @param resultLength pointer to receive the length of the result
130*0e209d39SAndroid Build Coastguard Worker  *                     (not including the terminating \\0).
131*0e209d39SAndroid Build Coastguard Worker  *                     If the pointer is NULL it is ignored.
132*0e209d39SAndroid Build Coastguard Worker  * @param status the error code, set to U_ENUM_OUT_OF_SYNC_ERROR if
133*0e209d39SAndroid Build Coastguard Worker  *               the iterator is out of sync with its service.  Set to
134*0e209d39SAndroid Build Coastguard Worker  *               U_INVARIANT_CONVERSION_ERROR if the underlying native string is
135*0e209d39SAndroid Build Coastguard Worker  *               UChar* and conversion to char* with the invariant converter
136*0e209d39SAndroid Build Coastguard Worker  *               fails. This error pertains only to current string, so iteration
137*0e209d39SAndroid Build Coastguard Worker  *               might be able to continue successfully.
138*0e209d39SAndroid Build Coastguard Worker  * @return a pointer to the string.  The string will be
139*0e209d39SAndroid Build Coastguard Worker  *         zero-terminated.  The return pointer is owned by this iterator
140*0e209d39SAndroid Build Coastguard Worker  *         and must not be deleted by the caller.  The pointer is valid
141*0e209d39SAndroid Build Coastguard Worker  *         until the next call to any uenum_... method, including
142*0e209d39SAndroid Build Coastguard Worker  *         uenum_next() or uenum_unext().  When all strings have been
143*0e209d39SAndroid Build Coastguard Worker  *         traversed, returns NULL.
144*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.2
145*0e209d39SAndroid Build Coastguard Worker  */
146*0e209d39SAndroid Build Coastguard Worker U_CAPI const char* U_EXPORT2
147*0e209d39SAndroid Build Coastguard Worker uenum_next(UEnumeration* en,
148*0e209d39SAndroid Build Coastguard Worker            int32_t* resultLength,
149*0e209d39SAndroid Build Coastguard Worker            UErrorCode* status);
150*0e209d39SAndroid Build Coastguard Worker 
151*0e209d39SAndroid Build Coastguard Worker /**
152*0e209d39SAndroid Build Coastguard Worker  * Resets the iterator to the current list of service IDs.  This
153*0e209d39SAndroid Build Coastguard Worker  * re-establishes sync with the service and rewinds the iterator
154*0e209d39SAndroid Build Coastguard Worker  * to start at the first element.
155*0e209d39SAndroid Build Coastguard Worker  * @param en the iterator object
156*0e209d39SAndroid Build Coastguard Worker  * @param status the error code, set to U_ENUM_OUT_OF_SYNC_ERROR if
157*0e209d39SAndroid Build Coastguard Worker  *               the iterator is out of sync with its service.
158*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.2
159*0e209d39SAndroid Build Coastguard Worker  */
160*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
161*0e209d39SAndroid Build Coastguard Worker uenum_reset(UEnumeration* en, UErrorCode* status);
162*0e209d39SAndroid Build Coastguard Worker 
163*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
164*0e209d39SAndroid Build Coastguard Worker 
165*0e209d39SAndroid Build Coastguard Worker /**
166*0e209d39SAndroid Build Coastguard Worker  * Given a StringEnumeration, wrap it in a UEnumeration.  The
167*0e209d39SAndroid Build Coastguard Worker  * StringEnumeration is adopted; after this call, the caller must not
168*0e209d39SAndroid Build Coastguard Worker  * delete it (regardless of error status).
169*0e209d39SAndroid Build Coastguard Worker  * @param adopted the C++ StringEnumeration to be wrapped in a UEnumeration.
170*0e209d39SAndroid Build Coastguard Worker  * @param ec the error code.
171*0e209d39SAndroid Build Coastguard Worker  * @return a UEnumeration wrapping the adopted StringEnumeration.
172*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 4.2
173*0e209d39SAndroid Build Coastguard Worker  */
174*0e209d39SAndroid Build Coastguard Worker U_CAPI UEnumeration* U_EXPORT2
175*0e209d39SAndroid Build Coastguard Worker uenum_openFromStringEnumeration(icu::StringEnumeration* adopted, UErrorCode* ec);
176*0e209d39SAndroid Build Coastguard Worker 
177*0e209d39SAndroid Build Coastguard Worker #endif
178*0e209d39SAndroid Build Coastguard Worker 
179*0e209d39SAndroid Build Coastguard Worker /**
180*0e209d39SAndroid Build Coastguard Worker  * Given an array of const UChar* strings, return a UEnumeration.  String pointers from 0..count-1 must not be null.
181*0e209d39SAndroid Build Coastguard Worker  * Do not free or modify either the string array or the characters it points to until this object has been destroyed with uenum_close.
182*0e209d39SAndroid Build Coastguard Worker  * \snippet test/cintltst/uenumtst.c uenum_openUCharStringsEnumeration
183*0e209d39SAndroid Build Coastguard Worker  * @param strings array of const UChar* strings (each null terminated). All storage is owned by the caller.
184*0e209d39SAndroid Build Coastguard Worker  * @param count length of the array
185*0e209d39SAndroid Build Coastguard Worker  * @param ec error code
186*0e209d39SAndroid Build Coastguard Worker  * @return the new UEnumeration object. Caller is responsible for calling uenum_close to free memory.
187*0e209d39SAndroid Build Coastguard Worker  * @see uenum_close
188*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 50
189*0e209d39SAndroid Build Coastguard Worker  */
190*0e209d39SAndroid Build Coastguard Worker U_CAPI UEnumeration* U_EXPORT2
191*0e209d39SAndroid Build Coastguard Worker uenum_openUCharStringsEnumeration(const UChar* const strings[], int32_t count,
192*0e209d39SAndroid Build Coastguard Worker                                  UErrorCode* ec);
193*0e209d39SAndroid Build Coastguard Worker 
194*0e209d39SAndroid Build Coastguard Worker /**
195*0e209d39SAndroid Build Coastguard Worker  * Given an array of const char* strings (invariant chars only), return a UEnumeration.  String pointers from 0..count-1 must not be null.
196*0e209d39SAndroid Build Coastguard Worker  * Do not free or modify either the string array or the characters it points to until this object has been destroyed with uenum_close.
197*0e209d39SAndroid Build Coastguard Worker  * \snippet test/cintltst/uenumtst.c uenum_openCharStringsEnumeration
198*0e209d39SAndroid Build Coastguard Worker  * @param strings array of char* strings (each null terminated).  All storage is owned by the caller.
199*0e209d39SAndroid Build Coastguard Worker  * @param count length of the array
200*0e209d39SAndroid Build Coastguard Worker  * @param ec error code
201*0e209d39SAndroid Build Coastguard Worker  * @return the new UEnumeration object. Caller is responsible for calling uenum_close to free memory
202*0e209d39SAndroid Build Coastguard Worker  * @see uenum_close
203*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 50
204*0e209d39SAndroid Build Coastguard Worker  */
205*0e209d39SAndroid Build Coastguard Worker U_CAPI UEnumeration* U_EXPORT2
206*0e209d39SAndroid Build Coastguard Worker uenum_openCharStringsEnumeration(const char* const strings[], int32_t count,
207*0e209d39SAndroid Build Coastguard Worker                                  UErrorCode* ec);
208*0e209d39SAndroid Build Coastguard Worker 
209*0e209d39SAndroid Build Coastguard Worker #endif
210