ICU 74.1 74.1

ures.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 **********************************************************************
5 * Copyright (C) 1997-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
8 *
9 * File URES.H (formerly CRESBUND.H)
10 *
11 * Modification History:
12 *
13 * Date Name Description
14 * 04/01/97 aliu Creation.
15 * 02/22/99 damiba overhaul.
16 * 04/04/99 helena Fixed internal header inclusion.
17 * 04/15/99 Madhu Updated Javadoc
18 * 06/14/99 stephen Removed functions taking a filename suffix.
19 * 07/20/99 stephen Language-independent typedef to void*
20 * 11/09/99 weiv Added ures_getLocale()
21 * 06/24/02 weiv Added support for resource sharing
22 ******************************************************************************
23 */
24
25 #ifndef URES_H
26 #define URES_H
27
28 #include "unicode/char16ptr.h"
29 #include "unicode/utypes.h"
30 #include "unicode/uloc.h"
31
32 #if U_SHOW_CPLUSPLUS_API
33 #include "unicode/localpointer.h"
34 #endif // U_SHOW_CPLUSPLUS_API
35
58 struct UResourceBundle;
59
63 typedef struct UResourceBundle UResourceBundle;
64
70 typedef enum {
72 URES_NONE=-1,
73
75 URES_STRING=0,
76
78 URES_BINARY=1,
79
81 URES_TABLE=2,
82
90 URES_ALIAS=3,
91
99 URES_INT=7,
100
102 URES_ARRAY=8,
103
109 URES_INT_VECTOR = 14,
110 #ifndef U_HIDE_DEPRECATED_API
112 RES_NONE=URES_NONE,
114 RES_STRING=URES_STRING,
116 RES_BINARY=URES_BINARY,
118 RES_TABLE=URES_TABLE,
120 RES_ALIAS=URES_ALIAS,
122 RES_INT=URES_INT,
124 RES_ARRAY=URES_ARRAY,
126 RES_INT_VECTOR=URES_INT_VECTOR,
128 RES_RESERVED=15,
129
134 URES_LIMIT = 16
135 #endif // U_HIDE_DEPRECATED_API
136 } UResType;
137
138 /*
139 * Functions to create and destroy resource bundles.
140 */
141
170 U_CAPI UResourceBundle* U_EXPORT2
171 ures_open(const char* packageName,
172 const char* locale,
173 UErrorCode* status);
174
175
193 U_CAPI UResourceBundle* U_EXPORT2
194 ures_openDirect(const char* packageName,
195 const char* locale,
196 UErrorCode* status);
197
216 U_CAPI UResourceBundle* U_EXPORT2
217 ures_openU(const UChar* packageName,
218 const char* locale,
219 UErrorCode* status);
220
221 #ifndef U_HIDE_DEPRECATED_API
238 U_DEPRECATED int32_t U_EXPORT2
239 ures_countArrayItems(const UResourceBundle* resourceBundle,
240 const char* resourceKey,
241 UErrorCode* err);
242 #endif /* U_HIDE_DEPRECATED_API */
243
252 U_CAPI void U_EXPORT2
253 ures_close(UResourceBundle* resourceBundle);
254
255 #if U_SHOW_CPLUSPLUS_API
256
257 U_NAMESPACE_BEGIN
258
268 U_DEFINE_LOCAL_OPEN_POINTER(LocalUResourceBundlePointer, UResourceBundle, ures_close);
269
270 U_NAMESPACE_END
271
272 #endif
273
274 #ifndef U_HIDE_DEPRECATED_API
285 U_DEPRECATED const char* U_EXPORT2
286 ures_getVersionNumber(const UResourceBundle* resourceBundle);
287 #endif /* U_HIDE_DEPRECATED_API */
288
298 U_CAPI void U_EXPORT2
299 ures_getVersion(const UResourceBundle* resB,
300 UVersionInfo versionInfo);
301
302 #ifndef U_HIDE_DEPRECATED_API
315 U_DEPRECATED const char* U_EXPORT2
316 ures_getLocale(const UResourceBundle* resourceBundle,
317 UErrorCode* status);
318 #endif /* U_HIDE_DEPRECATED_API */
319
332 U_CAPI const char* U_EXPORT2
333 ures_getLocaleByType(const UResourceBundle* resourceBundle,
334 ULocDataLocaleType type,
335 UErrorCode* status);
336
337
338 #ifndef U_HIDE_INTERNAL_API
355 U_CAPI void U_EXPORT2
356 ures_openFillIn(UResourceBundle *r,
357 const char* packageName,
358 const char* localeID,
359 UErrorCode* status);
360 #endif /* U_HIDE_INTERNAL_API */
361
379 U_CAPI const UChar* U_EXPORT2
380 ures_getString(const UResourceBundle* resourceBundle,
381 int32_t* len,
382 UErrorCode* status);
383
431 U_CAPI const char * U_EXPORT2
432 ures_getUTF8String(const UResourceBundle *resB,
433 char *dest, int32_t *length,
434 UBool forceCopy,
435 UErrorCode *status);
436
454 U_CAPI const uint8_t* U_EXPORT2
455 ures_getBinary(const UResourceBundle* resourceBundle,
456 int32_t* len,
457 UErrorCode* status);
458
476 U_CAPI const int32_t* U_EXPORT2
477 ures_getIntVector(const UResourceBundle* resourceBundle,
478 int32_t* len,
479 UErrorCode* status);
480
497 U_CAPI uint32_t U_EXPORT2
498 ures_getUInt(const UResourceBundle* resourceBundle,
499 UErrorCode *status);
500
517 U_CAPI int32_t U_EXPORT2
518 ures_getInt(const UResourceBundle* resourceBundle,
519 UErrorCode *status);
520
531 U_CAPI int32_t U_EXPORT2
532 ures_getSize(const UResourceBundle *resourceBundle);
533
542 U_CAPI UResType U_EXPORT2
543 ures_getType(const UResourceBundle *resourceBundle);
544
553 U_CAPI const char * U_EXPORT2
554 ures_getKey(const UResourceBundle *resourceBundle);
555
556 /* ITERATION API
557 This API provides means for iterating through a resource
558 */
559
566 U_CAPI void U_EXPORT2
567 ures_resetIterator(UResourceBundle *resourceBundle);
568
576 U_CAPI UBool U_EXPORT2
577 ures_hasNext(const UResourceBundle *resourceBundle);
578
591 U_CAPI UResourceBundle* U_EXPORT2
592 ures_getNextResource(UResourceBundle *resourceBundle,
593 UResourceBundle *fillIn,
594 UErrorCode *status);
595
608 U_CAPI const UChar* U_EXPORT2
609 ures_getNextString(UResourceBundle *resourceBundle,
610 int32_t* len,
611 const char ** key,
612 UErrorCode *status);
613
626 U_CAPI UResourceBundle* U_EXPORT2
627 ures_getByIndex(const UResourceBundle *resourceBundle,
628 int32_t indexR,
629 UResourceBundle *fillIn,
630 UErrorCode *status);
631
643 U_CAPI const UChar* U_EXPORT2
644 ures_getStringByIndex(const UResourceBundle *resourceBundle,
645 int32_t indexS,
646 int32_t* len,
647 UErrorCode *status);
648
697 U_CAPI const char * U_EXPORT2
698 ures_getUTF8StringByIndex(const UResourceBundle *resB,
699 int32_t stringIndex,
700 char *dest, int32_t *pLength,
701 UBool forceCopy,
702 UErrorCode *status);
703
716 U_CAPI UResourceBundle* U_EXPORT2
717 ures_getByKey(const UResourceBundle *resourceBundle,
718 const char* key,
719 UResourceBundle *fillIn,
720 UErrorCode *status);
721
734 U_CAPI const UChar* U_EXPORT2
735 ures_getStringByKey(const UResourceBundle *resB,
736 const char* key,
737 int32_t* len,
738 UErrorCode *status);
739
790 U_CAPI const char * U_EXPORT2
791 ures_getUTF8StringByKey(const UResourceBundle *resB,
792 const char *key,
793 char *dest, int32_t *pLength,
794 UBool forceCopy,
795 UErrorCode *status);
796
797 #if U_SHOW_CPLUSPLUS_API
798 #include "unicode/unistr.h"
799
800 U_NAMESPACE_BEGIN
812 inline UnicodeString
813 ures_getUnicodeString(const UResourceBundle *resB, UErrorCode* status) {
814 UnicodeString result;
815 int32_t len = 0;
816 const char16_t *r = ConstChar16Ptr(ures_getString(resB, &len, status));
817 if(U_SUCCESS(*status)) {
818 result.setTo(true, r, len);
819 } else {
820 result.setToBogus();
821 }
822 return result;
823 }
824
837 inline UnicodeString
838 ures_getNextUnicodeString(UResourceBundle *resB, const char ** key, UErrorCode* status) {
839 UnicodeString result;
840 int32_t len = 0;
841 const char16_t* r = ConstChar16Ptr(ures_getNextString(resB, &len, key, status));
842 if(U_SUCCESS(*status)) {
843 result.setTo(true, r, len);
844 } else {
845 result.setToBogus();
846 }
847 return result;
848 }
849
859 inline UnicodeString
860 ures_getUnicodeStringByIndex(const UResourceBundle *resB, int32_t indexS, UErrorCode* status) {
861 UnicodeString result;
862 int32_t len = 0;
863 const char16_t* r = ConstChar16Ptr(ures_getStringByIndex(resB, indexS, &len, status));
864 if(U_SUCCESS(*status)) {
865 result.setTo(true, r, len);
866 } else {
867 result.setToBogus();
868 }
869 return result;
870 }
871
882 inline UnicodeString
883 ures_getUnicodeStringByKey(const UResourceBundle *resB, const char* key, UErrorCode* status) {
884 UnicodeString result;
885 int32_t len = 0;
886 const char16_t* r = ConstChar16Ptr(ures_getStringByKey(resB, key, &len, status));
887 if(U_SUCCESS(*status)) {
888 result.setTo(true, r, len);
889 } else {
890 result.setToBogus();
891 }
892 return result;
893 }
894
895 U_NAMESPACE_END
896
897 #endif
898
907 U_CAPI UEnumeration* U_EXPORT2
908 ures_openAvailableLocales(const char *packageName, UErrorCode *status);
909
910
911 #endif /*_URES*/
912 /*eof*/
char16ptr.h
C++ API: char16_t pointer wrappers with implicit conversion from bit-compatible raw pointer types.
LocalUResourceBundlePointer
"Smart pointer" class, closes a UResourceBundle via ures_close().
icu::ConstChar16Ptr
const char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types.
Definition: char16ptr.h:149
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
icu::UnicodeString::setToBogus
void setToBogus()
Make this UnicodeString object invalid.
icu::UnicodeString::setTo
UnicodeString & setTo(const UnicodeString &srcText, int32_t srcStart)
Set the text in the UnicodeString object to the characters in srcText in the range [srcStart,...
Definition: unistr.h:4612
localpointer.h
C++ API: "Smart pointers" for use with and in ICU4C C++ code.
U_DEFINE_LOCAL_OPEN_POINTER
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
Definition: localpointer.h:550
icu::ures_getUnicodeString
UnicodeString ures_getUnicodeString(const UResourceBundle *resB, UErrorCode *status)
Returns the string value from a string resource bundle.
Definition: ures.h:813
icu::ures_getUnicodeStringByIndex
UnicodeString ures_getUnicodeStringByIndex(const UResourceBundle *resB, int32_t indexS, UErrorCode *status)
Returns the string in a given resource array or table at the specified index.
Definition: ures.h:860
icu::ures_getNextUnicodeString
UnicodeString ures_getNextUnicodeString(UResourceBundle *resB, const char **key, UErrorCode *status)
Returns the next string in a resource, or an empty string if there are no more resources to iterate o...
Definition: ures.h:838
icu::ures_getUnicodeStringByKey
UnicodeString ures_getUnicodeStringByKey(const UResourceBundle *resB, const char *key, UErrorCode *status)
Returns a string in a resource that has a given key.
Definition: ures.h:883
UEnumeration
struct UEnumeration UEnumeration
structure representing an enumeration object instance
Definition: uenum.h:44
uloc.h
C API: Locale ID functionality similar to C++ class Locale.
ULocDataLocaleType
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
Definition: uloc.h:338
U_DEPRECATED
#define U_DEPRECATED
This is used to declare a function as a deprecated public ICU C API
Definition: umachine.h:116
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
U_CAPI
#define U_CAPI
This is used to declare a function as a public ICU C API.
Definition: umachine.h:110
UChar
char16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:386
unistr.h
C++ API: Unicode String.
ures_countArrayItems
int32_t ures_countArrayItems(const UResourceBundle *resourceBundle, const char *resourceKey, UErrorCode *err)
Returns the number of strings/arrays in resource bundles.
ures_getInt
U_CAPI int32_t ures_getInt(const UResourceBundle *resourceBundle, UErrorCode *status)
Returns a signed integer from a resource.
ures_getSize
U_CAPI int32_t ures_getSize(const UResourceBundle *resourceBundle)
Returns the size of a resource.
ures_openDirect
U_CAPI UResourceBundle * ures_openDirect(const char *packageName, const char *locale, UErrorCode *status)
This function does not care what kind of localeID is passed in.
ures_getVersionNumber
const char * ures_getVersionNumber(const UResourceBundle *resourceBundle)
Return the version number associated with this ResourceBundle as a string.
ures_resetIterator
U_CAPI void ures_resetIterator(UResourceBundle *resourceBundle)
Resets the internal context of a resource so that iteration starts from the first element.
ures_open
U_CAPI UResourceBundle * ures_open(const char *packageName, const char *locale, UErrorCode *status)
Opens a UResourceBundle, from which users can extract strings by using their corresponding keys.
UResType
UResType
Numeric constants for types of resource items.
Definition: ures.h:70
RES_BINARY
@ RES_BINARY
Definition: ures.h:116
URES_TABLE
@ URES_TABLE
Resource type constant for tables of key-value pairs.
Definition: ures.h:81
RES_ARRAY
@ RES_ARRAY
Definition: ures.h:124
URES_ALIAS
@ URES_ALIAS
Resource type constant for aliases; internally stores a string which identifies the actual resource s...
Definition: ures.h:90
URES_INT_VECTOR
@ URES_INT_VECTOR
Resource type constant for vectors of 32-bit integers.
Definition: ures.h:109
URES_BINARY
@ URES_BINARY
Resource type constant for binary data.
Definition: ures.h:78
RES_NONE
@ RES_NONE
Definition: ures.h:112
URES_ARRAY
@ URES_ARRAY
Resource type constant for arrays of resources.
Definition: ures.h:102
URES_NONE
@ URES_NONE
Resource type constant for "no resource".
Definition: ures.h:72
RES_RESERVED
@ RES_RESERVED
Definition: ures.h:128
URES_STRING
@ URES_STRING
Resource type constant for 16-bit Unicode strings.
Definition: ures.h:75
RES_INT_VECTOR
@ RES_INT_VECTOR
Definition: ures.h:126
URES_INT
@ URES_INT
Resource type constant for a single 28-bit integer, interpreted as signed or unsigned by the ures_get...
Definition: ures.h:99
RES_TABLE
@ RES_TABLE
Definition: ures.h:118
RES_STRING
@ RES_STRING
Definition: ures.h:114
RES_ALIAS
@ RES_ALIAS
Definition: ures.h:120
RES_INT
@ RES_INT
Definition: ures.h:122
URES_LIMIT
@ URES_LIMIT
One more than the highest normal UResType value.
Definition: ures.h:134
ures_getType
U_CAPI UResType ures_getType(const UResourceBundle *resourceBundle)
Returns the type of a resource.
ures_hasNext
U_CAPI UBool ures_hasNext(const UResourceBundle *resourceBundle)
Checks whether the given resource has another element to iterate over.
ures_close
U_CAPI void ures_close(UResourceBundle *resourceBundle)
Close a resource bundle, all pointers returned from the various ures_getXXX calls on this particular ...
ures_openAvailableLocales
U_CAPI UEnumeration * ures_openAvailableLocales(const char *packageName, UErrorCode *status)
Create a string enumerator, owned by the caller, of all locales located within the specified resource...
ures_getBinary
U_CAPI const uint8_t * ures_getBinary(const UResourceBundle *resourceBundle, int32_t *len, UErrorCode *status)
Returns a binary data from a binary resource.
ures_getIntVector
U_CAPI const int32_t * ures_getIntVector(const UResourceBundle *resourceBundle, int32_t *len, UErrorCode *status)
Returns a 32 bit integer array from a resource.
ures_getUTF8StringByKey
U_CAPI const char * ures_getUTF8StringByKey(const UResourceBundle *resB, const char *key, char *dest, int32_t *pLength, UBool forceCopy, UErrorCode *status)
Returns a UTF-8 string from a resource and a key.
UResourceBundle
struct UResourceBundle UResourceBundle
Definition: ures.h:63
ures_getUTF8StringByIndex
U_CAPI const char * ures_getUTF8StringByIndex(const UResourceBundle *resB, int32_t stringIndex, char *dest, int32_t *pLength, UBool forceCopy, UErrorCode *status)
Returns a UTF-8 string from a resource at the specified index.
ures_getLocale
const char * ures_getLocale(const UResourceBundle *resourceBundle, UErrorCode *status)
Return the name of the Locale associated with this ResourceBundle.
ures_openU
U_CAPI UResourceBundle * ures_openU(const UChar *packageName, const char *locale, UErrorCode *status)
Same as ures_open() but takes a const UChar *path.
ures_getUTF8String
U_CAPI const char * ures_getUTF8String(const UResourceBundle *resB, char *dest, int32_t *length, UBool forceCopy, UErrorCode *status)
Returns a UTF-8 string from a string resource.
ures_openFillIn
U_CAPI void ures_openFillIn(UResourceBundle *r, const char *packageName, const char *localeID, UErrorCode *status)
Same as ures_open() but uses the fill-in parameter instead of allocating a new bundle.
ures_getLocaleByType
U_CAPI const char * ures_getLocaleByType(const UResourceBundle *resourceBundle, ULocDataLocaleType type, UErrorCode *status)
Return the name of the Locale associated with this ResourceBundle.
ures_getKey
U_CAPI const char * ures_getKey(const UResourceBundle *resourceBundle)
Returns the key associated with a given resource.
ures_getUInt
U_CAPI uint32_t ures_getUInt(const UResourceBundle *resourceBundle, UErrorCode *status)
Returns an unsigned integer from a resource.
ures_getNextResource
U_CAPI UResourceBundle * ures_getNextResource(UResourceBundle *resourceBundle, UResourceBundle *fillIn, UErrorCode *status)
Returns the next resource in a given resource or NULL if there are no more resources to iterate over.
ures_getByKey
U_CAPI UResourceBundle * ures_getByKey(const UResourceBundle *resourceBundle, const char *key, UResourceBundle *fillIn, UErrorCode *status)
Returns a resource in a given resource that has a given key.
ures_getStringByIndex
U_CAPI const UChar * ures_getStringByIndex(const UResourceBundle *resourceBundle, int32_t indexS, int32_t *len, UErrorCode *status)
Returns the string in a given resource at the specified index.
ures_getNextString
U_CAPI const UChar * ures_getNextString(UResourceBundle *resourceBundle, int32_t *len, const char **key, UErrorCode *status)
Returns the next string in a given resource or NULL if there are no more resources to iterate over.
ures_getByIndex
U_CAPI UResourceBundle * ures_getByIndex(const UResourceBundle *resourceBundle, int32_t indexR, UResourceBundle *fillIn, UErrorCode *status)
Returns the resource in a given resource at the specified index.
ures_getVersion
U_CAPI void ures_getVersion(const UResourceBundle *resB, UVersionInfo versionInfo)
Return the version number associated with this ResourceBundle as an UVersionInfo array.
ures_getString
U_CAPI const UChar * ures_getString(const UResourceBundle *resourceBundle, int32_t *len, UErrorCode *status)
Returns a string from a string resource type.
ures_getStringByKey
U_CAPI const UChar * ures_getStringByKey(const UResourceBundle *resB, const char *key, int32_t *len, UErrorCode *status)
Returns a string in a given resource that has a given key.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
U_SUCCESS
#define U_SUCCESS(x)
Does the error code indicate success?
Definition: utypes.h:712
UVersionInfo
uint8_t UVersionInfo[U_MAX_VERSION_LENGTH]
The binary form of a version on ICU APIs is an array of 4 uint8_t.
Definition: uversion.h:59