2 **********************************************************************
3 * Copyright (C) 1997-2010, 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"
28 #include "unicode/localpointer.h"
32 * \brief C API: Resource Bundle
34 * <h2>C API: Resource Bundle</h2>
36 * C API representing a collection of resource information pertaining to a given
37 * locale. A resource bundle provides a way of accessing locale- specific information in
38 * a data file. You create a resource bundle that manages the resources for a given
39 * locale and then ask it for individual resources.
41 * Resource bundles in ICU4C are currently defined using text files which conform to the following
42 * <a href="http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt">BNF definition</a>.
43 * More on resource bundle concepts and syntax can be found in the
44 * <a href="http://icu-project.org/userguide/ResourceManagement.html">Users Guide</a>.
49 * UResourceBundle is an opaque type for handles for resource bundles in C APIs.
52 struct UResourceBundle
;
57 typedef struct UResourceBundle UResourceBundle
;
60 * Numeric constants for types of resource items.
65 /** Resource type constant for "no resource". @stable ICU 2.6 */
68 /** Resource type constant for 16-bit Unicode strings. @stable ICU 2.6 */
71 /** Resource type constant for binary data. @stable ICU 2.6 */
74 /** Resource type constant for tables of key-value pairs. @stable ICU 2.6 */
78 * Resource type constant for aliases;
79 * internally stores a string which identifies the actual resource
80 * storing the data (can be in a different resource bundle).
81 * Resolved internally before delivering the actual resource through the API.
87 * Resource type constant for a single 28-bit integer, interpreted as
88 * signed or unsigned by the ures_getInt() or ures_getUInt() function.
95 /** Resource type constant for arrays of resources. @stable ICU 2.6 */
99 * Resource type constant for vectors of 32-bit integers.
100 * @see ures_getIntVector
103 URES_INT_VECTOR
= 14,
104 #ifndef U_HIDE_DEPRECATED_API
105 /** @deprecated ICU 2.6 Use the URES_ constant instead. */
107 /** @deprecated ICU 2.6 Use the URES_ constant instead. */
108 RES_STRING
=URES_STRING
,
109 /** @deprecated ICU 2.6 Use the URES_ constant instead. */
110 RES_BINARY
=URES_BINARY
,
111 /** @deprecated ICU 2.6 Use the URES_ constant instead. */
112 RES_TABLE
=URES_TABLE
,
113 /** @deprecated ICU 2.6 Use the URES_ constant instead. */
114 RES_ALIAS
=URES_ALIAS
,
115 /** @deprecated ICU 2.6 Use the URES_ constant instead. */
117 /** @deprecated ICU 2.6 Use the URES_ constant instead. */
118 RES_ARRAY
=URES_ARRAY
,
119 /** @deprecated ICU 2.6 Use the URES_ constant instead. */
120 RES_INT_VECTOR
=URES_INT_VECTOR
,
121 /** @deprecated ICU 2.6 Not used. */
123 #endif /* U_HIDE_DEPRECATED_API */
129 * Functions to create and destroy resource bundles.
133 * Opens a UResourceBundle, from which users can extract strings by using
134 * their corresponding keys.
135 * Note that the caller is responsible of calling <TT>ures_close</TT> on each succesfully
136 * opened resource bundle.
137 * @param packageName The packageName and locale together point to an ICU udata object,
138 * as defined by <code> udata_open( packageName, "res", locale, err) </code>
139 * or equivalent. Typically, packageName will refer to a (.dat) file, or to
140 * a package registered with udata_setAppData(). Using a full file or directory
141 * pathname for packageName is deprecated. If NULL, ICU data will be used.
142 * @param locale specifies the locale for which we want to open the resource
143 * if NULL, the default locale will be used. If strlen(locale) == 0
144 * root locale will be used.
146 * @param status fills in the outgoing error code.
147 * The UErrorCode err parameter is used to return status information to the user. To
148 * check whether the construction succeeded or not, you should check the value of
149 * U_SUCCESS(err). If you wish more detailed information, you can check for
150 * informational status results which still indicate success. U_USING_FALLBACK_WARNING
151 * indicates that a fall back locale was used. For example, 'de_CH' was requested,
152 * but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that
153 * the default locale data or root locale data was used; neither the requested locale
154 * nor any of its fall back locales could be found. Please see the users guide for more
155 * information on this topic.
156 * @return a newly allocated resource bundle.
160 U_STABLE UResourceBundle
* U_EXPORT2
161 ures_open(const char* packageName
,
166 /** This function does not care what kind of localeID is passed in. It simply opens a bundle with
167 * that name. Fallback mechanism is disabled for the new bundle. If the requested bundle contains
168 * an %%ALIAS directive, the results are undefined.
169 * @param packageName The packageName and locale together point to an ICU udata object,
170 * as defined by <code> udata_open( packageName, "res", locale, err) </code>
171 * or equivalent. Typically, packageName will refer to a (.dat) file, or to
172 * a package registered with udata_setAppData(). Using a full file or directory
173 * pathname for packageName is deprecated. If NULL, ICU data will be used.
174 * @param locale specifies the locale for which we want to open the resource
175 * if NULL, the default locale will be used. If strlen(locale) == 0
176 * root locale will be used.
178 * @param status fills in the outgoing error code. Either U_ZERO_ERROR or U_MISSING_RESOURCE_ERROR
179 * @return a newly allocated resource bundle or NULL if it doesn't exist.
183 U_STABLE UResourceBundle
* U_EXPORT2
184 ures_openDirect(const char* packageName
,
189 * Same as ures_open() but takes a const UChar *path.
190 * This path will be converted to char * using the default converter,
191 * then ures_open() is called.
193 * @param packageName The packageName and locale together point to an ICU udata object,
194 * as defined by <code> udata_open( packageName, "res", locale, err) </code>
195 * or equivalent. Typically, packageName will refer to a (.dat) file, or to
196 * a package registered with udata_setAppData(). Using a full file or directory
197 * pathname for packageName is deprecated. If NULL, ICU data will be used.
198 * @param locale specifies the locale for which we want to open the resource
199 * if NULL, the default locale will be used. If strlen(locale) == 0
200 * root locale will be used.
201 * @param status fills in the outgoing error code.
202 * @return a newly allocated resource bundle.
206 U_STABLE UResourceBundle
* U_EXPORT2
207 ures_openU(const UChar
* packageName
,
212 * Returns the number of strings/arrays in resource bundles.
213 * Better to use ures_getSize, as this function will be deprecated.
215 *@param resourceBundle resource bundle containing the desired strings
216 *@param resourceKey key tagging the resource
217 *@param err fills in the outgoing error code
218 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
219 * could be a non-failing error
220 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_FALLBACK_WARNING </TT>
221 *@return: for <STRONG>Arrays</STRONG>: returns the number of resources in the array
222 * <STRONG>Tables</STRONG>: returns the number of resources in the table
223 * <STRONG>single string</STRONG>: returns 1
225 * @deprecated ICU 2.8 User ures_getSize instead
227 U_DEPRECATED
int32_t U_EXPORT2
228 ures_countArrayItems(const UResourceBundle
* resourceBundle
,
229 const char* resourceKey
,
232 * Close a resource bundle, all pointers returned from the various ures_getXXX calls
233 * on this particular bundle should be considered invalid henceforth.
235 * @param resourceBundle a pointer to a resourceBundle struct. Can be NULL.
239 U_STABLE
void U_EXPORT2
240 ures_close(UResourceBundle
* resourceBundle
);
242 #if U_SHOW_CPLUSPLUS_API
247 * \class LocalUResourceBundlePointer
248 * "Smart pointer" class, closes a UResourceBundle via ures_close().
249 * For most methods see the LocalPointerBase base class.
251 * @see LocalPointerBase
255 U_DEFINE_LOCAL_OPEN_POINTER(LocalUResourceBundlePointer
, UResourceBundle
, ures_close
);
262 * Return the version number associated with this ResourceBundle as a string. Please
263 * use ures_getVersion as this function is going to be deprecated.
265 * @param resourceBundle The resource bundle for which the version is checked.
266 * @return A version number string as specified in the resource bundle or its parent.
267 * The caller does not own this string.
268 * @see ures_getVersion
269 * @deprecated ICU 2.8 Use ures_getVersion instead.
271 U_DEPRECATED
const char* U_EXPORT2
272 ures_getVersionNumber(const UResourceBundle
* resourceBundle
);
275 * Return the version number associated with this ResourceBundle as an
276 * UVersionInfo array.
278 * @param resB The resource bundle for which the version is checked.
279 * @param versionInfo A UVersionInfo array that is filled with the version number
280 * as specified in the resource bundle or its parent.
283 U_STABLE
void U_EXPORT2
284 ures_getVersion(const UResourceBundle
* resB
,
285 UVersionInfo versionInfo
);
288 * Return the name of the Locale associated with this ResourceBundle. This API allows
289 * you to query for the real locale of the resource. For example, if you requested
290 * "en_US_CALIFORNIA" and only "en_US" bundle exists, "en_US" will be returned.
291 * For subresources, the locale where this resource comes from will be returned.
292 * If fallback has occured, getLocale will reflect this.
294 * @param resourceBundle resource bundle in question
295 * @param status just for catching illegal arguments
296 * @return A Locale name
297 * @deprecated ICU 2.8 Use ures_getLocaleByType instead.
299 U_DEPRECATED
const char* U_EXPORT2
300 ures_getLocale(const UResourceBundle
* resourceBundle
,
305 * Return the name of the Locale associated with this ResourceBundle.
306 * You can choose between requested, valid and real locale.
308 * @param resourceBundle resource bundle in question
309 * @param type You can choose between requested, valid and actual
310 * locale. For description see the definition of
311 * ULocDataLocaleType in uloc.h
312 * @param status just for catching illegal arguments
313 * @return A Locale name
316 U_STABLE
const char* U_EXPORT2
317 ures_getLocaleByType(const UResourceBundle
* resourceBundle
,
318 ULocDataLocaleType type
,
323 * Same as ures_open() but uses the fill-in parameter instead of allocating
324 * a bundle, if r!=NULL.
325 * TODO need to revisit usefulness of this function
326 * and usage model for fillIn parameters without knowing sizeof(UResourceBundle)
327 * @param r The resourcebundle to open
328 * @param packageName The packageName and locale together point to an ICU udata object,
329 * as defined by <code> udata_open( packageName, "res", locale, err) </code>
330 * or equivalent. Typically, packageName will refer to a (.dat) file, or to
331 * a package registered with udata_setAppData(). Using a full file or directory
332 * pathname for packageName is deprecated. If NULL, ICU data will be used.
333 * @param localeID specifies the locale for which we want to open the resource
334 * @param status The error code
335 * @return a newly allocated resource bundle or NULL if it doesn't exist.
338 U_INTERNAL
void U_EXPORT2
339 ures_openFillIn(UResourceBundle
*r
,
340 const char* packageName
,
341 const char* localeID
,
345 * Returns a string from a string resource type
347 * @param resourceBundle a string resource
348 * @param len fills in the length of resulting string
349 * @param status fills in the outgoing error code
350 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
351 * Always check the value of status. Don't count on returning NULL.
352 * could be a non-failing error
353 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
354 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
355 * @see ures_getBinary
356 * @see ures_getIntVector
361 U_STABLE
const UChar
* U_EXPORT2
362 ures_getString(const UResourceBundle
* resourceBundle
,
367 * Returns a UTF-8 string from a string resource.
368 * The UTF-8 string may be returnable directly as a pointer, or
369 * it may need to be copied, or transformed from UTF-16 using u_strToUTF8()
372 * If forceCopy==TRUE, then the string is always written to the dest buffer
373 * and dest is returned.
375 * If forceCopy==FALSE, then the string is returned as a pointer if possible,
376 * without needing a dest buffer (it can be NULL). If the string needs to be
377 * copied or transformed, then it may be placed into dest at an arbitrary offset.
379 * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and
380 * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual.
382 * If the string is transformed from UTF-16, then a conversion error may occur
383 * if an unpaired surrogate is encountered. If the function is successful, then
384 * the output UTF-8 string is always well-formed.
386 * @param resB Resource bundle.
387 * @param dest Destination buffer. Can be NULL only if capacity=*length==0.
388 * @param length Input: Capacity of destination buffer.
389 * Output: Actual length of the UTF-8 string, not counting the
390 * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR.
391 * Can be NULL, meaning capacity=0 and the string length is not
392 * returned to the caller.
393 * @param forceCopy If TRUE, then the output string will always be written to
394 * dest, with U_BUFFER_OVERFLOW_ERROR and
395 * U_STRING_NOT_TERMINATED_WARNING set if appropriate.
396 * If FALSE, then the dest buffer may or may not contain a
397 * copy of the string. dest may or may not be modified.
398 * If a copy needs to be written, then the UErrorCode parameter
399 * indicates overflow etc. as usual.
400 * @param status Pointer to a standard ICU error code. Its input value must
401 * pass the U_SUCCESS() test, or else the function returns
402 * immediately. Check for U_FAILURE() on output or use with
403 * function chaining. (See User Guide for details.)
404 * @return The pointer to the UTF-8 string. It may be dest, or at some offset
405 * from dest (only if !forceCopy), or in unrelated memory.
406 * Always NUL-terminated unless the string was written to dest and
407 * length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set).
409 * @see ures_getString
413 U_STABLE
const char * U_EXPORT2
414 ures_getUTF8String(const UResourceBundle
*resB
,
415 char *dest
, int32_t *length
,
420 * Returns a binary data from a binary resource.
422 * @param resourceBundle a string resource
423 * @param len fills in the length of resulting byte chunk
424 * @param status fills in the outgoing error code
425 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
426 * Always check the value of status. Don't count on returning NULL.
427 * could be a non-failing error
428 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
429 * @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.
430 * @see ures_getString
431 * @see ures_getIntVector
436 U_STABLE
const uint8_t* U_EXPORT2
437 ures_getBinary(const UResourceBundle
* resourceBundle
,
442 * Returns a 32 bit integer array from a resource.
444 * @param resourceBundle an int vector resource
445 * @param len fills in the length of resulting byte chunk
446 * @param status fills in the outgoing error code
447 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
448 * Always check the value of status. Don't count on returning NULL.
449 * could be a non-failing error
450 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
451 * @return a pointer to a chunk of integers which live in a memory mapped/DLL file.
452 * @see ures_getBinary
453 * @see ures_getString
458 U_STABLE
const int32_t* U_EXPORT2
459 ures_getIntVector(const UResourceBundle
* resourceBundle
,
464 * Returns an unsigned integer from a resource.
465 * This integer is originally 28 bits.
467 * @param resourceBundle a string resource
468 * @param status fills in the outgoing error code
469 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
470 * could be a non-failing error
471 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
472 * @return an integer value
474 * @see ures_getIntVector
475 * @see ures_getBinary
476 * @see ures_getString
479 U_STABLE
uint32_t U_EXPORT2
480 ures_getUInt(const UResourceBundle
* resourceBundle
,
484 * Returns a signed integer from a resource.
485 * This integer is originally 28 bit and the sign gets propagated.
487 * @param resourceBundle a string resource
488 * @param status fills in the outgoing error code
489 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
490 * could be a non-failing error
491 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
492 * @return an integer value
494 * @see ures_getIntVector
495 * @see ures_getBinary
496 * @see ures_getString
499 U_STABLE
int32_t U_EXPORT2
500 ures_getInt(const UResourceBundle
* resourceBundle
,
504 * Returns the size of a resource. Size for scalar types is always 1,
505 * and for vector/table types is the number of child resources.
506 * @warning Integer array is treated as a scalar type. There are no
507 * APIs to access individual members of an integer array. It
508 * is always returned as a whole.
509 * @param resourceBundle a resource
510 * @return number of resources in a given resource.
513 U_STABLE
int32_t U_EXPORT2
514 ures_getSize(const UResourceBundle
*resourceBundle
);
517 * Returns the type of a resource. Available types are defined in enum UResType
519 * @param resourceBundle a resource
520 * @return type of the given resource.
524 U_STABLE UResType U_EXPORT2
525 ures_getType(const UResourceBundle
*resourceBundle
);
528 * Returns the key associated with a given resource. Not all the resources have a key - only
529 * those that are members of a table.
531 * @param resourceBundle a resource
532 * @return a key associated to this resource, or NULL if it doesn't have a key
535 U_STABLE
const char * U_EXPORT2
536 ures_getKey(const UResourceBundle
*resourceBundle
);
539 This API provides means for iterating through a resource
543 * Resets the internal context of a resource so that iteration starts from the first element.
545 * @param resourceBundle a resource
548 U_STABLE
void U_EXPORT2
549 ures_resetIterator(UResourceBundle
*resourceBundle
);
552 * Checks whether the given resource has another element to iterate over.
554 * @param resourceBundle a resource
555 * @return TRUE if there are more elements, FALSE if there is no more elements
558 U_STABLE UBool U_EXPORT2
559 ures_hasNext(const UResourceBundle
*resourceBundle
);
562 * Returns the next resource in a given resource or NULL if there are no more resources
563 * to iterate over. Features a fill-in parameter.
565 * @param resourceBundle a resource
566 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be closed by the caller.
567 * Alternatively, you can supply a struct to be filled by this function.
568 * @param status fills in the outgoing error code. You may still get a non NULL result even if an
569 * error occured. Check status instead.
570 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it
573 U_STABLE UResourceBundle
* U_EXPORT2
574 ures_getNextResource(UResourceBundle
*resourceBundle
,
575 UResourceBundle
*fillIn
,
579 * Returns the next string in a given resource or NULL if there are no more resources
582 * @param resourceBundle a resource
583 * @param len fill in length of the string
584 * @param key fill in for key associated with this string. NULL if no key
585 * @param status fills in the outgoing error code. If an error occured, we may return NULL, but don't
586 * count on it. Check status instead!
587 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
590 U_STABLE
const UChar
* U_EXPORT2
591 ures_getNextString(UResourceBundle
*resourceBundle
,
597 * Returns the resource in a given resource at the specified index. Features a fill-in parameter.
599 * @param resourceBundle the resource bundle from which to get a sub-resource
600 * @param indexR an index to the wanted resource.
601 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be closed by the caller.
602 * Alternatively, you can supply a struct to be filled by this function.
603 * @param status fills in the outgoing error code. Don't count on NULL being returned if an error has
604 * occured. Check status instead.
605 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it
608 U_STABLE UResourceBundle
* U_EXPORT2
609 ures_getByIndex(const UResourceBundle
*resourceBundle
,
611 UResourceBundle
*fillIn
,
615 * Returns the string in a given resource at the specified index.
617 * @param resourceBundle a resource
618 * @param indexS an index to the wanted string.
619 * @param len fill in length of the string
620 * @param status fills in the outgoing error code. If an error occured, we may return NULL, but don't
621 * count on it. Check status instead!
622 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
625 U_STABLE
const UChar
* U_EXPORT2
626 ures_getStringByIndex(const UResourceBundle
*resourceBundle
,
632 * Returns a UTF-8 string from a resource at the specified index.
633 * The UTF-8 string may be returnable directly as a pointer, or
634 * it may need to be copied, or transformed from UTF-16 using u_strToUTF8()
637 * If forceCopy==TRUE, then the string is always written to the dest buffer
638 * and dest is returned.
640 * If forceCopy==FALSE, then the string is returned as a pointer if possible,
641 * without needing a dest buffer (it can be NULL). If the string needs to be
642 * copied or transformed, then it may be placed into dest at an arbitrary offset.
644 * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and
645 * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual.
647 * If the string is transformed from UTF-16, then a conversion error may occur
648 * if an unpaired surrogate is encountered. If the function is successful, then
649 * the output UTF-8 string is always well-formed.
651 * @param resB Resource bundle.
652 * @param stringIndex An index to the wanted string.
653 * @param dest Destination buffer. Can be NULL only if capacity=*length==0.
654 * @param pLength Input: Capacity of destination buffer.
655 * Output: Actual length of the UTF-8 string, not counting the
656 * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR.
657 * Can be NULL, meaning capacity=0 and the string length is not
658 * returned to the caller.
659 * @param forceCopy If TRUE, then the output string will always be written to
660 * dest, with U_BUFFER_OVERFLOW_ERROR and
661 * U_STRING_NOT_TERMINATED_WARNING set if appropriate.
662 * If FALSE, then the dest buffer may or may not contain a
663 * copy of the string. dest may or may not be modified.
664 * If a copy needs to be written, then the UErrorCode parameter
665 * indicates overflow etc. as usual.
666 * @param status Pointer to a standard ICU error code. Its input value must
667 * pass the U_SUCCESS() test, or else the function returns
668 * immediately. Check for U_FAILURE() on output or use with
669 * function chaining. (See User Guide for details.)
670 * @return The pointer to the UTF-8 string. It may be dest, or at some offset
671 * from dest (only if !forceCopy), or in unrelated memory.
672 * Always NUL-terminated unless the string was written to dest and
673 * length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set).
675 * @see ures_getStringByIndex
679 U_STABLE
const char * U_EXPORT2
680 ures_getUTF8StringByIndex(const UResourceBundle
*resB
,
682 char *dest
, int32_t *pLength
,
687 * Returns a resource in a given resource that has a given key. This procedure works only with table
688 * resources. Features a fill-in parameter.
690 * @param resourceBundle a resource
691 * @param key a key associated with the wanted resource
692 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be closed by the caller.
693 * Alternatively, you can supply a struct to be filled by this function.
694 * @param status fills in the outgoing error code.
695 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it
698 U_STABLE UResourceBundle
* U_EXPORT2
699 ures_getByKey(const UResourceBundle
*resourceBundle
,
701 UResourceBundle
*fillIn
,
705 * Returns a string in a given resource that has a given key. This procedure works only with table
708 * @param resB a resource
709 * @param key a key associated with the wanted string
710 * @param len fill in length of the string
711 * @param status fills in the outgoing error code. If an error occured, we may return NULL, but don't
712 * count on it. Check status instead!
713 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
716 U_STABLE
const UChar
* U_EXPORT2
717 ures_getStringByKey(const UResourceBundle
*resB
,
723 * Returns a UTF-8 string from a resource and a key.
724 * This function works only with table resources.
726 * The UTF-8 string may be returnable directly as a pointer, or
727 * it may need to be copied, or transformed from UTF-16 using u_strToUTF8()
730 * If forceCopy==TRUE, then the string is always written to the dest buffer
731 * and dest is returned.
733 * If forceCopy==FALSE, then the string is returned as a pointer if possible,
734 * without needing a dest buffer (it can be NULL). If the string needs to be
735 * copied or transformed, then it may be placed into dest at an arbitrary offset.
737 * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and
738 * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual.
740 * If the string is transformed from UTF-16, then a conversion error may occur
741 * if an unpaired surrogate is encountered. If the function is successful, then
742 * the output UTF-8 string is always well-formed.
744 * @param resB Resource bundle.
745 * @param key A key associated with the wanted resource
746 * @param dest Destination buffer. Can be NULL only if capacity=*length==0.
747 * @param pLength Input: Capacity of destination buffer.
748 * Output: Actual length of the UTF-8 string, not counting the
749 * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR.
750 * Can be NULL, meaning capacity=0 and the string length is not
751 * returned to the caller.
752 * @param forceCopy If TRUE, then the output string will always be written to
753 * dest, with U_BUFFER_OVERFLOW_ERROR and
754 * U_STRING_NOT_TERMINATED_WARNING set if appropriate.
755 * If FALSE, then the dest buffer may or may not contain a
756 * copy of the string. dest may or may not be modified.
757 * If a copy needs to be written, then the UErrorCode parameter
758 * indicates overflow etc. as usual.
759 * @param status Pointer to a standard ICU error code. Its input value must
760 * pass the U_SUCCESS() test, or else the function returns
761 * immediately. Check for U_FAILURE() on output or use with
762 * function chaining. (See User Guide for details.)
763 * @return The pointer to the UTF-8 string. It may be dest, or at some offset
764 * from dest (only if !forceCopy), or in unrelated memory.
765 * Always NUL-terminated unless the string was written to dest and
766 * length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set).
768 * @see ures_getStringByKey
772 U_STABLE
const char * U_EXPORT2
773 ures_getUTF8StringByKey(const UResourceBundle
*resB
,
775 char *dest
, int32_t *pLength
,
779 #if U_SHOW_CPLUSPLUS_API
780 #include "unicode/unistr.h"
784 * returns a string from a string resource type
786 * @param resB a resource
787 * @param status: fills in the outgoing error code
788 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
789 * could be a non-failing error
790 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
791 * @return a UnicodeString object. If there is an error, string is bogus
795 ures_getUnicodeString(const UResourceBundle
*resB
,
799 const UChar
*r
= ures_getString(resB
, &len
, status
);
800 return UnicodeString(TRUE
, r
, len
);
804 * Returns the next string in a resource or NULL if there are no more resources
807 * @param resB a resource
808 * @param key fill in for key associated with this string
809 * @param status fills in the outgoing error code
810 * @return an UnicodeString object.
814 ures_getNextUnicodeString(UResourceBundle
*resB
,
819 const UChar
* r
= ures_getNextString(resB
, &len
, key
, status
);
820 return UnicodeString(TRUE
, r
, len
);
824 * Returns the string in a given resource at the specified index.
826 * @param resB a resource
827 * @param index an index to the wanted string.
828 * @param status fills in the outgoing error code
829 * @return an UnicodeString object. If there is an error, string is bogus
833 ures_getUnicodeStringByIndex(const UResourceBundle
*resB
,
838 const UChar
* r
= ures_getStringByIndex(resB
, indexS
, &len
, status
);
839 return UnicodeString(TRUE
, r
, len
);
843 * Returns a string in a resource that has a given key. This procedure works only with table
846 * @param resB a resource
847 * @param key a key associated with the wanted string
848 * @param status fills in the outgoing error code
849 * @return an UnicodeString object. If there is an error, string is bogus
853 ures_getUnicodeStringByKey(const UResourceBundle
*resB
,
858 const UChar
* r
= ures_getStringByKey(resB
, key
, &len
, status
);
859 return UnicodeString(TRUE
, r
, len
);
867 * Create a string enumerator, owned by the caller, of all locales located within
868 * the specified resource tree.
869 * @param packageName name of the tree, such as (NULL) or U_ICUDATA_ALIAS or or "ICUDATA-coll"
870 * This call is similar to uloc_getAvailable().
871 * @param status error code
874 U_STABLE UEnumeration
* U_EXPORT2
875 ures_openAvailableLocales(const char *packageName
, UErrorCode
*status
);