Home | History | Annotate | Download | only in unicode
      1 /*
      2 **********************************************************************
      3 *   Copyright (C) 1997-2012, International Business Machines
      4 *   Corporation and others.  All Rights Reserved.
      5 **********************************************************************
      6 *
      7 * File URES.H (formerly CRESBUND.H)
      8 *
      9 * Modification History:
     10 *
     11 *   Date        Name        Description
     12 *   04/01/97    aliu        Creation.
     13 *   02/22/99    damiba      overhaul.
     14 *   04/04/99    helena      Fixed internal header inclusion.
     15 *   04/15/99    Madhu       Updated Javadoc
     16 *   06/14/99    stephen     Removed functions taking a filename suffix.
     17 *   07/20/99    stephen     Language-independent ypedef to void*
     18 *   11/09/99    weiv        Added ures_getLocale()
     19 *   06/24/02    weiv        Added support for resource sharing
     20 ******************************************************************************
     21 */
     22 
     23 #ifndef URES_H
     24 #define URES_H
     25 
     26 #include "unicode/utypes.h"
     27 #include "unicode/uloc.h"
     28 #include "unicode/localpointer.h"
     29 
     30 /**
     31  * \file
     32  * \brief C API: Resource Bundle
     33  *
     34  * <h2>C API: Resource Bundle</h2>
     35  *
     36  * C API representing a collection of resource information pertaining to a given
     37  * locale. A resource bundle provides a way of accessing locale- specific information in
     38  * a data file. You create a resource bundle that manages the resources for a given
     39  * locale and then ask it for individual resources.
     40  * <P>
     41  * Resource bundles in ICU4C are currently defined using text files which conform to the following
     42  * <a href="http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt">BNF definition</a>.
     43  * More on resource bundle concepts and syntax can be found in the
     44  * <a href="http://icu-project.org/userguide/ResourceManagement.html">Users Guide</a>.
     45  * <P>
     46  */
     47 
     48 /**
     49  * UResourceBundle is an opaque type for handles for resource bundles in C APIs.
     50  * @stable ICU 2.0
     51  */
     52 struct UResourceBundle;
     53 
     54 /**
     55  * @stable ICU 2.0
     56  */
     57 typedef struct UResourceBundle UResourceBundle;
     58 
     59 /**
     60  * Numeric constants for types of resource items.
     61  * @see ures_getType
     62  * @stable ICU 2.0
     63  */
     64 typedef enum {
     65     /** Resource type constant for "no resource". @stable ICU 2.6 */
     66     URES_NONE=-1,
     67 
     68     /** Resource type constant for 16-bit Unicode strings. @stable ICU 2.6 */
     69     URES_STRING=0,
     70 
     71     /** Resource type constant for binary data. @stable ICU 2.6 */
     72     URES_BINARY=1,
     73 
     74     /** Resource type constant for tables of key-value pairs. @stable ICU 2.6 */
     75     URES_TABLE=2,
     76 
     77     /**
     78      * Resource type constant for aliases;
     79      * internally stores a string which identifies the actual resource
     80      * storing the data (can be in a different resource bundle).
     81      * Resolved internally before delivering the actual resource through the API.
     82      * @stable ICU 2.6
     83      */
     84     URES_ALIAS=3,
     85 
     86     /**
     87      * Resource type constant for a single 28-bit integer, interpreted as
     88      * signed or unsigned by the ures_getInt() or ures_getUInt() function.
     89      * @see ures_getInt
     90      * @see ures_getUInt
     91      * @stable ICU 2.6
     92      */
     93     URES_INT=7,
     94 
     95     /** Resource type constant for arrays of resources. @stable ICU 2.6 */
     96     URES_ARRAY=8,
     97 
     98     /**
     99      * Resource type constant for vectors of 32-bit integers.
    100      * @see ures_getIntVector
    101      * @stable ICU 2.6
    102      */
    103     URES_INT_VECTOR = 14,
    104 #ifndef U_HIDE_DEPRECATED_API
    105     /** @deprecated ICU 2.6 Use the URES_ constant instead. */
    106     RES_NONE=URES_NONE,
    107     /** @deprecated ICU 2.6 Use the URES_ constant instead. */
    108     RES_STRING=URES_STRING,
    109     /** @deprecated ICU 2.6 Use the URES_ constant instead. */
    110     RES_BINARY=URES_BINARY,
    111     /** @deprecated ICU 2.6 Use the URES_ constant instead. */
    112     RES_TABLE=URES_TABLE,
    113     /** @deprecated ICU 2.6 Use the URES_ constant instead. */
    114     RES_ALIAS=URES_ALIAS,
    115     /** @deprecated ICU 2.6 Use the URES_ constant instead. */
    116     RES_INT=URES_INT,
    117     /** @deprecated ICU 2.6 Use the URES_ constant instead. */
    118     RES_ARRAY=URES_ARRAY,
    119     /** @deprecated ICU 2.6 Use the URES_ constant instead. */
    120     RES_INT_VECTOR=URES_INT_VECTOR,
    121     /** @deprecated ICU 2.6 Not used. */
    122     RES_RESERVED=15,
    123 #endif /* U_HIDE_DEPRECATED_API */
    124 
    125     URES_LIMIT = 16
    126 } UResType;
    127 
    128 /*
    129  * Functions to create and destroy resource bundles.
    130  */
    131 
    132 /**
    133  * Opens a UResourceBundle, from which users can extract strings by using
    134  * their corresponding keys.
    135  * Note that the caller is responsible of calling <TT>ures_close</TT> on each succesfully
    136  * opened resource bundle.
    137  * @param packageName   The packageName and locale together point to an ICU udata object,
    138  *                      as defined by <code> udata_open( packageName, "res", locale, err) </code>
    139  *                      or equivalent.  Typically, packageName will refer to a (.dat) file, or to
    140  *                      a package registered with udata_setAppData(). Using a full file or directory
    141  *                      pathname for packageName is deprecated. If NULL, ICU data will be used.
    142  * @param locale  specifies the locale for which we want to open the resource
    143  *                if NULL, the default locale will be used. If strlen(locale) == 0
    144  *                root locale will be used.
    145  *
    146  * @param status  fills in the outgoing error code.
    147  * The UErrorCode err parameter is used to return status information to the user. To
    148  * check whether the construction succeeded or not, you should check the value of
    149  * U_SUCCESS(err). If you wish more detailed information, you can check for
    150  * informational status results which still indicate success. U_USING_FALLBACK_WARNING
    151  * indicates that a fall back locale was used. For example, 'de_CH' was requested,
    152  * but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that
    153  * the default locale data or root locale data was used; neither the requested locale
    154  * nor any of its fall back locales could be found. Please see the users guide for more
    155  * information on this topic.
    156  * @return      a newly allocated resource bundle.
    157  * @see ures_close
    158  * @stable ICU 2.0
    159  */
    160 U_STABLE UResourceBundle*  U_EXPORT2
    161 ures_open(const char*    packageName,
    162           const char*  locale,
    163           UErrorCode*     status);
    164 
    165 
    166 /** This function does not care what kind of localeID is passed in. It simply opens a bundle with
    167  *  that name. Fallback mechanism is disabled for the new bundle. If the requested bundle contains
    168  *  an %%ALIAS directive, the results are undefined.
    169  * @param packageName   The packageName and locale together point to an ICU udata object,
    170  *                      as defined by <code> udata_open( packageName, "res", locale, err) </code>
    171  *                      or equivalent.  Typically, packageName will refer to a (.dat) file, or to
    172  *                      a package registered with udata_setAppData(). Using a full file or directory
    173  *                      pathname for packageName is deprecated. If NULL, ICU data will be used.
    174  * @param locale  specifies the locale for which we want to open the resource
    175  *                if NULL, the default locale will be used. If strlen(locale) == 0
    176  *                root locale will be used.
    177  *
    178  * @param status fills in the outgoing error code. Either U_ZERO_ERROR or U_MISSING_RESOURCE_ERROR
    179  * @return      a newly allocated resource bundle or NULL if it doesn't exist.
    180  * @see ures_close
    181  * @stable ICU 2.0
    182  */
    183 U_STABLE UResourceBundle* U_EXPORT2
    184 ures_openDirect(const char* packageName,
    185                 const char* locale,
    186                 UErrorCode* status);
    187 
    188 /**
    189  * Same as ures_open() but takes a const UChar *path.
    190  * This path will be converted to char * using the default converter,
    191  * then ures_open() is called.
    192  *
    193  * @param packageName   The packageName and locale together point to an ICU udata object,
    194  *                      as defined by <code> udata_open( packageName, "res", locale, err) </code>
    195  *                      or equivalent.  Typically, packageName will refer to a (.dat) file, or to
    196  *                      a package registered with udata_setAppData(). Using a full file or directory
    197  *                      pathname for packageName is deprecated. If NULL, ICU data will be used.
    198  * @param locale  specifies the locale for which we want to open the resource
    199  *                if NULL, the default locale will be used. If strlen(locale) == 0
    200  *                root locale will be used.
    201  * @param status  fills in the outgoing error code.
    202  * @return      a newly allocated resource bundle.
    203  * @see ures_open
    204  * @stable ICU 2.0
    205  */
    206 U_STABLE UResourceBundle* U_EXPORT2
    207 ures_openU(const UChar* packageName,
    208            const char* locale,
    209            UErrorCode* status);
    210 
    211 #ifndef U_HIDE_DEPRECATED_API
    212 /**
    213  * Returns the number of strings/arrays in resource bundles.
    214  * Better to use ures_getSize, as this function will be deprecated.
    215  *
    216  *@param resourceBundle resource bundle containing the desired strings
    217  *@param resourceKey key tagging the resource
    218  *@param err fills in the outgoing error code
    219  *                could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
    220  *                could be a non-failing error
    221  *                e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_FALLBACK_WARNING </TT>
    222  *@return: for    <STRONG>Arrays</STRONG>: returns the number of resources in the array
    223  *                <STRONG>Tables</STRONG>: returns the number of resources in the table
    224  *                <STRONG>single string</STRONG>: returns 1
    225  *@see ures_getSize
    226  * @deprecated ICU 2.8 User ures_getSize instead
    227  */
    228 U_DEPRECATED int32_t U_EXPORT2
    229 ures_countArrayItems(const UResourceBundle* resourceBundle,
    230                      const char* resourceKey,
    231                      UErrorCode* err);
    232 #endif  /* U_HIDE_DEPRECATED_API */
    233 /**
    234  * Close a resource bundle, all pointers returned from the various ures_getXXX calls
    235  * on this particular bundle should be considered invalid henceforth.
    236  *
    237  * @param resourceBundle a pointer to a resourceBundle struct. Can be NULL.
    238  * @see ures_open
    239  * @stable ICU 2.0
    240  */
    241 U_STABLE void U_EXPORT2
    242 ures_close(UResourceBundle* resourceBundle);
    243 
    244 #if U_SHOW_CPLUSPLUS_API
    245 
    246 U_NAMESPACE_BEGIN
    247 
    248 /**
    249  * \class LocalUResourceBundlePointer
    250  * "Smart pointer" class, closes a UResourceBundle via ures_close().
    251  * For most methods see the LocalPointerBase base class.
    252  *
    253  * @see LocalPointerBase
    254  * @see LocalPointer
    255  * @stable ICU 4.4
    256  */
    257 U_DEFINE_LOCAL_OPEN_POINTER(LocalUResourceBundlePointer, UResourceBundle, ures_close);
    258 
    259 U_NAMESPACE_END
    260 
    261 #endif
    262 
    263 #ifndef U_HIDE_DEPRECATED_API
    264 /**
    265  * Return the version number associated with this ResourceBundle as a string. Please
    266  * use ures_getVersion as this function is going to be deprecated.
    267  *
    268  * @param resourceBundle The resource bundle for which the version is checked.
    269  * @return  A version number string as specified in the resource bundle or its parent.
    270  *          The caller does not own this string.
    271  * @see ures_getVersion
    272  * @deprecated ICU 2.8 Use ures_getVersion instead.
    273  */
    274 U_DEPRECATED const char* U_EXPORT2
    275 ures_getVersionNumber(const UResourceBundle*   resourceBundle);
    276 #endif  /* U_HIDE_DEPRECATED_API */
    277 
    278 /**
    279  * Return the version number associated with this ResourceBundle as an
    280  * UVersionInfo array.
    281  *
    282  * @param resB The resource bundle for which the version is checked.
    283  * @param versionInfo A UVersionInfo array that is filled with the version number
    284  *                    as specified in the resource bundle or its parent.
    285  * @stable ICU 2.0
    286  */
    287 U_STABLE void U_EXPORT2
    288 ures_getVersion(const UResourceBundle* resB,
    289                 UVersionInfo versionInfo);
    290 
    291 #ifndef U_HIDE_DEPRECATED_API
    292 /**
    293  * Return the name of the Locale associated with this ResourceBundle. This API allows
    294  * you to query for the real locale of the resource. For example, if you requested
    295  * "en_US_CALIFORNIA" and only "en_US" bundle exists, "en_US" will be returned.
    296  * For subresources, the locale where this resource comes from will be returned.
    297  * If fallback has occured, getLocale will reflect this.
    298  *
    299  * @param resourceBundle resource bundle in question
    300  * @param status just for catching illegal arguments
    301  * @return  A Locale name
    302  * @deprecated ICU 2.8 Use ures_getLocaleByType instead.
    303  */
    304 U_DEPRECATED const char* U_EXPORT2
    305 ures_getLocale(const UResourceBundle* resourceBundle,
    306                UErrorCode* status);
    307 #endif  /* U_HIDE_DEPRECATED_API */
    308 
    309 /**
    310  * Return the name of the Locale associated with this ResourceBundle.
    311  * You can choose between requested, valid and real locale.
    312  *
    313  * @param resourceBundle resource bundle in question
    314  * @param type You can choose between requested, valid and actual
    315  *             locale. For description see the definition of
    316  *             ULocDataLocaleType in uloc.h
    317  * @param status just for catching illegal arguments
    318  * @return  A Locale name
    319  * @stable ICU 2.8
    320  */
    321 U_STABLE const char* U_EXPORT2
    322 ures_getLocaleByType(const UResourceBundle* resourceBundle,
    323                      ULocDataLocaleType type,
    324                      UErrorCode* status);
    325 
    326 
    327 #ifndef U_HIDE_INTERNAL_API
    328 /**
    329  * Same as ures_open() but uses the fill-in parameter instead of allocating
    330  * a bundle, if r!=NULL.
    331  * TODO need to revisit usefulness of this function
    332  *      and usage model for fillIn parameters without knowing sizeof(UResourceBundle)
    333  * @param r The resourcebundle to open
    334  * @param packageName   The packageName and locale together point to an ICU udata object,
    335  *                      as defined by <code> udata_open( packageName, "res", locale, err) </code>
    336  *                      or equivalent.  Typically, packageName will refer to a (.dat) file, or to
    337  *                      a package registered with udata_setAppData(). Using a full file or directory
    338  *                      pathname for packageName is deprecated. If NULL, ICU data will be used.
    339  * @param localeID specifies the locale for which we want to open the resource
    340  * @param status The error code
    341  * @return a newly allocated resource bundle or NULL if it doesn't exist.
    342  * @internal
    343  */
    344 U_INTERNAL void U_EXPORT2
    345 ures_openFillIn(UResourceBundle *r,
    346                 const char* packageName,
    347                 const char* localeID,
    348                 UErrorCode* status);
    349 #endif  /* U_HIDE_INTERNAL_API */
    350 
    351 /**
    352  * Returns a string from a string resource type
    353  *
    354  * @param resourceBundle a string resource
    355  * @param len    fills in the length of resulting string
    356  * @param status fills in the outgoing error code
    357  *                could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
    358  *                Always check the value of status. Don't count on returning NULL.
    359  *                could be a non-failing error
    360  *                e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
    361  * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
    362  * @see ures_getBinary
    363  * @see ures_getIntVector
    364  * @see ures_getInt
    365  * @see ures_getUInt
    366  * @stable ICU 2.0
    367  */
    368 U_STABLE const UChar* U_EXPORT2
    369 ures_getString(const UResourceBundle* resourceBundle,
    370                int32_t* len,
    371                UErrorCode* status);
    372 
    373 /**
    374  * Returns a UTF-8 string from a string resource.
    375  * The UTF-8 string may be returnable directly as a pointer, or
    376  * it may need to be copied, or transformed from UTF-16 using u_strToUTF8()
    377  * or equivalent.
    378  *
    379  * If forceCopy==TRUE, then the string is always written to the dest buffer
    380  * and dest is returned.
    381  *
    382  * If forceCopy==FALSE, then the string is returned as a pointer if possible,
    383  * without needing a dest buffer (it can be NULL). If the string needs to be
    384  * copied or transformed, then it may be placed into dest at an arbitrary offset.
    385  *
    386  * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and
    387  * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual.
    388  *
    389  * If the string is transformed from UTF-16, then a conversion error may occur
    390  * if an unpaired surrogate is encountered. If the function is successful, then
    391  * the output UTF-8 string is always well-formed.
    392  *
    393  * @param resB Resource bundle.
    394  * @param dest Destination buffer. Can be NULL only if capacity=*length==0.
    395  * @param length Input: Capacity of destination buffer.
    396  *               Output: Actual length of the UTF-8 string, not counting the
    397  *               terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR.
    398  *               Can be NULL, meaning capacity=0 and the string length is not
    399  *               returned to the caller.
    400  * @param forceCopy If TRUE, then the output string will always be written to
    401  *                  dest, with U_BUFFER_OVERFLOW_ERROR and
    402  *                  U_STRING_NOT_TERMINATED_WARNING set if appropriate.
    403  *                  If FALSE, then the dest buffer may or may not contain a
    404  *                  copy of the string. dest may or may not be modified.
    405  *                  If a copy needs to be written, then the UErrorCode parameter
    406  *                  indicates overflow etc. as usual.
    407  * @param status Pointer to a standard ICU error code. Its input value must
    408  *               pass the U_SUCCESS() test, or else the function returns
    409  *               immediately. Check for U_FAILURE() on output or use with
    410  *               function chaining. (See User Guide for details.)
    411  * @return The pointer to the UTF-8 string. It may be dest, or at some offset
    412  *         from dest (only if !forceCopy), or in unrelated memory.
    413  *         Always NUL-terminated unless the string was written to dest and
    414  *         length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set).
    415  *
    416  * @see ures_getString
    417  * @see u_strToUTF8
    418  * @stable ICU 3.6
    419  */
    420 U_STABLE const char * U_EXPORT2
    421 ures_getUTF8String(const UResourceBundle *resB,
    422                    char *dest, int32_t *length,
    423                    UBool forceCopy,
    424                    UErrorCode *status);
    425 
    426 /**
    427  * Returns a binary data from a binary resource.
    428  *
    429  * @param resourceBundle a string resource
    430  * @param len    fills in the length of resulting byte chunk
    431  * @param status fills in the outgoing error code
    432  *                could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
    433  *                Always check the value of status. Don't count on returning NULL.
    434  *                could be a non-failing error
    435  *                e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
    436  * @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.
    437  * @see ures_getString
    438  * @see ures_getIntVector
    439  * @see ures_getInt
    440  * @see ures_getUInt
    441  * @stable ICU 2.0
    442  */
    443 U_STABLE const uint8_t* U_EXPORT2
    444 ures_getBinary(const UResourceBundle* resourceBundle,
    445                int32_t* len,
    446                UErrorCode* status);
    447 
    448 /**
    449  * Returns a 32 bit integer array from a resource.
    450  *
    451  * @param resourceBundle an int vector resource
    452  * @param len    fills in the length of resulting byte chunk
    453  * @param status fills in the outgoing error code
    454  *                could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
    455  *                Always check the value of status. Don't count on returning NULL.
    456  *                could be a non-failing error
    457  *                e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
    458  * @return a pointer to a chunk of integers which live in a memory mapped/DLL file.
    459  * @see ures_getBinary
    460  * @see ures_getString
    461  * @see ures_getInt
    462  * @see ures_getUInt
    463  * @stable ICU 2.0
    464  */
    465 U_STABLE const int32_t* U_EXPORT2
    466 ures_getIntVector(const UResourceBundle* resourceBundle,
    467                   int32_t* len,
    468                   UErrorCode* status);
    469 
    470 /**
    471  * Returns an unsigned integer from a resource.
    472  * This integer is originally 28 bits.
    473  *
    474  * @param resourceBundle a string resource
    475  * @param status fills in the outgoing error code
    476  *                could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
    477  *                could be a non-failing error
    478  *                e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
    479  * @return an integer value
    480  * @see ures_getInt
    481  * @see ures_getIntVector
    482  * @see ures_getBinary
    483  * @see ures_getString
    484  * @stable ICU 2.0
    485  */
    486 U_STABLE uint32_t U_EXPORT2
    487 ures_getUInt(const UResourceBundle* resourceBundle,
    488              UErrorCode *status);
    489 
    490 /**
    491  * Returns a signed integer from a resource.
    492  * This integer is originally 28 bit and the sign gets propagated.
    493  *
    494  * @param resourceBundle a string resource
    495  * @param status  fills in the outgoing error code
    496  *                could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
    497  *                could be a non-failing error
    498  *                e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
    499  * @return an integer value
    500  * @see ures_getUInt
    501  * @see ures_getIntVector
    502  * @see ures_getBinary
    503  * @see ures_getString
    504  * @stable ICU 2.0
    505  */
    506 U_STABLE int32_t U_EXPORT2
    507 ures_getInt(const UResourceBundle* resourceBundle,
    508             UErrorCode *status);
    509 
    510 /**
    511  * Returns the size of a resource. Size for scalar types is always 1,
    512  * and for vector/table types is the number of child resources.
    513  * @warning Integer array is treated as a scalar type. There are no
    514  *          APIs to access individual members of an integer array. It
    515  *          is always returned as a whole.
    516  * @param resourceBundle a resource
    517  * @return number of resources in a given resource.
    518  * @stable ICU 2.0
    519  */
    520 U_STABLE int32_t U_EXPORT2
    521 ures_getSize(const UResourceBundle *resourceBundle);
    522 
    523 /**
    524  * Returns the type of a resource. Available types are defined in enum UResType
    525  *
    526  * @param resourceBundle a resource
    527  * @return type of the given resource.
    528  * @see UResType
    529  * @stable ICU 2.0
    530  */
    531 U_STABLE UResType U_EXPORT2
    532 ures_getType(const UResourceBundle *resourceBundle);
    533 
    534 /**
    535  * Returns the key associated with a given resource. Not all the resources have a key - only
    536  * those that are members of a table.
    537  *
    538  * @param resourceBundle a resource
    539  * @return a key associated to this resource, or NULL if it doesn't have a key
    540  * @stable ICU 2.0
    541  */
    542 U_STABLE const char * U_EXPORT2
    543 ures_getKey(const UResourceBundle *resourceBundle);
    544 
    545 /* ITERATION API
    546     This API provides means for iterating through a resource
    547 */
    548 
    549 /**
    550  * Resets the internal context of a resource so that iteration starts from the first element.
    551  *
    552  * @param resourceBundle a resource
    553  * @stable ICU 2.0
    554  */
    555 U_STABLE void U_EXPORT2
    556 ures_resetIterator(UResourceBundle *resourceBundle);
    557 
    558 /**
    559  * Checks whether the given resource has another element to iterate over.
    560  *
    561  * @param resourceBundle a resource
    562  * @return TRUE if there are more elements, FALSE if there is no more elements
    563  * @stable ICU 2.0
    564  */
    565 U_STABLE UBool U_EXPORT2
    566 ures_hasNext(const UResourceBundle *resourceBundle);
    567 
    568 /**
    569  * Returns the next resource in a given resource or NULL if there are no more resources
    570  * to iterate over. Features a fill-in parameter.
    571  *
    572  * @param resourceBundle    a resource
    573  * @param fillIn            if NULL a new UResourceBundle struct is allocated and must be closed by the caller.
    574  *                          Alternatively, you can supply a struct to be filled by this function.
    575  * @param status            fills in the outgoing error code. You may still get a non NULL result even if an
    576  *                          error occured. Check status instead.
    577  * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it
    578  * @stable ICU 2.0
    579  */
    580 U_STABLE UResourceBundle* U_EXPORT2
    581 ures_getNextResource(UResourceBundle *resourceBundle,
    582                      UResourceBundle *fillIn,
    583                      UErrorCode *status);
    584 
    585 /**
    586  * Returns the next string in a given resource or NULL if there are no more resources
    587  * to iterate over.
    588  *
    589  * @param resourceBundle    a resource
    590  * @param len               fill in length of the string
    591  * @param key               fill in for key associated with this string. NULL if no key
    592  * @param status            fills in the outgoing error code. If an error occured, we may return NULL, but don't
    593  *                          count on it. Check status instead!
    594  * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
    595  * @stable ICU 2.0
    596  */
    597 U_STABLE const UChar* U_EXPORT2
    598 ures_getNextString(UResourceBundle *resourceBundle,
    599                    int32_t* len,
    600                    const char ** key,
    601                    UErrorCode *status);
    602 
    603 /**
    604  * Returns the resource in a given resource at the specified index. Features a fill-in parameter.
    605  *
    606  * @param resourceBundle    the resource bundle from which to get a sub-resource
    607  * @param indexR            an index to the wanted resource.
    608  * @param fillIn            if NULL a new UResourceBundle struct is allocated and must be closed by the caller.
    609  *                          Alternatively, you can supply a struct to be filled by this function.
    610  * @param status            fills in the outgoing error code. Don't count on NULL being returned if an error has
    611  *                          occured. Check status instead.
    612  * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it
    613  * @stable ICU 2.0
    614  */
    615 U_STABLE UResourceBundle* U_EXPORT2
    616 ures_getByIndex(const UResourceBundle *resourceBundle,
    617                 int32_t indexR,
    618                 UResourceBundle *fillIn,
    619                 UErrorCode *status);
    620 
    621 /**
    622  * Returns the string in a given resource at the specified index.
    623  *
    624  * @param resourceBundle    a resource
    625  * @param indexS            an index to the wanted string.
    626  * @param len               fill in length of the string
    627  * @param status            fills in the outgoing error code. If an error occured, we may return NULL, but don't
    628  *                          count on it. Check status instead!
    629  * @return                  a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
    630  * @stable ICU 2.0
    631  */
    632 U_STABLE const UChar* U_EXPORT2
    633 ures_getStringByIndex(const UResourceBundle *resourceBundle,
    634                       int32_t indexS,
    635                       int32_t* len,
    636                       UErrorCode *status);
    637 
    638 /**
    639  * Returns a UTF-8 string from a resource at the specified index.
    640  * The UTF-8 string may be returnable directly as a pointer, or
    641  * it may need to be copied, or transformed from UTF-16 using u_strToUTF8()
    642  * or equivalent.
    643  *
    644  * If forceCopy==TRUE, then the string is always written to the dest buffer
    645  * and dest is returned.
    646  *
    647  * If forceCopy==FALSE, then the string is returned as a pointer if possible,
    648  * without needing a dest buffer (it can be NULL). If the string needs to be
    649  * copied or transformed, then it may be placed into dest at an arbitrary offset.
    650  *
    651  * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and
    652  * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual.
    653  *
    654  * If the string is transformed from UTF-16, then a conversion error may occur
    655  * if an unpaired surrogate is encountered. If the function is successful, then
    656  * the output UTF-8 string is always well-formed.
    657  *
    658  * @param resB Resource bundle.
    659  * @param stringIndex An index to the wanted string.
    660  * @param dest Destination buffer. Can be NULL only if capacity=*length==0.
    661  * @param pLength Input: Capacity of destination buffer.
    662  *               Output: Actual length of the UTF-8 string, not counting the
    663  *               terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR.
    664  *               Can be NULL, meaning capacity=0 and the string length is not
    665  *               returned to the caller.
    666  * @param forceCopy If TRUE, then the output string will always be written to
    667  *                  dest, with U_BUFFER_OVERFLOW_ERROR and
    668  *                  U_STRING_NOT_TERMINATED_WARNING set if appropriate.
    669  *                  If FALSE, then the dest buffer may or may not contain a
    670  *                  copy of the string. dest may or may not be modified.
    671  *                  If a copy needs to be written, then the UErrorCode parameter
    672  *                  indicates overflow etc. as usual.
    673  * @param status Pointer to a standard ICU error code. Its input value must
    674  *               pass the U_SUCCESS() test, or else the function returns
    675  *               immediately. Check for U_FAILURE() on output or use with
    676  *               function chaining. (See User Guide for details.)
    677  * @return The pointer to the UTF-8 string. It may be dest, or at some offset
    678  *         from dest (only if !forceCopy), or in unrelated memory.
    679  *         Always NUL-terminated unless the string was written to dest and
    680  *         length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set).
    681  *
    682  * @see ures_getStringByIndex
    683  * @see u_strToUTF8
    684  * @stable ICU 3.6
    685  */
    686 U_STABLE const char * U_EXPORT2
    687 ures_getUTF8StringByIndex(const UResourceBundle *resB,
    688                           int32_t stringIndex,
    689                           char *dest, int32_t *pLength,
    690                           UBool forceCopy,
    691                           UErrorCode *status);
    692 
    693 /**
    694  * Returns a resource in a given resource that has a given key. This procedure works only with table
    695  * resources. Features a fill-in parameter.
    696  *
    697  * @param resourceBundle    a resource
    698  * @param key               a key associated with the wanted resource
    699  * @param fillIn            if NULL a new UResourceBundle struct is allocated and must be closed by the caller.
    700  *                          Alternatively, you can supply a struct to be filled by this function.
    701  * @param status            fills in the outgoing error code.
    702  * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it
    703  * @stable ICU 2.0
    704  */
    705 U_STABLE UResourceBundle* U_EXPORT2
    706 ures_getByKey(const UResourceBundle *resourceBundle,
    707               const char* key,
    708               UResourceBundle *fillIn,
    709               UErrorCode *status);
    710 
    711 /**
    712  * Returns a string in a given resource that has a given key. This procedure works only with table
    713  * resources.
    714  *
    715  * @param resB              a resource
    716  * @param key               a key associated with the wanted string
    717  * @param len               fill in length of the string
    718  * @param status            fills in the outgoing error code. If an error occured, we may return NULL, but don't
    719  *                          count on it. Check status instead!
    720  * @return                  a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
    721  * @stable ICU 2.0
    722  */
    723 U_STABLE const UChar* U_EXPORT2
    724 ures_getStringByKey(const UResourceBundle *resB,
    725                     const char* key,
    726                     int32_t* len,
    727                     UErrorCode *status);
    728 
    729 /**
    730  * Returns a UTF-8 string from a resource and a key.
    731  * This function works only with table resources.
    732  *
    733  * The UTF-8 string may be returnable directly as a pointer, or
    734  * it may need to be copied, or transformed from UTF-16 using u_strToUTF8()
    735  * or equivalent.
    736  *
    737  * If forceCopy==TRUE, then the string is always written to the dest buffer
    738  * and dest is returned.
    739  *
    740  * If forceCopy==FALSE, then the string is returned as a pointer if possible,
    741  * without needing a dest buffer (it can be NULL). If the string needs to be
    742  * copied or transformed, then it may be placed into dest at an arbitrary offset.
    743  *
    744  * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and
    745  * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual.
    746  *
    747  * If the string is transformed from UTF-16, then a conversion error may occur
    748  * if an unpaired surrogate is encountered. If the function is successful, then
    749  * the output UTF-8 string is always well-formed.
    750  *
    751  * @param resB Resource bundle.
    752  * @param key  A key associated with the wanted resource
    753  * @param dest Destination buffer. Can be NULL only if capacity=*length==0.
    754  * @param pLength Input: Capacity of destination buffer.
    755  *               Output: Actual length of the UTF-8 string, not counting the
    756  *               terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR.
    757  *               Can be NULL, meaning capacity=0 and the string length is not
    758  *               returned to the caller.
    759  * @param forceCopy If TRUE, then the output string will always be written to
    760  *                  dest, with U_BUFFER_OVERFLOW_ERROR and
    761  *                  U_STRING_NOT_TERMINATED_WARNING set if appropriate.
    762  *                  If FALSE, then the dest buffer may or may not contain a
    763  *                  copy of the string. dest may or may not be modified.
    764  *                  If a copy needs to be written, then the UErrorCode parameter
    765  *                  indicates overflow etc. as usual.
    766  * @param status Pointer to a standard ICU error code. Its input value must
    767  *               pass the U_SUCCESS() test, or else the function returns
    768  *               immediately. Check for U_FAILURE() on output or use with
    769  *               function chaining. (See User Guide for details.)
    770  * @return The pointer to the UTF-8 string. It may be dest, or at some offset
    771  *         from dest (only if !forceCopy), or in unrelated memory.
    772  *         Always NUL-terminated unless the string was written to dest and
    773  *         length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set).
    774  *
    775  * @see ures_getStringByKey
    776  * @see u_strToUTF8
    777  * @stable ICU 3.6
    778  */
    779 U_STABLE const char * U_EXPORT2
    780 ures_getUTF8StringByKey(const UResourceBundle *resB,
    781                         const char *key,
    782                         char *dest, int32_t *pLength,
    783                         UBool forceCopy,
    784                         UErrorCode *status);
    785 
    786 #if U_SHOW_CPLUSPLUS_API
    787 #include "unicode/unistr.h"
    788 
    789 U_NAMESPACE_BEGIN
    790 /**
    791  * returns a string from a string resource type
    792  *
    793  * @param resB    a resource
    794  * @param status: fills in the outgoing error code
    795  *                could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
    796  *                could be a non-failing error
    797  *                e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
    798  * @return        a UnicodeString object. If there is an error, string is bogus
    799  * @stable ICU 2.0
    800  */
    801 inline UnicodeString
    802 ures_getUnicodeString(const UResourceBundle *resB,
    803                       UErrorCode* status)
    804 {
    805     int32_t len = 0;
    806     const UChar *r = ures_getString(resB, &len, status);
    807     return UnicodeString(TRUE, r, len);
    808 }
    809 
    810 /**
    811  * Returns the next string in a resource or NULL if there are no more resources
    812  * to iterate over.
    813  *
    814  * @param resB              a resource
    815  * @param key               fill in for key associated with this string
    816  * @param status            fills in the outgoing error code
    817  * @return an UnicodeString object.
    818  * @stable ICU 2.0
    819  */
    820 inline UnicodeString
    821 ures_getNextUnicodeString(UResourceBundle *resB,
    822                           const char ** key,
    823                           UErrorCode* status)
    824 {
    825     int32_t len = 0;
    826     const UChar* r = ures_getNextString(resB, &len, key, status);
    827     return UnicodeString(TRUE, r, len);
    828 }
    829 
    830 /**
    831  * Returns the string in a given resource at the specified index.
    832  *
    833  * @param resB              a resource
    834  * @param indexS            an index to the wanted string.
    835  * @param status            fills in the outgoing error code
    836  * @return                  an UnicodeString object. If there is an error, string is bogus
    837  * @stable ICU 2.0
    838  */
    839 inline UnicodeString
    840 ures_getUnicodeStringByIndex(const UResourceBundle *resB,
    841                              int32_t indexS,
    842                              UErrorCode* status)
    843 {
    844     int32_t len = 0;
    845     const UChar* r = ures_getStringByIndex(resB, indexS, &len, status);
    846     return UnicodeString(TRUE, r, len);
    847 }
    848 
    849 /**
    850  * Returns a string in a resource that has a given key. This procedure works only with table
    851  * resources.
    852  *
    853  * @param resB              a resource
    854  * @param key               a key associated with the wanted string
    855  * @param status            fills in the outgoing error code
    856  * @return                  an UnicodeString object. If there is an error, string is bogus
    857  * @stable ICU 2.0
    858  */
    859 inline UnicodeString
    860 ures_getUnicodeStringByKey(const UResourceBundle *resB,
    861                            const char* key,
    862                            UErrorCode* status)
    863 {
    864     int32_t len = 0;
    865     const UChar* r = ures_getStringByKey(resB, key, &len, status);
    866     return UnicodeString(TRUE, r, len);
    867 }
    868 
    869 U_NAMESPACE_END
    870 
    871 #endif
    872 
    873 /**
    874  * Create a string enumerator, owned by the caller, of all locales located within
    875  * the specified resource tree.
    876  * @param packageName name of the tree, such as (NULL) or U_ICUDATA_ALIAS or  or "ICUDATA-coll"
    877  * This call is similar to uloc_getAvailable().
    878  * @param status error code
    879  * @stable ICU 3.2
    880  */
    881 U_STABLE UEnumeration* U_EXPORT2
    882 ures_openAvailableLocales(const char *packageName, UErrorCode *status);
    883 
    884 
    885 #endif /*_URES*/
    886 /*eof*/
    887