jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ********************************************************************** jpayne@69: * Copyright (C) 1997-2016, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: ********************************************************************** jpayne@69: * jpayne@69: * File URES.H (formerly CRESBUND.H) jpayne@69: * jpayne@69: * Modification History: jpayne@69: * jpayne@69: * Date Name Description jpayne@69: * 04/01/97 aliu Creation. jpayne@69: * 02/22/99 damiba overhaul. jpayne@69: * 04/04/99 helena Fixed internal header inclusion. jpayne@69: * 04/15/99 Madhu Updated Javadoc jpayne@69: * 06/14/99 stephen Removed functions taking a filename suffix. jpayne@69: * 07/20/99 stephen Language-independent typedef to void* jpayne@69: * 11/09/99 weiv Added ures_getLocale() jpayne@69: * 06/24/02 weiv Added support for resource sharing jpayne@69: ****************************************************************************** jpayne@69: */ jpayne@69: jpayne@69: #ifndef URES_H jpayne@69: #define URES_H jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: #include "unicode/uloc.h" jpayne@69: #include "unicode/localpointer.h" jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C API: Resource Bundle jpayne@69: * jpayne@69: *

C API: Resource Bundle

jpayne@69: * jpayne@69: * C API representing a collection of resource information pertaining to a given jpayne@69: * locale. A resource bundle provides a way of accessing locale- specific information in jpayne@69: * a data file. You create a resource bundle that manages the resources for a given jpayne@69: * locale and then ask it for individual resources. jpayne@69: *

jpayne@69: * Resource bundles in ICU4C are currently defined using text files which conform to the following jpayne@69: * BNF definition. jpayne@69: * More on resource bundle concepts and syntax can be found in the jpayne@69: * Users Guide. jpayne@69: *

