2 **********************************************************************
3 * Copyright (C) 1997-2004, 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://oss.software.ibm.com/cvs/icu/~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://oss.software.ibm.com/icu/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 path string containing the full path pointing to the directory
145 * where the resources reside followed by the package name
146 * e.g. "/usr/resource/my_app/resources/guimessages" on a Unix system.
147 * if NULL, ICU default data files will be used.
148 * @param locale specifies the locale for which we want to open the resource
149 * if NULL, the default locale will be used. If strlen(locale) == 0
150 * root locale will be used.
152 * @param status fills in the outgoing error code.
153 * The UErrorCode err parameter is used to return status information to the user. To
154 * check whether the construction succeeded or not, you should check the value of
155 * U_SUCCESS(err). If you wish more detailed information, you can check for
156 * informational status results which still indicate success. U_USING_FALLBACK_WARNING
157 * indicates that a fall back locale was used. For example, 'de_CH' was requested,
158 * but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that
159 * the default locale data or root locale data was used; neither the requested locale
160 * nor any of its fall back locales could be found. Please see the users guide for more
161 * information on this topic.
162 * @return a newly allocated resource bundle.
166 U_STABLE UResourceBundle
* U_EXPORT2
167 ures_open(const char* path
,
172 /** This function does not care what kind of localeID is passed in. It simply opens a bundle with
173 * that name. Fallback mechanism is disabled for the new bundle. If the requested bundle contains
174 * an %%ALIAS directive, the results are undefined.
175 * @param path string containing the full path pointing to the directory
176 * where the resources reside followed by the package name
177 * e.g. "/usr/resource/my_app/resources/guimessages" on a Unix system.
178 * if NULL, ICU default data files will be used.
179 * @param locale specifies the locale for which we want to open the resource
180 * if NULL, the default locale will be used. If strlen(locale) == 0
181 * root locale will be used.
183 * @param status fills in the outgoing error code. Either U_ZERO_ERROR or U_MISSING_RESOURCE_ERROR
184 * @return a newly allocated resource bundle or NULL if it doesn't exist.
188 U_STABLE UResourceBundle
* U_EXPORT2
189 ures_openDirect(const char* path
,
194 * Same as ures_open() but takes a const UChar *path.
195 * This path will be converted to char * using the default converter,
196 * then ures_open() is called.
198 * @param path string containing the full path pointing to the directory
199 * where the resources reside followed by the package name
200 * @param locale specifies the locale for which we want to open the resource
201 * if NULL, the default locale will be used. If strlen(locale) == 0
202 * root locale will be used.
203 * @param status fills in the outgoing error code.
204 * @return a newly allocated resource bundle.
208 U_STABLE UResourceBundle
* U_EXPORT2
209 ures_openU(const UChar
* path
,
214 * Returns the number of strings/arrays in resource bundles.
215 * Better to use ures_getSize, as this function will be deprecated.
217 *@param resourceBundle resource bundle containing the desired strings
218 *@param resourceKey key tagging the resource
219 *@param err fills in the outgoing error code
220 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
221 * could be a non-failing error
222 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_FALLBACK_WARNING </TT>
223 *@return: for <STRONG>Arrays</STRONG>: returns the number of resources in the array
224 * <STRONG>Tables</STRONG>: returns the number of resources in the table
225 * <STRONG>single string</STRONG>: returns 1
227 * @deprecated ICU 2.8 User ures_getSize instead
229 U_DEPRECATED
int32_t U_EXPORT2
230 ures_countArrayItems(const UResourceBundle
* resourceBundle
,
231 const char* resourceKey
,
234 * Close a resource bundle, all pointers returned from the various ures_getXXX calls
235 * on this particular bundle should be considered invalid henceforth.
237 * @param resourceBundle a pointer to a resourceBundle struct. Can be NULL.
241 U_STABLE
void U_EXPORT2
242 ures_close(UResourceBundle
* resourceBundle
);
245 * Return the version number associated with this ResourceBundle as a string. Please
246 * use ures_getVersion as this function is going to be deprecated.
248 * @param resourceBundle The resource bundle for which the version is checked.
249 * @return A version number string as specified in the resource bundle or its parent.
250 * The caller does not own this string.
251 * @see ures_getVersion
252 * @deprecated ICU 2.8 Use ures_getVersion instead.
254 U_DEPRECATED
const char* U_EXPORT2
255 ures_getVersionNumber(const UResourceBundle
* resourceBundle
);
258 * Return the version number associated with this ResourceBundle as an
259 * UVersionInfo array.
261 * @param resB The resource bundle for which the version is checked.
262 * @param versionInfo A UVersionInfo array that is filled with the version number
263 * as specified in the resource bundle or its parent.
266 U_STABLE
void U_EXPORT2
267 ures_getVersion(const UResourceBundle
* resB
,
268 UVersionInfo versionInfo
);
271 * Return the name of the Locale associated with this ResourceBundle. This API allows
272 * you to query for the real locale of the resource. For example, if you requested
273 * "en_US_CALIFORNIA" and only "en_US" bundle exists, "en_US" will be returned.
274 * For subresources, the locale where this resource comes from will be returned.
275 * If fallback has occured, getLocale will reflect this.
277 * @param resourceBundle resource bundle in question
278 * @param status just for catching illegal arguments
279 * @return A Locale name
280 * @deprecated ICU 2.8 Use ures_getLocaleByType instead.
282 U_DEPRECATED
const char* U_EXPORT2
283 ures_getLocale(const UResourceBundle
* resourceBundle
,
288 * Return the name of the Locale associated with this ResourceBundle.
289 * You can choose between requested, valid and real locale.
291 * @param resourceBundle resource bundle in question
292 * @param type You can choose between requested, valid and actual
293 * locale. For description see the definition of
294 * ULocDataLocaleType in uloc.h
295 * @param status just for catching illegal arguments
296 * @return A Locale name
299 U_DRAFT
const char* U_EXPORT2
300 ures_getLocaleByType(const UResourceBundle
* resourceBundle
,
301 ULocDataLocaleType type
,
306 * Same as ures_open() but uses the fill-in parameter instead of allocating
307 * a bundle, if r!=NULL.
308 * TODO need to revisit usefulness of this function
309 * and usage model for fillIn parameters without knowing sizeof(UResourceBundle)
310 * @param r The resourcebundle to open
311 * @param path String containing the full path pointing to the directory
312 * where the resources reside followed by the package name
313 * @param localeID specifies the locale for which we want to open the resource
314 * @param status The error code
315 * @return a newly allocated resource bundle or NULL if it doesn't exist.
318 U_INTERNAL
void U_EXPORT2
319 ures_openFillIn(UResourceBundle
*r
,
321 const char* localeID
,
325 * Returns a string from a string resource type
327 * @param resourceBundle a string resource
328 * @param len fills in the length of resulting string
329 * @param status fills in the outgoing error code
330 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
331 * Always check the value of status. Don't count on returning NULL.
332 * could be a non-failing error
333 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
334 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
335 * @see ures_getBinary
336 * @see ures_getIntVector
341 U_STABLE
const UChar
* U_EXPORT2
342 ures_getString(const UResourceBundle
* resourceBundle
,
347 * Returns a binary data from a binary resource.
349 * @param resourceBundle a string resource
350 * @param len fills in the length of resulting byte chunk
351 * @param status fills in the outgoing error code
352 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
353 * Always check the value of status. Don't count on returning NULL.
354 * could be a non-failing error
355 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
356 * @return a pointer to a chuck of unsigned bytes which live in a memory mapped/DLL file.
357 * @see ures_getString
358 * @see ures_getIntVector
363 U_STABLE
const uint8_t* U_EXPORT2
364 ures_getBinary(const UResourceBundle
* resourceBundle
,
369 * Returns a 32 bit integer array from a resource.
371 * @param resourceBundle an int vector resource
372 * @param len fills in the length of resulting byte chunk
373 * @param status fills in the outgoing error code
374 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
375 * Always check the value of status. Don't count on returning NULL.
376 * could be a non-failing error
377 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
378 * @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.
379 * @see ures_getBinary
380 * @see ures_getString
385 U_STABLE
const int32_t* U_EXPORT2
386 ures_getIntVector(const UResourceBundle
* resourceBundle
,
391 * Returns an unsigned integer from a resource.
392 * This integer is originally 28 bits.
394 * @param resourceBundle a string resource
395 * @param status fills in the outgoing error code
396 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
397 * could be a non-failing error
398 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
399 * @return an integer value
401 * @see ures_getIntVector
402 * @see ures_getBinary
403 * @see ures_getString
406 U_STABLE
uint32_t U_EXPORT2
407 ures_getUInt(const UResourceBundle
* resourceBundle
,
411 * Returns a signed integer from a resource.
412 * This integer is originally 28 bit and the sign gets propagated.
414 * @param resourceBundle a string resource
415 * @param status fills in the outgoing error code
416 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
417 * could be a non-failing error
418 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
419 * @return an integer value
421 * @see ures_getIntVector
422 * @see ures_getBinary
423 * @see ures_getString
426 U_STABLE
int32_t U_EXPORT2
427 ures_getInt(const UResourceBundle
* resourceBundle
,
431 * Returns the size of a resource. Size for scalar types is always 1,
432 * and for vector/table types is the number of child resources.
433 * @warning Integer array is treated as a scalar type. There are no
434 * APIs to access individual members of an integer array. It
435 * is always returned as a whole.
436 * @param resourceBundle a resource
437 * @return number of resources in a given resource.
440 U_STABLE
int32_t U_EXPORT2
441 ures_getSize(const UResourceBundle
*resourceBundle
);
444 * Returns the type of a resource. Available types are defined in enum UResType
446 * @param resourceBundle a resource
447 * @return type of the given resource.
451 U_STABLE UResType U_EXPORT2
452 ures_getType(const UResourceBundle
*resourceBundle
);
455 * Returns the key associated with a given resource. Not all the resources have a key - only
456 * those that are members of a table.
458 * @param resourceBundle a resource
459 * @return a key associated to this resource, or NULL if it doesn't have a key
462 U_STABLE
const char * U_EXPORT2
463 ures_getKey(const UResourceBundle
*resourceBundle
);
466 This API provides means for iterating through a resource
470 * Resets the internal context of a resource so that iteration starts from the first element.
472 * @param resourceBundle a resource
475 U_STABLE
void U_EXPORT2
476 ures_resetIterator(UResourceBundle
*resourceBundle
);
479 * Checks whether the given resource has another element to iterate over.
481 * @param resourceBundle a resource
482 * @return TRUE if there are more elements, FALSE if there is no more elements
485 U_STABLE UBool U_EXPORT2
486 ures_hasNext(const UResourceBundle
*resourceBundle
);
489 * Returns the next resource in a given resource or NULL if there are no more resources
490 * to iterate over. Features a fill-in parameter.
492 * @param resourceBundle a resource
493 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
494 * Alternatively, you can supply a struct to be filled by this function.
495 * @param status fills in the outgoing error code. You may still get a non NULL result even if an
496 * error occured. Check status instead.
497 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
500 U_STABLE UResourceBundle
* U_EXPORT2
501 ures_getNextResource(UResourceBundle
*resourceBundle
,
502 UResourceBundle
*fillIn
,
506 * Returns the next string in a given resource or NULL if there are no more resources
509 * @param resourceBundle a resource
510 * @param len fill in length of the string
511 * @param key fill in for key associated with this string. NULL if no key
512 * @param status fills in the outgoing error code. If an error occured, we may return NULL, but don't
513 * count on it. Check status instead!
514 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
517 U_STABLE
const UChar
* U_EXPORT2
518 ures_getNextString(UResourceBundle
*resourceBundle
,
524 * Returns the resource in a given resource at the specified index. Features a fill-in parameter.
526 * @param resourceBundle the resource bundle from which to get a sub-resource
527 * @param indexR an index to the wanted resource.
528 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
529 * Alternatively, you can supply a struct to be filled by this function.
530 * @param status fills in the outgoing error code. Don't count on NULL being returned if an error has
531 * occured. Check status instead.
532 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
535 U_STABLE UResourceBundle
* U_EXPORT2
536 ures_getByIndex(const UResourceBundle
*resourceBundle
,
538 UResourceBundle
*fillIn
,
542 * Returns the string in a given resource at the specified index.
544 * @param resourceBundle a resource
545 * @param indexS an index to the wanted string.
546 * @param len fill in length of the string
547 * @param status fills in the outgoing error code. If an error occured, we may return NULL, but don't
548 * count on it. Check status instead!
549 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
552 U_STABLE
const UChar
* U_EXPORT2
553 ures_getStringByIndex(const UResourceBundle
*resourceBundle
,
559 * Returns a resource in a given resource that has a given key. This procedure works only with table
560 * resources. Features a fill-in parameter.
562 * @param resourceBundle a resource
563 * @param key a key associated with the wanted resource
564 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
565 * Alternatively, you can supply a struct to be filled by this function.
566 * @param status fills in the outgoing error code.
567 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
570 U_STABLE UResourceBundle
* U_EXPORT2
571 ures_getByKey(const UResourceBundle
*resourceBundle
,
573 UResourceBundle
*fillIn
,
577 * Returns a string in a given resource that has a given key. This procedure works only with table
580 * @param resB a resource
581 * @param key a key associated with the wanted string
582 * @param len fill in length of the string
583 * @param status fills in the outgoing error code. If an error occured, we may return NULL, but don't
584 * count on it. Check status instead!
585 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
588 U_STABLE
const UChar
* U_EXPORT2
589 ures_getStringByKey(const UResourceBundle
*resB
,
595 #include "unicode/unistr.h"
599 * returns a string from a string resource type
601 * @param resB a resource
602 * @param status: fills in the outgoing error code
603 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
604 * could be a non-failing error
605 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
606 * @return an UnicodeString object. If there is an error, string is bogus
610 ures_getUnicodeString(const UResourceBundle
*resB
,
614 const UChar
*r
= ures_getString(resB
, &len
, status
);
615 return UnicodeString(TRUE
, r
, len
);
619 * Returns the next string in a resource or NULL if there are no more resources
622 * @param resB a resource
623 * @param key fill in for key associated with this string
624 * @param status fills in the outgoing error code
625 * @return an UnicodeString object.
629 ures_getNextUnicodeString(UResourceBundle
*resB
,
634 const UChar
* r
= ures_getNextString(resB
, &len
, key
, status
);
635 return UnicodeString(TRUE
, r
, len
);
639 * Returns the string in a given resource at the specified index.
641 * @param resB a resource
642 * @param index an index to the wanted string.
643 * @param status fills in the outgoing error code
644 * @return an UnicodeString object. If there is an error, string is bogus
648 ures_getUnicodeStringByIndex(const UResourceBundle
*resB
,
653 const UChar
* r
= ures_getStringByIndex(resB
, indexS
, &len
, status
);
654 return UnicodeString(TRUE
, r
, len
);
658 * Returns a string in a resource that has a given key. This procedure works only with table
661 * @param resB a resource
662 * @param key a key associated with the wanted string
663 * @param status fills in the outgoing error code
664 * @return an UnicodeString object. If there is an error, string is bogus
668 ures_getUnicodeStringByKey(const UResourceBundle
*resB
,
673 const UChar
* r
= ures_getStringByKey(resB
, key
, &len
, status
);
674 return UnicodeString(TRUE
, r
, len
);
683 * Get a resource with multi-level fallback. Normally only the top level resources will
684 * fallback to its parent. This performs fallback on subresources. For example, when a table
685 * is defined in a resource bundle and a parent resource bundle, normally no fallback occurs
686 * on the sub-resources because the table is defined in the current resource bundle, but this
687 * function can perform fallback on the sub-resources of the table.
688 * @param resB a resource
689 * @param inKey a key associated with the requested resource
690 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
691 * Alternatively, you can supply a struct to be filled by this function.
692 * @param status: fills in the outgoing error code
693 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
694 * could be a non-failing error
695 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
696 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
699 U_INTERNAL UResourceBundle
* U_EXPORT2
700 ures_getByKeyWithFallback(const UResourceBundle
*resB
,
702 UResourceBundle
*fillIn
,
707 * Create a string enumerator, owned by the caller, of all locales located within
708 * the specified resource tree.
709 * @param path path to the tree, such as (NULL) or U_ICUDATA_ALIAS or or "ICUDATA-coll"
710 * This call is similar to uloc_getAvailable().
711 * @param status error code
714 U_DRAFT UEnumeration
* U_EXPORT2
715 ures_openAvailableLocales(const char *path
, UErrorCode
*status
);