/*
**********************************************************************
-* Copyright (C) 1997-2004, International Business Machines
+* Copyright (C) 1997-2012,2014, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*
#include "unicode/utypes.h"
#include "unicode/uloc.h"
+#include "unicode/localpointer.h"
/**
* \file
* locale and then ask it for individual resources.
* <P>
* Resource bundles in ICU4C are currently defined using text files which conform to the following
- * <a href="http://oss.software.ibm.com/cvs/icu/~checkout~/icuhtml/design/bnf_rb.txt">BNF definition</a>.
+ * <a href="http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt">BNF definition</a>.
* More on resource bundle concepts and syntax can be found in the
- * <a href="http://oss.software.ibm.com/icu/userguide/ResourceManagement.html">Users Guide</a>.
+ * <a href="http://icu-project.org/userguide/ResourceManagement.html">Users Guide</a>.
* <P>
*/
*/
URES_ALIAS=3,
- /**
- * Internal use only.
- * Alternative resource type constant for tables of key-value pairs.
- * Never returned by ures_getType().
- * @internal
- */
- URES_TABLE32=4,
-
/**
* Resource type constant for a single 28-bit integer, interpreted as
* signed or unsigned by the ures_getInt() or ures_getUInt() function.
* @see ures_getIntVector
* @stable ICU 2.6
*/
- URES_INT_VECTOR=14,
-
+ URES_INT_VECTOR = 14,
#ifndef U_HIDE_DEPRECATED_API
/** @deprecated ICU 2.6 Use the URES_ constant instead. */
RES_NONE=URES_NONE,
RES_ARRAY=URES_ARRAY,
/** @deprecated ICU 2.6 Use the URES_ constant instead. */
RES_INT_VECTOR=URES_INT_VECTOR,
+ /** @deprecated ICU 2.6 Not used. */
+ RES_RESERVED=15,
#endif /* U_HIDE_DEPRECATED_API */
- /** @deprecated ICU 2.6 Not used. */
- RES_RESERVED=15
+ URES_LIMIT = 16
} UResType;
/*
* their corresponding keys.
* Note that the caller is responsible of calling <TT>ures_close</TT> on each succesfully
* opened resource bundle.
- * @param path string containing the full path pointing to the directory
- * where the resources reside followed by the package name
- * e.g. "/usr/resource/my_app/resources/guimessages" on a Unix system.
- * if NULL, ICU default data files will be used.
+ * @param packageName The packageName and locale together point to an ICU udata object,
+ * as defined by <code> udata_open( packageName, "res", locale, err) </code>
+ * or equivalent. Typically, packageName will refer to a (.dat) file, or to
+ * a package registered with udata_setAppData(). Using a full file or directory
+ * pathname for packageName is deprecated. If NULL, ICU data will be used.
* @param locale specifies the locale for which we want to open the resource
* if NULL, the default locale will be used. If strlen(locale) == 0
* root locale will be used.
* @stable ICU 2.0
*/
U_STABLE UResourceBundle* U_EXPORT2
-ures_open(const char* path,
+ures_open(const char* packageName,
const char* locale,
UErrorCode* status);
/** This function does not care what kind of localeID is passed in. It simply opens a bundle with
* that name. Fallback mechanism is disabled for the new bundle. If the requested bundle contains
* an %%ALIAS directive, the results are undefined.
- * @param path string containing the full path pointing to the directory
- * where the resources reside followed by the package name
- * e.g. "/usr/resource/my_app/resources/guimessages" on a Unix system.
- * if NULL, ICU default data files will be used.
+ * @param packageName The packageName and locale together point to an ICU udata object,
+ * as defined by <code> udata_open( packageName, "res", locale, err) </code>
+ * or equivalent. Typically, packageName will refer to a (.dat) file, or to
+ * a package registered with udata_setAppData(). Using a full file or directory
+ * pathname for packageName is deprecated. If NULL, ICU data will be used.
* @param locale specifies the locale for which we want to open the resource
* if NULL, the default locale will be used. If strlen(locale) == 0
* root locale will be used.
* @stable ICU 2.0
*/
U_STABLE UResourceBundle* U_EXPORT2
-ures_openDirect(const char* path,
+ures_openDirect(const char* packageName,
const char* locale,
UErrorCode* status);
* This path will be converted to char * using the default converter,
* then ures_open() is called.
*
- * @param path string containing the full path pointing to the directory
- * where the resources reside followed by the package name
+ * @param packageName The packageName and locale together point to an ICU udata object,
+ * as defined by <code> udata_open( packageName, "res", locale, err) </code>
+ * or equivalent. Typically, packageName will refer to a (.dat) file, or to
+ * a package registered with udata_setAppData(). Using a full file or directory
+ * pathname for packageName is deprecated. If NULL, ICU data will be used.
* @param locale specifies the locale for which we want to open the resource
* if NULL, the default locale will be used. If strlen(locale) == 0
* root locale will be used.
* @stable ICU 2.0
*/
U_STABLE UResourceBundle* U_EXPORT2
-ures_openU(const UChar* path,
+ures_openU(const UChar* packageName,
const char* locale,
UErrorCode* status);
+#ifndef U_HIDE_DEPRECATED_API
/**
* Returns the number of strings/arrays in resource bundles.
* Better to use ures_getSize, as this function will be deprecated.
ures_countArrayItems(const UResourceBundle* resourceBundle,
const char* resourceKey,
UErrorCode* err);
+#endif /* U_HIDE_DEPRECATED_API */
+
/**
* Close a resource bundle, all pointers returned from the various ures_getXXX calls
* on this particular bundle should be considered invalid henceforth.
U_STABLE void U_EXPORT2
ures_close(UResourceBundle* resourceBundle);
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUResourceBundlePointer
+ * "Smart pointer" class, closes a UResourceBundle via ures_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 4.4
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUResourceBundlePointer, UResourceBundle, ures_close);
+
+U_NAMESPACE_END
+
+#endif
+
+#ifndef U_HIDE_DEPRECATED_API
/**
* Return the version number associated with this ResourceBundle as a string. Please
* use ures_getVersion as this function is going to be deprecated.
*/
U_DEPRECATED const char* U_EXPORT2
ures_getVersionNumber(const UResourceBundle* resourceBundle);
+#endif /* U_HIDE_DEPRECATED_API */
/**
* Return the version number associated with this ResourceBundle as an
ures_getVersion(const UResourceBundle* resB,
UVersionInfo versionInfo);
+#ifndef U_HIDE_DEPRECATED_API
/**
* Return the name of the Locale associated with this ResourceBundle. This API allows
* you to query for the real locale of the resource. For example, if you requested
U_DEPRECATED const char* U_EXPORT2
ures_getLocale(const UResourceBundle* resourceBundle,
UErrorCode* status);
-
+#endif /* U_HIDE_DEPRECATED_API */
/**
* Return the name of the Locale associated with this ResourceBundle.
* ULocDataLocaleType in uloc.h
* @param status just for catching illegal arguments
* @return A Locale name
- * @draft ICU 2.8
+ * @stable ICU 2.8
*/
-U_DRAFT const char* U_EXPORT2
+U_STABLE const char* U_EXPORT2
ures_getLocaleByType(const UResourceBundle* resourceBundle,
ULocDataLocaleType type,
UErrorCode* status);
+#ifndef U_HIDE_INTERNAL_API
/**
* Same as ures_open() but uses the fill-in parameter instead of allocating
* a bundle, if r!=NULL.
* TODO need to revisit usefulness of this function
* and usage model for fillIn parameters without knowing sizeof(UResourceBundle)
* @param r The resourcebundle to open
- * @param path String containing the full path pointing to the directory
- * where the resources reside followed by the package name
+ * @param packageName The packageName and locale together point to an ICU udata object,
+ * as defined by <code> udata_open( packageName, "res", locale, err) </code>
+ * or equivalent. Typically, packageName will refer to a (.dat) file, or to
+ * a package registered with udata_setAppData(). Using a full file or directory
+ * pathname for packageName is deprecated. If NULL, ICU data will be used.
* @param localeID specifies the locale for which we want to open the resource
* @param status The error code
* @return a newly allocated resource bundle or NULL if it doesn't exist.
*/
U_INTERNAL void U_EXPORT2
ures_openFillIn(UResourceBundle *r,
- const char* path,
+ const char* packageName,
const char* localeID,
UErrorCode* status);
+#endif /* U_HIDE_INTERNAL_API */
/**
* Returns a string from a string resource type
int32_t* len,
UErrorCode* status);
+/**
+ * Returns a UTF-8 string from a string resource.
+ * The UTF-8 string may be returnable directly as a pointer, or
+ * it may need to be copied, or transformed from UTF-16 using u_strToUTF8()
+ * or equivalent.
+ *
+ * If forceCopy==TRUE, then the string is always written to the dest buffer
+ * and dest is returned.
+ *
+ * If forceCopy==FALSE, then the string is returned as a pointer if possible,
+ * without needing a dest buffer (it can be NULL). If the string needs to be
+ * copied or transformed, then it may be placed into dest at an arbitrary offset.
+ *
+ * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and
+ * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual.
+ *
+ * If the string is transformed from UTF-16, then a conversion error may occur
+ * if an unpaired surrogate is encountered. If the function is successful, then
+ * the output UTF-8 string is always well-formed.
+ *
+ * @param resB Resource bundle.
+ * @param dest Destination buffer. Can be NULL only if capacity=*length==0.
+ * @param length Input: Capacity of destination buffer.
+ * Output: Actual length of the UTF-8 string, not counting the
+ * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR.
+ * Can be NULL, meaning capacity=0 and the string length is not
+ * returned to the caller.
+ * @param forceCopy If TRUE, then the output string will always be written to
+ * dest, with U_BUFFER_OVERFLOW_ERROR and
+ * U_STRING_NOT_TERMINATED_WARNING set if appropriate.
+ * If FALSE, then the dest buffer may or may not contain a
+ * copy of the string. dest may or may not be modified.
+ * If a copy needs to be written, then the UErrorCode parameter
+ * indicates overflow etc. as usual.
+ * @param status Pointer to a standard ICU error code. Its input value must
+ * pass the U_SUCCESS() test, or else the function returns
+ * immediately. Check for U_FAILURE() on output or use with
+ * function chaining. (See User Guide for details.)
+ * @return The pointer to the UTF-8 string. It may be dest, or at some offset
+ * from dest (only if !forceCopy), or in unrelated memory.
+ * Always NUL-terminated unless the string was written to dest and
+ * length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set).
+ *
+ * @see ures_getString
+ * @see u_strToUTF8
+ * @stable ICU 3.6
+ */
+U_STABLE const char * U_EXPORT2
+ures_getUTF8String(const UResourceBundle *resB,
+ char *dest, int32_t *length,
+ UBool forceCopy,
+ UErrorCode *status);
+
/**
* Returns a binary data from a binary resource.
*
* Always check the value of status. Don't count on returning NULL.
* could be a non-failing error
* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
- * @return a pointer to a chuck of unsigned bytes which live in a memory mapped/DLL file.
+ * @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.
* @see ures_getString
* @see ures_getIntVector
* @see ures_getInt
* Always check the value of status. Don't count on returning NULL.
* could be a non-failing error
* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
- * @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.
+ * @return a pointer to a chunk of integers which live in a memory mapped/DLL file.
* @see ures_getBinary
* @see ures_getString
* @see ures_getInt
* to iterate over. Features a fill-in parameter.
*
* @param resourceBundle a resource
- * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
+ * @param fillIn if NULL a new UResourceBundle struct is allocated and must be closed by the caller.
* Alternatively, you can supply a struct to be filled by this function.
* @param status fills in the outgoing error code. You may still get a non NULL result even if an
* error occured. Check status instead.
- * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
+ * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it
* @stable ICU 2.0
*/
U_STABLE UResourceBundle* U_EXPORT2
*
* @param resourceBundle the resource bundle from which to get a sub-resource
* @param indexR an index to the wanted resource.
- * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
+ * @param fillIn if NULL a new UResourceBundle struct is allocated and must be closed by the caller.
* Alternatively, you can supply a struct to be filled by this function.
* @param status fills in the outgoing error code. Don't count on NULL being returned if an error has
* occured. Check status instead.
- * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
+ * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it
* @stable ICU 2.0
*/
U_STABLE UResourceBundle* U_EXPORT2
int32_t* len,
UErrorCode *status);
+/**
+ * Returns a UTF-8 string from a resource at the specified index.
+ * The UTF-8 string may be returnable directly as a pointer, or
+ * it may need to be copied, or transformed from UTF-16 using u_strToUTF8()
+ * or equivalent.
+ *
+ * If forceCopy==TRUE, then the string is always written to the dest buffer
+ * and dest is returned.
+ *
+ * If forceCopy==FALSE, then the string is returned as a pointer if possible,
+ * without needing a dest buffer (it can be NULL). If the string needs to be
+ * copied or transformed, then it may be placed into dest at an arbitrary offset.
+ *
+ * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and
+ * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual.
+ *
+ * If the string is transformed from UTF-16, then a conversion error may occur
+ * if an unpaired surrogate is encountered. If the function is successful, then
+ * the output UTF-8 string is always well-formed.
+ *
+ * @param resB Resource bundle.
+ * @param stringIndex An index to the wanted string.
+ * @param dest Destination buffer. Can be NULL only if capacity=*length==0.
+ * @param pLength Input: Capacity of destination buffer.
+ * Output: Actual length of the UTF-8 string, not counting the
+ * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR.
+ * Can be NULL, meaning capacity=0 and the string length is not
+ * returned to the caller.
+ * @param forceCopy If TRUE, then the output string will always be written to
+ * dest, with U_BUFFER_OVERFLOW_ERROR and
+ * U_STRING_NOT_TERMINATED_WARNING set if appropriate.
+ * If FALSE, then the dest buffer may or may not contain a
+ * copy of the string. dest may or may not be modified.
+ * If a copy needs to be written, then the UErrorCode parameter
+ * indicates overflow etc. as usual.
+ * @param status Pointer to a standard ICU error code. Its input value must
+ * pass the U_SUCCESS() test, or else the function returns
+ * immediately. Check for U_FAILURE() on output or use with
+ * function chaining. (See User Guide for details.)
+ * @return The pointer to the UTF-8 string. It may be dest, or at some offset
+ * from dest (only if !forceCopy), or in unrelated memory.
+ * Always NUL-terminated unless the string was written to dest and
+ * length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set).
+ *
+ * @see ures_getStringByIndex
+ * @see u_strToUTF8
+ * @stable ICU 3.6
+ */
+U_STABLE const char * U_EXPORT2
+ures_getUTF8StringByIndex(const UResourceBundle *resB,
+ int32_t stringIndex,
+ char *dest, int32_t *pLength,
+ UBool forceCopy,
+ UErrorCode *status);
+
/**
* Returns a resource in a given resource that has a given key. This procedure works only with table
* resources. Features a fill-in parameter.
*
* @param resourceBundle a resource
* @param key a key associated with the wanted resource
- * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
+ * @param fillIn if NULL a new UResourceBundle struct is allocated and must be closed by the caller.
* Alternatively, you can supply a struct to be filled by this function.
* @param status fills in the outgoing error code.
- * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
+ * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it
* @stable ICU 2.0
*/
U_STABLE UResourceBundle* U_EXPORT2
int32_t* len,
UErrorCode *status);
-#ifdef XP_CPLUSPLUS
+/**
+ * Returns a UTF-8 string from a resource and a key.
+ * This function works only with table resources.
+ *
+ * The UTF-8 string may be returnable directly as a pointer, or
+ * it may need to be copied, or transformed from UTF-16 using u_strToUTF8()
+ * or equivalent.
+ *
+ * If forceCopy==TRUE, then the string is always written to the dest buffer
+ * and dest is returned.
+ *
+ * If forceCopy==FALSE, then the string is returned as a pointer if possible,
+ * without needing a dest buffer (it can be NULL). If the string needs to be
+ * copied or transformed, then it may be placed into dest at an arbitrary offset.
+ *
+ * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and
+ * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual.
+ *
+ * If the string is transformed from UTF-16, then a conversion error may occur
+ * if an unpaired surrogate is encountered. If the function is successful, then
+ * the output UTF-8 string is always well-formed.
+ *
+ * @param resB Resource bundle.
+ * @param key A key associated with the wanted resource
+ * @param dest Destination buffer. Can be NULL only if capacity=*length==0.
+ * @param pLength Input: Capacity of destination buffer.
+ * Output: Actual length of the UTF-8 string, not counting the
+ * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR.
+ * Can be NULL, meaning capacity=0 and the string length is not
+ * returned to the caller.
+ * @param forceCopy If TRUE, then the output string will always be written to
+ * dest, with U_BUFFER_OVERFLOW_ERROR and
+ * U_STRING_NOT_TERMINATED_WARNING set if appropriate.
+ * If FALSE, then the dest buffer may or may not contain a
+ * copy of the string. dest may or may not be modified.
+ * If a copy needs to be written, then the UErrorCode parameter
+ * indicates overflow etc. as usual.
+ * @param status Pointer to a standard ICU error code. Its input value must
+ * pass the U_SUCCESS() test, or else the function returns
+ * immediately. Check for U_FAILURE() on output or use with
+ * function chaining. (See User Guide for details.)
+ * @return The pointer to the UTF-8 string. It may be dest, or at some offset
+ * from dest (only if !forceCopy), or in unrelated memory.
+ * Always NUL-terminated unless the string was written to dest and
+ * length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set).
+ *
+ * @see ures_getStringByKey
+ * @see u_strToUTF8
+ * @stable ICU 3.6
+ */
+U_STABLE const char * U_EXPORT2
+ures_getUTF8StringByKey(const UResourceBundle *resB,
+ const char *key,
+ char *dest, int32_t *pLength,
+ UBool forceCopy,
+ UErrorCode *status);
+
+#if U_SHOW_CPLUSPLUS_API
#include "unicode/unistr.h"
U_NAMESPACE_BEGIN
/**
* returns a string from a string resource type
*
- * @param resB a resource
+ * @param resB a resource
* @param status: fills in the outgoing error code
* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
* could be a non-failing error
* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
- * @return an UnicodeString object. If there is an error, string is bogus
+ * @return a UnicodeString object. If there is an error, string is bogus
* @stable ICU 2.0
*/
inline UnicodeString
* Returns the string in a given resource at the specified index.
*
* @param resB a resource
- * @param index an index to the wanted string.
+ * @param indexS an index to the wanted string.
* @param status fills in the outgoing error code
* @return an UnicodeString object. If there is an error, string is bogus
* @stable ICU 2.0
#endif
-
-/**
- * Get a resource with multi-level fallback. Normally only the top level resources will
- * fallback to its parent. This performs fallback on subresources. For example, when a table
- * is defined in a resource bundle and a parent resource bundle, normally no fallback occurs
- * on the sub-resources because the table is defined in the current resource bundle, but this
- * function can perform fallback on the sub-resources of the table.
- * @param resB a resource
- * @param inKey a key associated with the requested resource
- * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
- * Alternatively, you can supply a struct to be filled by this function.
- * @param status: fills in the outgoing error code
- * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
- * could be a non-failing error
- * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
- * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
- * @internal ICU 3.0
- */
-U_INTERNAL UResourceBundle* U_EXPORT2
-ures_getByKeyWithFallback(const UResourceBundle *resB,
- const char* inKey,
- UResourceBundle *fillIn,
- UErrorCode *status);
-
-
/**
* Create a string enumerator, owned by the caller, of all locales located within
* the specified resource tree.
- * @param path path to the tree, such as (NULL) or U_ICUDATA_ALIAS or or "ICUDATA-coll"
+ * @param packageName name of the tree, such as (NULL) or U_ICUDATA_ALIAS or or "ICUDATA-coll"
* This call is similar to uloc_getAvailable().
* @param status error code
- * @draft ICU 3.2
+ * @stable ICU 3.2
*/
-U_DRAFT UEnumeration* U_EXPORT2
-ures_openAvailableLocales(const char *path, UErrorCode *status);
+U_STABLE UEnumeration* U_EXPORT2
+ures_openAvailableLocales(const char *packageName, UErrorCode *status);
#endif /*_URES*/