Update contrib.
2 **********************************************************************
3 * Copyright (C) 1997-2005, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
7 * File URES.H (formerly CRESBUND.H)
9 * Modification History:
11 * Date Name Description
12 * 04/01/97 aliu Creation.
13 * 02/22/99 damiba overhaul.
14 * 04/04/99 helena Fixed internal header inclusion.
15 * 04/15/99 Madhu Updated Javadoc
16 * 06/14/99 stephen Removed functions taking a filename suffix.
17 * 07/20/99 stephen Language-independent ypedef to void*
18 * 11/09/99 weiv Added ures_getLocale()
19 * 06/24/02 weiv Added support for resource sharing
20 ******************************************************************************
26 #include "unicode/utypes.h"
27 #include "unicode/uloc.h"
31 * \brief C API: Resource Bundle
33 * <h2>C API: Resource Bundle</h2>
35 * C API representing a collection of resource information pertaining to a given
36 * locale. A resource bundle provides a way of accessing locale- specific information in
37 * a data file. You create a resource bundle that manages the resources for a given
38 * locale and then ask it for individual resources.
40 * Resource bundles in ICU4C are currently defined using text files which conform to the following
41 * <a href="http://dev.icu-project.org/cgi-bin/viewcvs.cgi/~checkout~/icuhtml/design/bnf_rb.txt">BNF definition</a>.
42 * More on resource bundle concepts and syntax can be found in the
43 * <a href="http://icu.sourceforge.net/userguide/ResourceManagement.html">Users Guide</a>.
48 * UResourceBundle is an opaque type for handles for resource bundles in C APIs.
51 struct UResourceBundle;
56 typedef struct UResourceBundle UResourceBundle;
59 * Numeric constants for types of resource items.
64 /** Resource type constant for "no resource". @stable ICU 2.6 */
67 /** Resource type constant for 16-bit Unicode strings. @stable ICU 2.6 */
70 /** Resource type constant for binary data. @stable ICU 2.6 */
73 /** Resource type constant for tables of key-value pairs. @stable ICU 2.6 */
77 * Resource type constant for aliases;
78 * internally stores a string which identifies the actual resource
79 * storing the data (can be in a different resource bundle).
80 * Resolved internally before delivering the actual resource through the API.
87 * Alternative resource type constant for tables of key-value pairs.
88 * Never returned by ures_getType().
94 * Resource type constant for a single 28-bit integer, interpreted as
95 * signed or unsigned by the ures_getInt() or ures_getUInt() function.
102 /** Resource type constant for arrays of resources. @stable ICU 2.6 */
106 * Resource type constant for vectors of 32-bit integers.
107 * @see ures_getIntVector
112 #ifndef U_HIDE_DEPRECATED_API
113 /** @deprecated ICU 2.6 Use the URES_ constant instead. */
115 /** @deprecated ICU 2.6 Use the URES_ constant instead. */
116 RES_STRING=URES_STRING,
117 /** @deprecated ICU 2.6 Use the URES_ constant instead. */
118 RES_BINARY=URES_BINARY,
119 /** @deprecated ICU 2.6 Use the URES_ constant instead. */
120 RES_TABLE=URES_TABLE,
121 /** @deprecated ICU 2.6 Use the URES_ constant instead. */
122 RES_ALIAS=URES_ALIAS,
123 /** @deprecated ICU 2.6 Use the URES_ constant instead. */
125 /** @deprecated ICU 2.6 Use the URES_ constant instead. */
126 RES_ARRAY=URES_ARRAY,
127 /** @deprecated ICU 2.6 Use the URES_ constant instead. */
128 RES_INT_VECTOR=URES_INT_VECTOR,
129 #endif /* U_HIDE_DEPRECATED_API */
131 /** @deprecated ICU 2.6 Not used. */
136 * Functions to create and destroy resource bundles.
140 * Opens a UResourceBundle, from which users can extract strings by using
141 * their corresponding keys.
142 * Note that the caller is responsible of calling <TT>ures_close</TT> on each succesfully
143 * opened resource bundle.
144 * @param packageName The packageName and locale together point to an ICU udata object,
145 * as defined by <code> udata_open( packageName, "res", locale, err) </code>
146 * or equivalent. Typically, packageName will refer to a (.dat) file, or to
147 * a package registered with udata_setAppData(). Using a full file or directory
148 * pathname for packageName is deprecated. If NULL, ICU data will be used.
149 * @param locale specifies the locale for which we want to open the resource
150 * if NULL, the default locale will be used. If strlen(locale) == 0
151 * root locale will be used.
153 * @param status fills in the outgoing error code.
154 * The UErrorCode err parameter is used to return status information to the user. To
155 * check whether the construction succeeded or not, you should check the value of
156 * U_SUCCESS(err). If you wish more detailed information, you can check for
157 * informational status results which still indicate success. U_USING_FALLBACK_WARNING
158 * indicates that a fall back locale was used. For example, 'de_CH' was requested,
159 * but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that
160 * the default locale data or root locale data was used; neither the requested locale
161 * nor any of its fall back locales could be found. Please see the users guide for more
162 * information on this topic.
163 * @return a newly allocated resource bundle.
167 U_STABLE UResourceBundle* U_EXPORT2
168 ures_open(const char* packageName,
173 /** This function does not care what kind of localeID is passed in. It simply opens a bundle with
174 * that name. Fallback mechanism is disabled for the new bundle. If the requested bundle contains
175 * an %%ALIAS directive, the results are undefined.
176 * @param packageName The packageName and locale together point to an ICU udata object,
177 * as defined by <code> udata_open( packageName, "res", locale, err) </code>
178 * or equivalent. Typically, packageName will refer to a (.dat) file, or to
179 * a package registered with udata_setAppData(). Using a full file or directory
180 * pathname for packageName is deprecated. If NULL, ICU data will be used.
181 * @param locale specifies the locale for which we want to open the resource
182 * if NULL, the default locale will be used. If strlen(locale) == 0
183 * root locale will be used.
185 * @param status fills in the outgoing error code. Either U_ZERO_ERROR or U_MISSING_RESOURCE_ERROR
186 * @return a newly allocated resource bundle or NULL if it doesn't exist.
190 U_STABLE UResourceBundle* U_EXPORT2
191 ures_openDirect(const char* packageName,
196 * Same as ures_open() but takes a const UChar *path.
197 * This path will be converted to char * using the default converter,
198 * then ures_open() is called.
200 * @param packageName The packageName and locale together point to an ICU udata object,
201 * as defined by <code> udata_open( packageName, "res", locale, err) </code>
202 * or equivalent. Typically, packageName will refer to a (.dat) file, or to
203 * a package registered with udata_setAppData(). Using a full file or directory
204 * pathname for packageName is deprecated. If NULL, ICU data will be used.
205 * @param locale specifies the locale for which we want to open the resource
206 * if NULL, the default locale will be used. If strlen(locale) == 0
207 * root locale will be used.
208 * @param status fills in the outgoing error code.
209 * @return a newly allocated resource bundle.
213 U_STABLE UResourceBundle* U_EXPORT2
214 ures_openU(const UChar* packageName,
219 * Returns the number of strings/arrays in resource bundles.
220 * Better to use ures_getSize, as this function will be deprecated.
222 *@param resourceBundle resource bundle containing the desired strings
223 *@param resourceKey key tagging the resource
224 *@param err fills in the outgoing error code
225 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
226 * could be a non-failing error
227 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_FALLBACK_WARNING </TT>
228 *@return: for <STRONG>Arrays</STRONG>: returns the number of resources in the array
229 * <STRONG>Tables</STRONG>: returns the number of resources in the table
230 * <STRONG>single string</STRONG>: returns 1
232 * @deprecated ICU 2.8 User ures_getSize instead
234 U_DEPRECATED int32_t U_EXPORT2
235 ures_countArrayItems(const UResourceBundle* resourceBundle,
236 const char* resourceKey,
239 * Close a resource bundle, all pointers returned from the various ures_getXXX calls
240 * on this particular bundle should be considered invalid henceforth.
242 * @param resourceBundle a pointer to a resourceBundle struct. Can be NULL.
246 U_STABLE void U_EXPORT2
247 ures_close(UResourceBundle* resourceBundle);
250 * Return the version number associated with this ResourceBundle as a string. Please
251 * use ures_getVersion as this function is going to be deprecated.
253 * @param resourceBundle The resource bundle for which the version is checked.
254 * @return A version number string as specified in the resource bundle or its parent.
255 * The caller does not own this string.
256 * @see ures_getVersion
257 * @deprecated ICU 2.8 Use ures_getVersion instead.
259 U_DEPRECATED const char* U_EXPORT2
260 ures_getVersionNumber(const UResourceBundle* resourceBundle);
263 * Return the version number associated with this ResourceBundle as an
264 * UVersionInfo array.
266 * @param resB The resource bundle for which the version is checked.
267 * @param versionInfo A UVersionInfo array that is filled with the version number
268 * as specified in the resource bundle or its parent.
271 U_STABLE void U_EXPORT2
272 ures_getVersion(const UResourceBundle* resB,
273 UVersionInfo versionInfo);
276 * Return the name of the Locale associated with this ResourceBundle. This API allows
277 * you to query for the real locale of the resource. For example, if you requested
278 * "en_US_CALIFORNIA" and only "en_US" bundle exists, "en_US" will be returned.
279 * For subresources, the locale where this resource comes from will be returned.
280 * If fallback has occured, getLocale will reflect this.
282 * @param resourceBundle resource bundle in question
283 * @param status just for catching illegal arguments
284 * @return A Locale name
285 * @deprecated ICU 2.8 Use ures_getLocaleByType instead.
287 U_DEPRECATED const char* U_EXPORT2
288 ures_getLocale(const UResourceBundle* resourceBundle,
293 * Return the name of the Locale associated with this ResourceBundle.
294 * You can choose between requested, valid and real locale.
296 * @param resourceBundle resource bundle in question
297 * @param type You can choose between requested, valid and actual
298 * locale. For description see the definition of
299 * ULocDataLocaleType in uloc.h
300 * @param status just for catching illegal arguments
301 * @return A Locale name
302 * @draft ICU 2.8 likely to change in the future
304 U_DRAFT const char* U_EXPORT2
305 ures_getLocaleByType(const UResourceBundle* resourceBundle,
306 ULocDataLocaleType type,
311 * Same as ures_open() but uses the fill-in parameter instead of allocating
312 * a bundle, if r!=NULL.
313 * TODO need to revisit usefulness of this function
314 * and usage model for fillIn parameters without knowing sizeof(UResourceBundle)
315 * @param r The resourcebundle to open
316 * @param packageName The packageName and locale together point to an ICU udata object,
317 * as defined by <code> udata_open( packageName, "res", locale, err) </code>
318 * or equivalent. Typically, packageName will refer to a (.dat) file, or to
319 * a package registered with udata_setAppData(). Using a full file or directory
320 * pathname for packageName is deprecated. If NULL, ICU data will be used.
321 * @param localeID specifies the locale for which we want to open the resource
322 * @param status The error code
323 * @return a newly allocated resource bundle or NULL if it doesn't exist.
326 U_INTERNAL void U_EXPORT2
327 ures_openFillIn(UResourceBundle *r,
328 const char* packageName,
329 const char* localeID,
333 * Returns a string from a string resource type
335 * @param resourceBundle a string resource
336 * @param len fills in the length of resulting string
337 * @param status fills in the outgoing error code
338 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
339 * Always check the value of status. Don't count on returning NULL.
340 * could be a non-failing error
341 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
342 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
343 * @see ures_getBinary
344 * @see ures_getIntVector
349 U_STABLE const UChar* U_EXPORT2
350 ures_getString(const UResourceBundle* resourceBundle,
355 * Returns a binary data from a binary resource.
357 * @param resourceBundle a string resource
358 * @param len fills in the length of resulting byte chunk
359 * @param status fills in the outgoing error code
360 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
361 * Always check the value of status. Don't count on returning NULL.
362 * could be a non-failing error
363 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
364 * @return a pointer to a chuck of unsigned bytes which live in a memory mapped/DLL file.
365 * @see ures_getString
366 * @see ures_getIntVector
371 U_STABLE const uint8_t* U_EXPORT2
372 ures_getBinary(const UResourceBundle* resourceBundle,
377 * Returns a 32 bit integer array from a resource.
379 * @param resourceBundle an int vector resource
380 * @param len fills in the length of resulting byte chunk
381 * @param status fills in the outgoing error code
382 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
383 * Always check the value of status. Don't count on returning NULL.
384 * could be a non-failing error
385 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
386 * @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.
387 * @see ures_getBinary
388 * @see ures_getString
393 U_STABLE const int32_t* U_EXPORT2
394 ures_getIntVector(const UResourceBundle* resourceBundle,
399 * Returns an unsigned integer from a resource.
400 * This integer is originally 28 bits.
402 * @param resourceBundle a string resource
403 * @param status fills in the outgoing error code
404 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
405 * could be a non-failing error
406 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
407 * @return an integer value
409 * @see ures_getIntVector
410 * @see ures_getBinary
411 * @see ures_getString
414 U_STABLE uint32_t U_EXPORT2
415 ures_getUInt(const UResourceBundle* resourceBundle,
419 * Returns a signed integer from a resource.
420 * This integer is originally 28 bit and the sign gets propagated.
422 * @param resourceBundle a string resource
423 * @param status fills in the outgoing error code
424 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
425 * could be a non-failing error
426 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
427 * @return an integer value
429 * @see ures_getIntVector
430 * @see ures_getBinary
431 * @see ures_getString
434 U_STABLE int32_t U_EXPORT2
435 ures_getInt(const UResourceBundle* resourceBundle,
439 * Returns the size of a resource. Size for scalar types is always 1,
440 * and for vector/table types is the number of child resources.
441 * @warning Integer array is treated as a scalar type. There are no
442 * APIs to access individual members of an integer array. It
443 * is always returned as a whole.
444 * @param resourceBundle a resource
445 * @return number of resources in a given resource.
448 U_STABLE int32_t U_EXPORT2
449 ures_getSize(const UResourceBundle *resourceBundle);
452 * Returns the type of a resource. Available types are defined in enum UResType
454 * @param resourceBundle a resource
455 * @return type of the given resource.
459 U_STABLE UResType U_EXPORT2
460 ures_getType(const UResourceBundle *resourceBundle);
463 * Returns the key associated with a given resource. Not all the resources have a key - only
464 * those that are members of a table.
466 * @param resourceBundle a resource
467 * @return a key associated to this resource, or NULL if it doesn't have a key
470 U_STABLE const char * U_EXPORT2
471 ures_getKey(const UResourceBundle *resourceBundle);
474 This API provides means for iterating through a resource
478 * Resets the internal context of a resource so that iteration starts from the first element.
480 * @param resourceBundle a resource
483 U_STABLE void U_EXPORT2
484 ures_resetIterator(UResourceBundle *resourceBundle);
487 * Checks whether the given resource has another element to iterate over.
489 * @param resourceBundle a resource
490 * @return TRUE if there are more elements, FALSE if there is no more elements
493 U_STABLE UBool U_EXPORT2
494 ures_hasNext(const UResourceBundle *resourceBundle);
497 * Returns the next resource in a given resource or NULL if there are no more resources
498 * to iterate over. Features a fill-in parameter.
500 * @param resourceBundle a resource
501 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
502 * Alternatively, you can supply a struct to be filled by this function.
503 * @param status fills in the outgoing error code. You may still get a non NULL result even if an
504 * error occured. Check status instead.
505 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
508 U_STABLE UResourceBundle* U_EXPORT2
509 ures_getNextResource(UResourceBundle *resourceBundle,
510 UResourceBundle *fillIn,
514 * Returns the next string in a given resource or NULL if there are no more resources
517 * @param resourceBundle a resource
518 * @param len fill in length of the string
519 * @param key fill in for key associated with this string. NULL if no key
520 * @param status fills in the outgoing error code. If an error occured, we may return NULL, but don't
521 * count on it. Check status instead!
522 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
525 U_STABLE const UChar* U_EXPORT2
526 ures_getNextString(UResourceBundle *resourceBundle,
532 * Returns the resource in a given resource at the specified index. Features a fill-in parameter.
534 * @param resourceBundle the resource bundle from which to get a sub-resource
535 * @param indexR an index to the wanted resource.
536 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
537 * Alternatively, you can supply a struct to be filled by this function.
538 * @param status fills in the outgoing error code. Don't count on NULL being returned if an error has
539 * occured. Check status instead.
540 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
543 U_STABLE UResourceBundle* U_EXPORT2
544 ures_getByIndex(const UResourceBundle *resourceBundle,
546 UResourceBundle *fillIn,
550 * Returns the string in a given resource at the specified index.
552 * @param resourceBundle a resource
553 * @param indexS an index to the wanted string.
554 * @param len fill in length of the string
555 * @param status fills in the outgoing error code. If an error occured, we may return NULL, but don't
556 * count on it. Check status instead!
557 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
560 U_STABLE const UChar* U_EXPORT2
561 ures_getStringByIndex(const UResourceBundle *resourceBundle,
567 * Returns a resource in a given resource that has a given key. This procedure works only with table
568 * resources. Features a fill-in parameter.
570 * @param resourceBundle a resource
571 * @param key a key associated with the wanted resource
572 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
573 * Alternatively, you can supply a struct to be filled by this function.
574 * @param status fills in the outgoing error code.
575 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
578 U_STABLE UResourceBundle* U_EXPORT2
579 ures_getByKey(const UResourceBundle *resourceBundle,
581 UResourceBundle *fillIn,
585 * Returns a string in a given resource that has a given key. This procedure works only with table
588 * @param resB a resource
589 * @param key a key associated with the wanted string
590 * @param len fill in length of the string
591 * @param status fills in the outgoing error code. If an error occured, we may return NULL, but don't
592 * count on it. Check status instead!
593 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
596 U_STABLE const UChar* U_EXPORT2
597 ures_getStringByKey(const UResourceBundle *resB,
603 #include "unicode/unistr.h"
607 * returns a string from a string resource type
609 * @param resB a resource
610 * @param status: fills in the outgoing error code
611 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
612 * could be a non-failing error
613 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
614 * @return an UnicodeString object. If there is an error, string is bogus
618 ures_getUnicodeString(const UResourceBundle *resB,
622 const UChar *r = ures_getString(resB, &len, status);
623 return UnicodeString(TRUE, r, len);
627 * Returns the next string in a resource or NULL if there are no more resources
630 * @param resB a resource
631 * @param key fill in for key associated with this string
632 * @param status fills in the outgoing error code
633 * @return an UnicodeString object.
637 ures_getNextUnicodeString(UResourceBundle *resB,
642 const UChar* r = ures_getNextString(resB, &len, key, status);
643 return UnicodeString(TRUE, r, len);
647 * Returns the string in a given resource at the specified index.
649 * @param resB a resource
650 * @param index an index to the wanted string.
651 * @param status fills in the outgoing error code
652 * @return an UnicodeString object. If there is an error, string is bogus
656 ures_getUnicodeStringByIndex(const UResourceBundle *resB,
661 const UChar* r = ures_getStringByIndex(resB, indexS, &len, status);
662 return UnicodeString(TRUE, r, len);
666 * Returns a string in a resource that has a given key. This procedure works only with table
669 * @param resB a resource
670 * @param key a key associated with the wanted string
671 * @param status fills in the outgoing error code
672 * @return an UnicodeString object. If there is an error, string is bogus
676 ures_getUnicodeStringByKey(const UResourceBundle *resB,
681 const UChar* r = ures_getStringByKey(resB, key, &len, status);
682 return UnicodeString(TRUE, r, len);
691 * Get a resource with multi-level fallback. Normally only the top level resources will
692 * fallback to its parent. This performs fallback on subresources. For example, when a table
693 * is defined in a resource bundle and a parent resource bundle, normally no fallback occurs
694 * on the sub-resources because the table is defined in the current resource bundle, but this
695 * function can perform fallback on the sub-resources of the table.
696 * @param resB a resource
697 * @param inKey a key associated with the requested resource
698 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
699 * Alternatively, you can supply a struct to be filled by this function.
700 * @param status: fills in the outgoing error code
701 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
702 * could be a non-failing error
703 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
704 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
707 U_INTERNAL UResourceBundle* U_EXPORT2
708 ures_getByKeyWithFallback(const UResourceBundle *resB,
710 UResourceBundle *fillIn,
715 * Create a string enumerator, owned by the caller, of all locales located within
716 * the specified resource tree.
717 * @param packageName name of the tree, such as (NULL) or U_ICUDATA_ALIAS or or "ICUDATA-coll"
718 * This call is similar to uloc_getAvailable().
719 * @param status error code
722 U_DRAFT UEnumeration* U_EXPORT2
723 ures_openAvailableLocales(const char *packageName, UErrorCode *status);