jpayne@69: */ jpayne@69: jpayne@69: /** jpayne@69: * UResourceBundle is an opaque type for handles for resource bundles in C APIs. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: struct UResourceBundle; jpayne@69: jpayne@69: /** jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: typedef struct UResourceBundle UResourceBundle; jpayne@69: jpayne@69: /** jpayne@69: * Numeric constants for types of resource items. jpayne@69: * @see ures_getType jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: typedef enum { jpayne@69: /** Resource type constant for "no resource". @stable ICU 2.6 */ jpayne@69: URES_NONE=-1, jpayne@69: jpayne@69: /** Resource type constant for 16-bit Unicode strings. @stable ICU 2.6 */ jpayne@69: URES_STRING=0, jpayne@69: jpayne@69: /** Resource type constant for binary data. @stable ICU 2.6 */ jpayne@69: URES_BINARY=1, jpayne@69: jpayne@69: /** Resource type constant for tables of key-value pairs. @stable ICU 2.6 */ jpayne@69: URES_TABLE=2, jpayne@69: jpayne@69: /** jpayne@69: * Resource type constant for aliases; jpayne@69: * internally stores a string which identifies the actual resource jpayne@69: * storing the data (can be in a different resource bundle). jpayne@69: * Resolved internally before delivering the actual resource through the API. jpayne@69: * @stable ICU 2.6 jpayne@69: */ jpayne@69: URES_ALIAS=3, jpayne@69: jpayne@69: /** jpayne@69: * Resource type constant for a single 28-bit integer, interpreted as jpayne@69: * signed or unsigned by the ures_getInt() or ures_getUInt() function. jpayne@69: * @see ures_getInt jpayne@69: * @see ures_getUInt jpayne@69: * @stable ICU 2.6 jpayne@69: */ jpayne@69: URES_INT=7, jpayne@69: jpayne@69: /** Resource type constant for arrays of resources. @stable ICU 2.6 */ jpayne@69: URES_ARRAY=8, jpayne@69: jpayne@69: /** jpayne@69: * Resource type constant for vectors of 32-bit integers. jpayne@69: * @see ures_getIntVector jpayne@69: * @stable ICU 2.6 jpayne@69: */ jpayne@69: URES_INT_VECTOR = 14, jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** @deprecated ICU 2.6 Use the URES_ constant instead. */ jpayne@69: RES_NONE=URES_NONE, jpayne@69: /** @deprecated ICU 2.6 Use the URES_ constant instead. */ jpayne@69: RES_STRING=URES_STRING, jpayne@69: /** @deprecated ICU 2.6 Use the URES_ constant instead. */ jpayne@69: RES_BINARY=URES_BINARY, jpayne@69: /** @deprecated ICU 2.6 Use the URES_ constant instead. */ jpayne@69: RES_TABLE=URES_TABLE, jpayne@69: /** @deprecated ICU 2.6 Use the URES_ constant instead. */ jpayne@69: RES_ALIAS=URES_ALIAS, jpayne@69: /** @deprecated ICU 2.6 Use the URES_ constant instead. */ jpayne@69: RES_INT=URES_INT, jpayne@69: /** @deprecated ICU 2.6 Use the URES_ constant instead. */ jpayne@69: RES_ARRAY=URES_ARRAY, jpayne@69: /** @deprecated ICU 2.6 Use the URES_ constant instead. */ jpayne@69: RES_INT_VECTOR=URES_INT_VECTOR, jpayne@69: /** @deprecated ICU 2.6 Not used. */ jpayne@69: RES_RESERVED=15, jpayne@69: jpayne@69: /** jpayne@69: * One more than the highest normal UResType value. jpayne@69: * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. jpayne@69: */ jpayne@69: URES_LIMIT = 16 jpayne@69: #endif // U_HIDE_DEPRECATED_API jpayne@69: } UResType; jpayne@69: jpayne@69: /* jpayne@69: * Functions to create and destroy resource bundles. jpayne@69: */ jpayne@69: jpayne@69: /** jpayne@69: * Opens a UResourceBundle, from which users can extract strings by using jpayne@69: * their corresponding keys. jpayne@69: * Note that the caller is responsible of calling ures_close on each successfully jpayne@69: * opened resource bundle. jpayne@69: * @param packageName The packageName and locale together point to an ICU udata object, jpayne@69: * as defined by udata_open( packageName, "res", locale, err) jpayne@69: * or equivalent. Typically, packageName will refer to a (.dat) file, or to jpayne@69: * a package registered with udata_setAppData(). Using a full file or directory jpayne@69: * pathname for packageName is deprecated. If NULL, ICU data will be used. jpayne@69: * @param locale specifies the locale for which we want to open the resource jpayne@69: * if NULL, the default locale will be used. If strlen(locale) == 0 jpayne@69: * root locale will be used. jpayne@69: * jpayne@69: * @param status fills in the outgoing error code. jpayne@69: * The UErrorCode err parameter is used to return status information to the user. To jpayne@69: * check whether the construction succeeded or not, you should check the value of jpayne@69: * U_SUCCESS(err). If you wish more detailed information, you can check for jpayne@69: * informational status results which still indicate success. U_USING_FALLBACK_WARNING jpayne@69: * indicates that a fall back locale was used. For example, 'de_CH' was requested, jpayne@69: * but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that jpayne@69: * the default locale data or root locale data was used; neither the requested locale jpayne@69: * nor any of its fall back locales could be found. Please see the users guide for more jpayne@69: * information on this topic. jpayne@69: * @return a newly allocated resource bundle. jpayne@69: * @see ures_close jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UResourceBundle* U_EXPORT2 jpayne@69: ures_open(const char* packageName, jpayne@69: const char* locale, jpayne@69: UErrorCode* status); jpayne@69: jpayne@69: jpayne@69: /** This function does not care what kind of localeID is passed in. It simply opens a bundle with jpayne@69: * that name. Fallback mechanism is disabled for the new bundle. If the requested bundle contains jpayne@69: * an %%ALIAS directive, the results are undefined. jpayne@69: * @param packageName The packageName and locale together point to an ICU udata object, jpayne@69: * as defined by udata_open( packageName, "res", locale, err) jpayne@69: * or equivalent. Typically, packageName will refer to a (.dat) file, or to jpayne@69: * a package registered with udata_setAppData(). Using a full file or directory jpayne@69: * pathname for packageName is deprecated. If NULL, ICU data will be used. jpayne@69: * @param locale specifies the locale for which we want to open the resource jpayne@69: * if NULL, the default locale will be used. If strlen(locale) == 0 jpayne@69: * root locale will be used. jpayne@69: * jpayne@69: * @param status fills in the outgoing error code. Either U_ZERO_ERROR or U_MISSING_RESOURCE_ERROR jpayne@69: * @return a newly allocated resource bundle or NULL if it doesn't exist. jpayne@69: * @see ures_close jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UResourceBundle* U_EXPORT2 jpayne@69: ures_openDirect(const char* packageName, jpayne@69: const char* locale, jpayne@69: UErrorCode* status); jpayne@69: jpayne@69: /** jpayne@69: * Same as ures_open() but takes a const UChar *path. jpayne@69: * This path will be converted to char * using the default converter, jpayne@69: * then ures_open() is called. jpayne@69: * jpayne@69: * @param packageName The packageName and locale together point to an ICU udata object, jpayne@69: * as defined by udata_open( packageName, "res", locale, err) jpayne@69: * or equivalent. Typically, packageName will refer to a (.dat) file, or to jpayne@69: * a package registered with udata_setAppData(). Using a full file or directory jpayne@69: * pathname for packageName is deprecated. If NULL, ICU data will be used. jpayne@69: * @param locale specifies the locale for which we want to open the resource jpayne@69: * if NULL, the default locale will be used. If strlen(locale) == 0 jpayne@69: * root locale will be used. jpayne@69: * @param status fills in the outgoing error code. jpayne@69: * @return a newly allocated resource bundle. jpayne@69: * @see ures_open jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UResourceBundle* U_EXPORT2 jpayne@69: ures_openU(const UChar* packageName, jpayne@69: const char* locale, jpayne@69: UErrorCode* status); jpayne@69: jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * Returns the number of strings/arrays in resource bundles. jpayne@69: * Better to use ures_getSize, as this function will be deprecated. jpayne@69: * jpayne@69: *@param resourceBundle resource bundle containing the desired strings jpayne@69: *@param resourceKey key tagging the resource jpayne@69: *@param err fills in the outgoing error code jpayne@69: * could be U_MISSING_RESOURCE_ERROR if the key is not found jpayne@69: * could be a non-failing error jpayne@69: * e.g.: U_USING_FALLBACK_WARNING,U_USING_FALLBACK_WARNING jpayne@69: *@return: for Arrays: returns the number of resources in the array jpayne@69: * Tables: returns the number of resources in the table jpayne@69: * single string: returns 1 jpayne@69: *@see ures_getSize jpayne@69: * @deprecated ICU 2.8 User ures_getSize instead jpayne@69: */ jpayne@69: U_DEPRECATED int32_t U_EXPORT2 jpayne@69: ures_countArrayItems(const UResourceBundle* resourceBundle, jpayne@69: const char* resourceKey, jpayne@69: UErrorCode* err); jpayne@69: #endif /* U_HIDE_DEPRECATED_API */ jpayne@69: jpayne@69: /** jpayne@69: * Close a resource bundle, all pointers returned from the various ures_getXXX calls jpayne@69: * on this particular bundle should be considered invalid henceforth. jpayne@69: * jpayne@69: * @param resourceBundle a pointer to a resourceBundle struct. Can be NULL. jpayne@69: * @see ures_open jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ures_close(UResourceBundle* resourceBundle); jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: /** jpayne@69: * \class LocalUResourceBundlePointer jpayne@69: * "Smart pointer" class, closes a UResourceBundle via ures_close(). jpayne@69: * For most methods see the LocalPointerBase base class. jpayne@69: * jpayne@69: * @see LocalPointerBase jpayne@69: * @see LocalPointer jpayne@69: * @stable ICU 4.4 jpayne@69: */ jpayne@69: U_DEFINE_LOCAL_OPEN_POINTER(LocalUResourceBundlePointer, UResourceBundle, ures_close); jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif jpayne@69: jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * Return the version number associated with this ResourceBundle as a string. Please jpayne@69: * use ures_getVersion as this function is going to be deprecated. jpayne@69: * jpayne@69: * @param resourceBundle The resource bundle for which the version is checked. jpayne@69: * @return A version number string as specified in the resource bundle or its parent. jpayne@69: * The caller does not own this string. jpayne@69: * @see ures_getVersion jpayne@69: * @deprecated ICU 2.8 Use ures_getVersion instead. jpayne@69: */ jpayne@69: U_DEPRECATED const char* U_EXPORT2 jpayne@69: ures_getVersionNumber(const UResourceBundle* resourceBundle); jpayne@69: #endif /* U_HIDE_DEPRECATED_API */ jpayne@69: jpayne@69: /** jpayne@69: * Return the version number associated with this ResourceBundle as an jpayne@69: * UVersionInfo array. jpayne@69: * jpayne@69: * @param resB The resource bundle for which the version is checked. jpayne@69: * @param versionInfo A UVersionInfo array that is filled with the version number jpayne@69: * as specified in the resource bundle or its parent. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ures_getVersion(const UResourceBundle* resB, jpayne@69: UVersionInfo versionInfo); jpayne@69: jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * Return the name of the Locale associated with this ResourceBundle. This API allows jpayne@69: * you to query for the real locale of the resource. For example, if you requested jpayne@69: * "en_US_CALIFORNIA" and only "en_US" bundle exists, "en_US" will be returned. jpayne@69: * For subresources, the locale where this resource comes from will be returned. jpayne@69: * If fallback has occurred, getLocale will reflect this. jpayne@69: * jpayne@69: * @param resourceBundle resource bundle in question jpayne@69: * @param status just for catching illegal arguments jpayne@69: * @return A Locale name jpayne@69: * @deprecated ICU 2.8 Use ures_getLocaleByType instead. jpayne@69: */ jpayne@69: U_DEPRECATED const char* U_EXPORT2 jpayne@69: ures_getLocale(const UResourceBundle* resourceBundle, jpayne@69: UErrorCode* status); jpayne@69: #endif /* U_HIDE_DEPRECATED_API */ jpayne@69: jpayne@69: /** jpayne@69: * Return the name of the Locale associated with this ResourceBundle. jpayne@69: * You can choose between requested, valid and real locale. jpayne@69: * jpayne@69: * @param resourceBundle resource bundle in question jpayne@69: * @param type You can choose between requested, valid and actual jpayne@69: * locale. For description see the definition of jpayne@69: * ULocDataLocaleType in uloc.h jpayne@69: * @param status just for catching illegal arguments jpayne@69: * @return A Locale name jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: U_STABLE const char* U_EXPORT2 jpayne@69: ures_getLocaleByType(const UResourceBundle* resourceBundle, jpayne@69: ULocDataLocaleType type, jpayne@69: UErrorCode* status); jpayne@69: jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Same as ures_open() but uses the fill-in parameter instead of allocating a new bundle. jpayne@69: * jpayne@69: * TODO need to revisit usefulness of this function jpayne@69: * and usage model for fillIn parameters without knowing sizeof(UResourceBundle) jpayne@69: * @param r The existing UResourceBundle to fill in. If NULL then status will be jpayne@69: * set to U_ILLEGAL_ARGUMENT_ERROR. jpayne@69: * @param packageName The packageName and locale together point to an ICU udata object, jpayne@69: * as defined by udata_open( packageName, "res", locale, err) jpayne@69: * or equivalent. Typically, packageName will refer to a (.dat) file, or to jpayne@69: * a package registered with udata_setAppData(). Using a full file or directory jpayne@69: * pathname for packageName is deprecated. If NULL, ICU data will be used. jpayne@69: * @param localeID specifies the locale for which we want to open the resource jpayne@69: * @param status The error code. jpayne@69: * @internal jpayne@69: */ jpayne@69: U_INTERNAL void U_EXPORT2 jpayne@69: ures_openFillIn(UResourceBundle *r, jpayne@69: const char* packageName, jpayne@69: const char* localeID, jpayne@69: UErrorCode* status); jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: /** jpayne@69: * Returns a string from a string resource type jpayne@69: * jpayne@69: * @param resourceBundle a string resource jpayne@69: * @param len fills in the length of resulting string jpayne@69: * @param status fills in the outgoing error code jpayne@69: * could be U_MISSING_RESOURCE_ERROR if the key is not found jpayne@69: * Always check the value of status. Don't count on returning NULL. jpayne@69: * could be a non-failing error jpayne@69: * e.g.: U_USING_FALLBACK_WARNING,U_USING_DEFAULT_WARNING jpayne@69: * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file. jpayne@69: * @see ures_getBinary jpayne@69: * @see ures_getIntVector jpayne@69: * @see ures_getInt jpayne@69: * @see ures_getUInt jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE const UChar* U_EXPORT2 jpayne@69: ures_getString(const UResourceBundle* resourceBundle, jpayne@69: int32_t* len, jpayne@69: UErrorCode* status); jpayne@69: jpayne@69: /** jpayne@69: * Returns a UTF-8 string from a string resource. jpayne@69: * The UTF-8 string may be returnable directly as a pointer, or jpayne@69: * it may need to be copied, or transformed from UTF-16 using u_strToUTF8() jpayne@69: * or equivalent. jpayne@69: * jpayne@69: * If forceCopy==TRUE, then the string is always written to the dest buffer jpayne@69: * and dest is returned. jpayne@69: * jpayne@69: * If forceCopy==FALSE, then the string is returned as a pointer if possible, jpayne@69: * without needing a dest buffer (it can be NULL). If the string needs to be jpayne@69: * copied or transformed, then it may be placed into dest at an arbitrary offset. jpayne@69: * jpayne@69: * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and jpayne@69: * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual. jpayne@69: * jpayne@69: * If the string is transformed from UTF-16, then a conversion error may occur jpayne@69: * if an unpaired surrogate is encountered. If the function is successful, then jpayne@69: * the output UTF-8 string is always well-formed. jpayne@69: * jpayne@69: * @param resB Resource bundle. jpayne@69: * @param dest Destination buffer. Can be NULL only if capacity=*length==0. jpayne@69: * @param length Input: Capacity of destination buffer. jpayne@69: * Output: Actual length of the UTF-8 string, not counting the jpayne@69: * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR. jpayne@69: * Can be NULL, meaning capacity=0 and the string length is not jpayne@69: * returned to the caller. jpayne@69: * @param forceCopy If TRUE, then the output string will always be written to jpayne@69: * dest, with U_BUFFER_OVERFLOW_ERROR and jpayne@69: * U_STRING_NOT_TERMINATED_WARNING set if appropriate. jpayne@69: * If FALSE, then the dest buffer may or may not contain a jpayne@69: * copy of the string. dest may or may not be modified. jpayne@69: * If a copy needs to be written, then the UErrorCode parameter jpayne@69: * indicates overflow etc. as usual. jpayne@69: * @param status Pointer to a standard ICU error code. Its input value must jpayne@69: * pass the U_SUCCESS() test, or else the function returns jpayne@69: * immediately. Check for U_FAILURE() on output or use with jpayne@69: * function chaining. (See User Guide for details.) jpayne@69: * @return The pointer to the UTF-8 string. It may be dest, or at some offset jpayne@69: * from dest (only if !forceCopy), or in unrelated memory. jpayne@69: * Always NUL-terminated unless the string was written to dest and jpayne@69: * length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set). jpayne@69: * jpayne@69: * @see ures_getString jpayne@69: * @see u_strToUTF8 jpayne@69: * @stable ICU 3.6 jpayne@69: */ jpayne@69: U_STABLE const char * U_EXPORT2 jpayne@69: ures_getUTF8String(const UResourceBundle *resB, jpayne@69: char *dest, int32_t *length, jpayne@69: UBool forceCopy, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Returns a binary data from a binary resource. jpayne@69: * jpayne@69: * @param resourceBundle a string resource jpayne@69: * @param len fills in the length of resulting byte chunk jpayne@69: * @param status fills in the outgoing error code jpayne@69: * could be U_MISSING_RESOURCE_ERROR if the key is not found jpayne@69: * Always check the value of status. Don't count on returning NULL. jpayne@69: * could be a non-failing error jpayne@69: * e.g.: U_USING_FALLBACK_WARNING,U_USING_DEFAULT_WARNING jpayne@69: * @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file. jpayne@69: * @see ures_getString jpayne@69: * @see ures_getIntVector jpayne@69: * @see ures_getInt jpayne@69: * @see ures_getUInt jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE const uint8_t* U_EXPORT2 jpayne@69: ures_getBinary(const UResourceBundle* resourceBundle, jpayne@69: int32_t* len, jpayne@69: UErrorCode* status); jpayne@69: jpayne@69: /** jpayne@69: * Returns a 32 bit integer array from a resource. jpayne@69: * jpayne@69: * @param resourceBundle an int vector resource jpayne@69: * @param len fills in the length of resulting byte chunk jpayne@69: * @param status fills in the outgoing error code jpayne@69: * could be U_MISSING_RESOURCE_ERROR if the key is not found jpayne@69: * Always check the value of status. Don't count on returning NULL. jpayne@69: * could be a non-failing error jpayne@69: * e.g.: U_USING_FALLBACK_WARNING,U_USING_DEFAULT_WARNING jpayne@69: * @return a pointer to a chunk of integers which live in a memory mapped/DLL file. jpayne@69: * @see ures_getBinary jpayne@69: * @see ures_getString jpayne@69: * @see ures_getInt jpayne@69: * @see ures_getUInt jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE const int32_t* U_EXPORT2 jpayne@69: ures_getIntVector(const UResourceBundle* resourceBundle, jpayne@69: int32_t* len, jpayne@69: UErrorCode* status); jpayne@69: jpayne@69: /** jpayne@69: * Returns an unsigned integer from a resource. jpayne@69: * This integer is originally 28 bits. jpayne@69: * jpayne@69: * @param resourceBundle a string resource jpayne@69: * @param status fills in the outgoing error code jpayne@69: * could be U_MISSING_RESOURCE_ERROR if the key is not found jpayne@69: * could be a non-failing error jpayne@69: * e.g.: U_USING_FALLBACK_WARNING,U_USING_DEFAULT_WARNING jpayne@69: * @return an integer value jpayne@69: * @see ures_getInt jpayne@69: * @see ures_getIntVector jpayne@69: * @see ures_getBinary jpayne@69: * @see ures_getString jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE uint32_t U_EXPORT2 jpayne@69: ures_getUInt(const UResourceBundle* resourceBundle, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Returns a signed integer from a resource. jpayne@69: * This integer is originally 28 bit and the sign gets propagated. jpayne@69: * jpayne@69: * @param resourceBundle a string resource jpayne@69: * @param status fills in the outgoing error code jpayne@69: * could be U_MISSING_RESOURCE_ERROR if the key is not found jpayne@69: * could be a non-failing error jpayne@69: * e.g.: U_USING_FALLBACK_WARNING,U_USING_DEFAULT_WARNING jpayne@69: * @return an integer value jpayne@69: * @see ures_getUInt jpayne@69: * @see ures_getIntVector jpayne@69: * @see ures_getBinary jpayne@69: * @see ures_getString jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ures_getInt(const UResourceBundle* resourceBundle, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Returns the size of a resource. Size for scalar types is always 1, jpayne@69: * and for vector/table types is the number of child resources. jpayne@69: * @warning Integer array is treated as a scalar type. There are no jpayne@69: * APIs to access individual members of an integer array. It jpayne@69: * is always returned as a whole. jpayne@69: * @param resourceBundle a resource jpayne@69: * @return number of resources in a given resource. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ures_getSize(const UResourceBundle *resourceBundle); jpayne@69: jpayne@69: /** jpayne@69: * Returns the type of a resource. Available types are defined in enum UResType jpayne@69: * jpayne@69: * @param resourceBundle a resource jpayne@69: * @return type of the given resource. jpayne@69: * @see UResType jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UResType U_EXPORT2 jpayne@69: ures_getType(const UResourceBundle *resourceBundle); jpayne@69: jpayne@69: /** jpayne@69: * Returns the key associated with a given resource. Not all the resources have a key - only jpayne@69: * those that are members of a table. jpayne@69: * jpayne@69: * @param resourceBundle a resource jpayne@69: * @return a key associated to this resource, or NULL if it doesn't have a key jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE const char * U_EXPORT2 jpayne@69: ures_getKey(const UResourceBundle *resourceBundle); jpayne@69: jpayne@69: /* ITERATION API jpayne@69: This API provides means for iterating through a resource jpayne@69: */ jpayne@69: jpayne@69: /** jpayne@69: * Resets the internal context of a resource so that iteration starts from the first element. jpayne@69: * jpayne@69: * @param resourceBundle a resource jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ures_resetIterator(UResourceBundle *resourceBundle); jpayne@69: jpayne@69: /** jpayne@69: * Checks whether the given resource has another element to iterate over. jpayne@69: * jpayne@69: * @param resourceBundle a resource jpayne@69: * @return TRUE if there are more elements, FALSE if there is no more elements jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UBool U_EXPORT2 jpayne@69: ures_hasNext(const UResourceBundle *resourceBundle); jpayne@69: jpayne@69: /** jpayne@69: * Returns the next resource in a given resource or NULL if there are no more resources jpayne@69: * to iterate over. Features a fill-in parameter. jpayne@69: * jpayne@69: * @param resourceBundle a resource jpayne@69: * @param fillIn if NULL a new UResourceBundle struct is allocated and must be closed by the caller. jpayne@69: * Alternatively, you can supply a struct to be filled by this function. jpayne@69: * @param status fills in the outgoing error code. You may still get a non NULL result even if an jpayne@69: * error occurred. Check status instead. jpayne@69: * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UResourceBundle* U_EXPORT2 jpayne@69: ures_getNextResource(UResourceBundle *resourceBundle, jpayne@69: UResourceBundle *fillIn, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Returns the next string in a given resource or NULL if there are no more resources jpayne@69: * to iterate over. jpayne@69: * jpayne@69: * @param resourceBundle a resource jpayne@69: * @param len fill in length of the string jpayne@69: * @param key fill in for key associated with this string. NULL if no key jpayne@69: * @param status fills in the outgoing error code. If an error occurred, we may return NULL, but don't jpayne@69: * count on it. Check status instead! jpayne@69: * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE const UChar* U_EXPORT2 jpayne@69: ures_getNextString(UResourceBundle *resourceBundle, jpayne@69: int32_t* len, jpayne@69: const char ** key, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Returns the resource in a given resource at the specified index. Features a fill-in parameter. jpayne@69: * jpayne@69: * @param resourceBundle the resource bundle from which to get a sub-resource jpayne@69: * @param indexR an index to the wanted resource. jpayne@69: * @param fillIn if NULL a new UResourceBundle struct is allocated and must be closed by the caller. jpayne@69: * Alternatively, you can supply a struct to be filled by this function. jpayne@69: * @param status fills in the outgoing error code. Don't count on NULL being returned if an error has jpayne@69: * occurred. Check status instead. jpayne@69: * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UResourceBundle* U_EXPORT2 jpayne@69: ures_getByIndex(const UResourceBundle *resourceBundle, jpayne@69: int32_t indexR, jpayne@69: UResourceBundle *fillIn, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Returns the string in a given resource at the specified index. jpayne@69: * jpayne@69: * @param resourceBundle a resource jpayne@69: * @param indexS an index to the wanted string. jpayne@69: * @param len fill in length of the string jpayne@69: * @param status fills in the outgoing error code. If an error occurred, we may return NULL, but don't jpayne@69: * count on it. Check status instead! jpayne@69: * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE const UChar* U_EXPORT2 jpayne@69: ures_getStringByIndex(const UResourceBundle *resourceBundle, jpayne@69: int32_t indexS, jpayne@69: int32_t* len, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Returns a UTF-8 string from a resource at the specified index. jpayne@69: * The UTF-8 string may be returnable directly as a pointer, or jpayne@69: * it may need to be copied, or transformed from UTF-16 using u_strToUTF8() jpayne@69: * or equivalent. jpayne@69: * jpayne@69: * If forceCopy==TRUE, then the string is always written to the dest buffer jpayne@69: * and dest is returned. jpayne@69: * jpayne@69: * If forceCopy==FALSE, then the string is returned as a pointer if possible, jpayne@69: * without needing a dest buffer (it can be NULL). If the string needs to be jpayne@69: * copied or transformed, then it may be placed into dest at an arbitrary offset. jpayne@69: * jpayne@69: * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and jpayne@69: * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual. jpayne@69: * jpayne@69: * If the string is transformed from UTF-16, then a conversion error may occur jpayne@69: * if an unpaired surrogate is encountered. If the function is successful, then jpayne@69: * the output UTF-8 string is always well-formed. jpayne@69: * jpayne@69: * @param resB Resource bundle. jpayne@69: * @param stringIndex An index to the wanted string. jpayne@69: * @param dest Destination buffer. Can be NULL only if capacity=*length==0. jpayne@69: * @param pLength Input: Capacity of destination buffer. jpayne@69: * Output: Actual length of the UTF-8 string, not counting the jpayne@69: * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR. jpayne@69: * Can be NULL, meaning capacity=0 and the string length is not jpayne@69: * returned to the caller. jpayne@69: * @param forceCopy If TRUE, then the output string will always be written to jpayne@69: * dest, with U_BUFFER_OVERFLOW_ERROR and jpayne@69: * U_STRING_NOT_TERMINATED_WARNING set if appropriate. jpayne@69: * If FALSE, then the dest buffer may or may not contain a jpayne@69: * copy of the string. dest may or may not be modified. jpayne@69: * If a copy needs to be written, then the UErrorCode parameter jpayne@69: * indicates overflow etc. as usual. jpayne@69: * @param status Pointer to a standard ICU error code. Its input value must jpayne@69: * pass the U_SUCCESS() test, or else the function returns jpayne@69: * immediately. Check for U_FAILURE() on output or use with jpayne@69: * function chaining. (See User Guide for details.) jpayne@69: * @return The pointer to the UTF-8 string. It may be dest, or at some offset jpayne@69: * from dest (only if !forceCopy), or in unrelated memory. jpayne@69: * Always NUL-terminated unless the string was written to dest and jpayne@69: * length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set). jpayne@69: * jpayne@69: * @see ures_getStringByIndex jpayne@69: * @see u_strToUTF8 jpayne@69: * @stable ICU 3.6 jpayne@69: */ jpayne@69: U_STABLE const char * U_EXPORT2 jpayne@69: ures_getUTF8StringByIndex(const UResourceBundle *resB, jpayne@69: int32_t stringIndex, jpayne@69: char *dest, int32_t *pLength, jpayne@69: UBool forceCopy, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Returns a resource in a given resource that has a given key. This procedure works only with table jpayne@69: * resources. Features a fill-in parameter. jpayne@69: * jpayne@69: * @param resourceBundle a resource jpayne@69: * @param key a key associated with the wanted resource jpayne@69: * @param fillIn if NULL a new UResourceBundle struct is allocated and must be closed by the caller. jpayne@69: * Alternatively, you can supply a struct to be filled by this function. jpayne@69: * @param status fills in the outgoing error code. jpayne@69: * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UResourceBundle* U_EXPORT2 jpayne@69: ures_getByKey(const UResourceBundle *resourceBundle, jpayne@69: const char* key, jpayne@69: UResourceBundle *fillIn, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Returns a string in a given resource that has a given key. This procedure works only with table jpayne@69: * resources. jpayne@69: * jpayne@69: * @param resB a resource jpayne@69: * @param key a key associated with the wanted string jpayne@69: * @param len fill in length of the string jpayne@69: * @param status fills in the outgoing error code. If an error occurred, we may return NULL, but don't jpayne@69: * count on it. Check status instead! jpayne@69: * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE const UChar* U_EXPORT2 jpayne@69: ures_getStringByKey(const UResourceBundle *resB, jpayne@69: const char* key, jpayne@69: int32_t* len, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Returns a UTF-8 string from a resource and a key. jpayne@69: * This function works only with table resources. jpayne@69: * jpayne@69: * The UTF-8 string may be returnable directly as a pointer, or jpayne@69: * it may need to be copied, or transformed from UTF-16 using u_strToUTF8() jpayne@69: * or equivalent. jpayne@69: * jpayne@69: * If forceCopy==TRUE, then the string is always written to the dest buffer jpayne@69: * and dest is returned. jpayne@69: * jpayne@69: * If forceCopy==FALSE, then the string is returned as a pointer if possible, jpayne@69: * without needing a dest buffer (it can be NULL). If the string needs to be jpayne@69: * copied or transformed, then it may be placed into dest at an arbitrary offset. jpayne@69: * jpayne@69: * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and jpayne@69: * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual. jpayne@69: * jpayne@69: * If the string is transformed from UTF-16, then a conversion error may occur jpayne@69: * if an unpaired surrogate is encountered. If the function is successful, then jpayne@69: * the output UTF-8 string is always well-formed. jpayne@69: * jpayne@69: * @param resB Resource bundle. jpayne@69: * @param key A key associated with the wanted resource jpayne@69: * @param dest Destination buffer. Can be NULL only if capacity=*length==0. jpayne@69: * @param pLength Input: Capacity of destination buffer. jpayne@69: * Output: Actual length of the UTF-8 string, not counting the jpayne@69: * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR. jpayne@69: * Can be NULL, meaning capacity=0 and the string length is not jpayne@69: * returned to the caller. jpayne@69: * @param forceCopy If TRUE, then the output string will always be written to jpayne@69: * dest, with U_BUFFER_OVERFLOW_ERROR and jpayne@69: * U_STRING_NOT_TERMINATED_WARNING set if appropriate. jpayne@69: * If FALSE, then the dest buffer may or may not contain a jpayne@69: * copy of the string. dest may or may not be modified. jpayne@69: * If a copy needs to be written, then the UErrorCode parameter jpayne@69: * indicates overflow etc. as usual. jpayne@69: * @param status Pointer to a standard ICU error code. Its input value must jpayne@69: * pass the U_SUCCESS() test, or else the function returns jpayne@69: * immediately. Check for U_FAILURE() on output or use with jpayne@69: * function chaining. (See User Guide for details.) jpayne@69: * @return The pointer to the UTF-8 string. It may be dest, or at some offset jpayne@69: * from dest (only if !forceCopy), or in unrelated memory. jpayne@69: * Always NUL-terminated unless the string was written to dest and jpayne@69: * length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set). jpayne@69: * jpayne@69: * @see ures_getStringByKey jpayne@69: * @see u_strToUTF8 jpayne@69: * @stable ICU 3.6 jpayne@69: */ jpayne@69: U_STABLE const char * U_EXPORT2 jpayne@69: ures_getUTF8StringByKey(const UResourceBundle *resB, jpayne@69: const char *key, jpayne@69: char *dest, int32_t *pLength, jpayne@69: UBool forceCopy, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: #include "unicode/unistr.h" jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: /** jpayne@69: * Returns the string value from a string resource bundle. jpayne@69: * jpayne@69: * @param resB a resource, should have type URES_STRING jpayne@69: * @param status: fills in the outgoing error code jpayne@69: * could be U_MISSING_RESOURCE_ERROR if the key is not found jpayne@69: * could be a non-failing error jpayne@69: * e.g.: U_USING_FALLBACK_WARNING,U_USING_DEFAULT_WARNING jpayne@69: * @return The string value, or a bogus string if there is a failure UErrorCode. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: inline UnicodeString jpayne@69: ures_getUnicodeString(const UResourceBundle *resB, UErrorCode* status) { jpayne@69: UnicodeString result; jpayne@69: int32_t len = 0; jpayne@69: const UChar *r = ures_getString(resB, &len, status); jpayne@69: if(U_SUCCESS(*status)) { jpayne@69: result.setTo(TRUE, r, len); jpayne@69: } else { jpayne@69: result.setToBogus(); jpayne@69: } jpayne@69: return result; jpayne@69: } jpayne@69: jpayne@69: /** jpayne@69: * Returns the next string in a resource, or an empty string if there are no more resources jpayne@69: * to iterate over. jpayne@69: * Use ures_getNextString() instead to distinguish between jpayne@69: * the end of the iteration and a real empty string value. jpayne@69: * jpayne@69: * @param resB a resource jpayne@69: * @param key fill in for key associated with this string jpayne@69: * @param status fills in the outgoing error code jpayne@69: * @return The string value, or a bogus string if there is a failure UErrorCode. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: inline UnicodeString jpayne@69: ures_getNextUnicodeString(UResourceBundle *resB, const char ** key, UErrorCode* status) { jpayne@69: UnicodeString result; jpayne@69: int32_t len = 0; jpayne@69: const UChar* r = ures_getNextString(resB, &len, key, status); jpayne@69: if(U_SUCCESS(*status)) { jpayne@69: result.setTo(TRUE, r, len); jpayne@69: } else { jpayne@69: result.setToBogus(); jpayne@69: } jpayne@69: return result; jpayne@69: } jpayne@69: jpayne@69: /** jpayne@69: * Returns the string in a given resource array or table at the specified index. jpayne@69: * jpayne@69: * @param resB a resource jpayne@69: * @param indexS an index to the wanted string. jpayne@69: * @param status fills in the outgoing error code jpayne@69: * @return The string value, or a bogus string if there is a failure UErrorCode. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: inline UnicodeString jpayne@69: ures_getUnicodeStringByIndex(const UResourceBundle *resB, int32_t indexS, UErrorCode* status) { jpayne@69: UnicodeString result; jpayne@69: int32_t len = 0; jpayne@69: const UChar* r = ures_getStringByIndex(resB, indexS, &len, status); jpayne@69: if(U_SUCCESS(*status)) { jpayne@69: result.setTo(TRUE, r, len); jpayne@69: } else { jpayne@69: result.setToBogus(); jpayne@69: } jpayne@69: return result; jpayne@69: } jpayne@69: jpayne@69: /** jpayne@69: * Returns a string in a resource that has a given key. jpayne@69: * This procedure works only with table resources. jpayne@69: * jpayne@69: * @param resB a resource jpayne@69: * @param key a key associated with the wanted string jpayne@69: * @param status fills in the outgoing error code jpayne@69: * @return The string value, or a bogus string if there is a failure UErrorCode. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: inline UnicodeString jpayne@69: ures_getUnicodeStringByKey(const UResourceBundle *resB, const char* key, UErrorCode* status) { jpayne@69: UnicodeString result; jpayne@69: int32_t len = 0; jpayne@69: const UChar* r = ures_getStringByKey(resB, key, &len, status); jpayne@69: if(U_SUCCESS(*status)) { jpayne@69: result.setTo(TRUE, r, len); jpayne@69: } else { jpayne@69: result.setToBogus(); jpayne@69: } jpayne@69: return result; jpayne@69: } jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif jpayne@69: jpayne@69: /** jpayne@69: * Create a string enumerator, owned by the caller, of all locales located within jpayne@69: * the specified resource tree. jpayne@69: * @param packageName name of the tree, such as (NULL) or U_ICUDATA_ALIAS or or "ICUDATA-coll" jpayne@69: * This call is similar to uloc_getAvailable(). jpayne@69: * @param status error code jpayne@69: * @stable ICU 3.2 jpayne@69: */ jpayne@69: U_STABLE UEnumeration* U_EXPORT2 jpayne@69: ures_openAvailableLocales(const char *packageName, UErrorCode *status); jpayne@69: jpayne@69: jpayne@69: #endif /*_URES*/ jpayne@69: /*eof*/