2 ******************************************************************************* 
   4 *   Copyright (C) 2002-2010, International Business Machines 
   5 *   Corporation and others.  All Rights Reserved. 
   7 ******************************************************************************* 
  10 *   tab size:   8 (not used) 
  13 *   created on: 2002jul08 
  14 *   created by: Vladimir Weinstein 
  20 #include "unicode/utypes.h" 
  21 #include "unicode/localpointer.h" 
  23 #if U_SHOW_CPLUSPLUS_API 
  24 #include "unicode/strenum.h" 
  29  * \brief C API: String Enumeration  
  33  * An enumeration object. 
  34  * For usage in C programs. 
  38 /** structure representing an enumeration object instance @stable ICU 2.2 */ 
  39 typedef struct UEnumeration UEnumeration
; 
  42  * Disposes of resources in use by the iterator.  If en is NULL, 
  43  * does nothing.  After this call, any char* or UChar* pointer 
  44  * returned by uenum_unext() or uenum_next() is invalid. 
  45  * @param en UEnumeration structure pointer 
  48 U_STABLE 
void U_EXPORT2
 
  49 uenum_close(UEnumeration
* en
); 
  51 #if U_SHOW_CPLUSPLUS_API 
  56  * \class LocalUEnumerationPointer 
  57  * "Smart pointer" class, closes a UEnumeration via uenum_close(). 
  58  * For most methods see the LocalPointerBase base class. 
  60  * @see LocalPointerBase 
  64 U_DEFINE_LOCAL_OPEN_POINTER(LocalUEnumerationPointer
, UEnumeration
, uenum_close
); 
  71  * Returns the number of elements that the iterator traverses.  If 
  72  * the iterator is out-of-sync with its service, status is set to 
  73  * U_ENUM_OUT_OF_SYNC_ERROR. 
  74  * This is a convenience function. It can end up being very 
  75  * expensive as all the items might have to be pre-fetched (depending 
  76  * on the type of data being traversed). Use with caution and only  
  78  * @param en UEnumeration structure pointer 
  79  * @param status error code, can be U_ENUM_OUT_OF_SYNC_ERROR if the 
  80  *               iterator is out of sync. 
  81  * @return number of elements in the iterator 
  84 U_STABLE 
int32_t U_EXPORT2
 
  85 uenum_count(UEnumeration
* en
, UErrorCode
* status
); 
  88  * Returns the next element in the iterator's list.  If there are 
  89  * no more elements, returns NULL.  If the iterator is out-of-sync 
  90  * with its service, status is set to U_ENUM_OUT_OF_SYNC_ERROR and 
  91  * NULL is returned.  If the native service string is a char* string, 
  92  * it is converted to UChar* with the invariant converter. 
  93  * The result is terminated by (UChar)0. 
  94  * @param en the iterator object 
  95  * @param resultLength pointer to receive the length of the result 
  96  *                     (not including the terminating \\0). 
  97  *                     If the pointer is NULL it is ignored. 
  98  * @param status the error code, set to U_ENUM_OUT_OF_SYNC_ERROR if 
  99  *               the iterator is out of sync with its service. 
 100  * @return a pointer to the string.  The string will be 
 101  *         zero-terminated.  The return pointer is owned by this iterator 
 102  *         and must not be deleted by the caller.  The pointer is valid 
 103  *         until the next call to any uenum_... method, including 
 104  *         uenum_next() or uenum_unext().  When all strings have been 
 105  *         traversed, returns NULL. 
 108 U_STABLE 
const UChar
* U_EXPORT2
 
 109 uenum_unext(UEnumeration
* en
, 
 110             int32_t* resultLength
, 
 114  * Returns the next element in the iterator's list.  If there are 
 115  * no more elements, returns NULL.  If the iterator is out-of-sync 
 116  * with its service, status is set to U_ENUM_OUT_OF_SYNC_ERROR and 
 117  * NULL is returned.  If the native service string is a UChar* 
 118  * string, it is converted to char* with the invariant converter. 
 119  * The result is terminated by (char)0.  If the conversion fails 
 120  * (because a character cannot be converted) then status is set to 
 121  * U_INVARIANT_CONVERSION_ERROR and the return value is undefined 
 123  * @param en the iterator object 
 124  * @param resultLength pointer to receive the length of the result 
 125  *                     (not including the terminating \\0). 
 126  *                     If the pointer is NULL it is ignored. 
 127  * @param status the error code, set to U_ENUM_OUT_OF_SYNC_ERROR if 
 128  *               the iterator is out of sync with its service.  Set to 
 129  *               U_INVARIANT_CONVERSION_ERROR if the underlying native string is 
 130  *               UChar* and conversion to char* with the invariant converter 
 131  *               fails. This error pertains only to current string, so iteration 
 132  *               might be able to continue successfully. 
 133  * @return a pointer to the string.  The string will be 
 134  *         zero-terminated.  The return pointer is owned by this iterator 
 135  *         and must not be deleted by the caller.  The pointer is valid 
 136  *         until the next call to any uenum_... method, including 
 137  *         uenum_next() or uenum_unext().  When all strings have been 
 138  *         traversed, returns NULL. 
 141 U_STABLE 
const char* U_EXPORT2
 
 142 uenum_next(UEnumeration
* en
, 
 143            int32_t* resultLength
, 
 147  * Resets the iterator to the current list of service IDs.  This 
 148  * re-establishes sync with the service and rewinds the iterator 
 149  * to start at the first element. 
 150  * @param en the iterator object 
 151  * @param status the error code, set to U_ENUM_OUT_OF_SYNC_ERROR if 
 152  *               the iterator is out of sync with its service.   
 155 U_STABLE 
void U_EXPORT2
 
 156 uenum_reset(UEnumeration
* en
, UErrorCode
* status
); 
 158 #if U_SHOW_CPLUSPLUS_API 
 161  * Given a StringEnumeration, wrap it in a UEnumeration.  The 
 162  * StringEnumeration is adopted; after this call, the caller must not 
 163  * delete it (regardless of error status). 
 164  * @param adopted the C++ StringEnumeration to be wrapped in a UEnumeration. 
 165  * @param ec the error code. 
 166  * @return a UEnumeration wrapping the adopted StringEnumeration. 
 169 U_CAPI UEnumeration
* U_EXPORT2
 
 170 uenum_openFromStringEnumeration(U_NAMESPACE_QUALIFIER StringEnumeration
* adopted
, UErrorCode
* ec
);