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

C API: Resource Bundle

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

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

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