ICU 75.1 75.1
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions
icu::ResourceBundle Class Reference

A class representing a collection of resource information pertaining to a given locale. More...

#include <resbund.h>

Inheritance diagram for icu::ResourceBundle:
icu::UObject icu::UMemory

Public Member Functions

 ResourceBundle (const UnicodeString &packageName, const Locale &locale, UErrorCode &err)
 Constructor.
 
 ResourceBundle (const UnicodeString &packageName, UErrorCode &err)
 Construct a resource bundle for the default bundle in the specified package.
 
 ResourceBundle (UErrorCode &err)
 Construct a resource bundle for the ICU default bundle.
 
 ResourceBundle (const char *packageName, const Locale &locale, UErrorCode &err)
 Standard constructor, constructs a resource bundle for the locale-specific bundle in the specified package.
 
 ResourceBundle (const ResourceBundle &original)
 Copy constructor.
 
 ResourceBundle (UResourceBundle *res, UErrorCode &status)
 Constructor from a C UResourceBundle.
 
ResourceBundleoperator= (const ResourceBundle &other)
 Assignment operator.
 
virtual ~ResourceBundle ()
 Destructor.
 
ResourceBundleclone () const
 Clone this object.
 
int32_t getSize () const
 Returns the size of a resource.
 
UnicodeString getString (UErrorCode &status) const
 returns a string from a string resource type
 
const uint8_tgetBinary (int32_t &len, UErrorCode &status) const
 returns a binary data from a resource.
 
const int32_tgetIntVector (int32_t &len, UErrorCode &status) const
 returns an integer vector from a resource.
 
uint32_t getUInt (UErrorCode &status) const
 returns an unsigned integer from a resource.
 
int32_t getInt (UErrorCode &status) const
 returns a signed integer from a resource.
 
UBool hasNext () const
 Checks whether the resource has another element to iterate over.
 
void resetIterator ()
 Resets the internal context of a resource so that iteration starts from the first element.
 
const chargetKey () const
 Returns the key associated with this resource.
 
const chargetName () const
 Gets the locale ID of the resource bundle as a string.
 
UResType getType () const
 Returns the type of a resource.
 
ResourceBundle getNext (UErrorCode &status)
 Returns the next resource in a given resource or nullptr if there are no more resources.
 
UnicodeString getNextString (UErrorCode &status)
 Returns the next string in a resource or nullptr if there are no more resources to iterate over.
 
UnicodeString getNextString (const char **key, UErrorCode &status)
 Returns the next string in a resource or nullptr if there are no more resources to iterate over.
 
ResourceBundle get (int32_t index, UErrorCode &status) const
 Returns the resource in a resource at the specified index.
 
UnicodeString getStringEx (int32_t index, UErrorCode &status) const
 Returns the string in a given resource at the specified index.
 
ResourceBundle get (const char *key, UErrorCode &status) const
 Returns a resource in a resource that has a given key.
 
UnicodeString getStringEx (const char *key, UErrorCode &status) const
 Returns a string in a resource that has a given key.
 
const chargetVersionNumber () const
 Return the version number associated with this ResourceBundle as a string.
 
void getVersion (UVersionInfo versionInfo) const
 Return the version number associated with this ResourceBundle as a UVersionInfo array.
 
const LocalegetLocale () const
 Return the Locale associated with this ResourceBundle.
 
const Locale getLocale (ULocDataLocaleType type, UErrorCode &status) const
 Return the Locale associated with this ResourceBundle.
 
ResourceBundle getWithFallback (const char *key, UErrorCode &status)
 This API implements multilevel fallback.
 
virtual UClassID getDynamicClassID () const override
 ICU "poor man's RTTI", returns a UClassID for the actual class.
 
- Public Member Functions inherited from icu::UObject
virtual ~UObject ()
 Destructor.
 

Static Public Member Functions

static UClassID getStaticClassID ()
 ICU "poor man's RTTI", returns a UClassID for this class.
 

Detailed Description

A class representing a collection of resource information pertaining to a given locale.

A resource bundle provides a way of accessing locale- specific information in a data file. You create a resource bundle that manages the resources for a given locale and then ask it for individual resources.

Resource bundles in ICU4C are currently defined using text files which conform to the following BNF definition. More on resource bundle concepts and syntax can be found in the Users Guide.

The ResourceBundle class is not suitable for subclassing.

Stable:
ICU 2.0

Definition at line 83 of file resbund.h.

Constructor & Destructor Documentation

◆ ResourceBundle() [1/6]

icu::ResourceBundle::ResourceBundle ( const UnicodeString packageName,
const Locale locale,
UErrorCode err 
)

Constructor.

Parameters
packageNameThe packageName and locale together point to an ICU udata object, as defined by udata_open( packageName, "res", locale, err) or equivalent. Typically, packageName will refer to a (.dat) file, or to a package registered with udata_setAppData(). Using a full file or directory pathname for packageName is deprecated.
localeThis is the locale this resource bundle is for. To get resources for the French locale, for example, you would create a ResourceBundle passing Locale::FRENCH for the "locale" parameter, and all subsequent calls to that resource bundle will return resources that pertain to the French locale. If the caller doesn't pass a locale parameter, the default locale for the system (as returned by Locale::getDefault()) will be used.
errThe Error Code. The UErrorCode& err parameter is used to return status information to the user. To check whether the construction succeeded or not, you should check the value of U_SUCCESS(err). If you wish more detailed information, you can check for informational error results which still indicate success. U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For example, 'de_CH' was requested, but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that the default locale data was used; neither the requested locale nor any of its fall back locales could be found.
Stable:
ICU 2.0

◆ ResourceBundle() [2/6]

icu::ResourceBundle::ResourceBundle ( const UnicodeString packageName,
UErrorCode err 
)

Construct a resource bundle for the default bundle in the specified package.

Parameters
packageNameThe packageName and locale together point to an ICU udata object, as defined by udata_open( packageName, "res", locale, err) or equivalent. Typically, packageName will refer to a (.dat) file, or to a package registered with udata_setAppData(). Using a full file or directory pathname for packageName is deprecated.
errA UErrorCode value
Stable:
ICU 2.0

◆ ResourceBundle() [3/6]

icu::ResourceBundle::ResourceBundle ( UErrorCode err)

Construct a resource bundle for the ICU default bundle.

Parameters
errA UErrorCode value
Stable:
ICU 2.0

◆ ResourceBundle() [4/6]

icu::ResourceBundle::ResourceBundle ( const char packageName,
const Locale locale,
UErrorCode err 
)

Standard constructor, constructs a resource bundle for the locale-specific bundle in the specified package.

Parameters
packageNameThe packageName and locale together point to an ICU udata object, as defined by udata_open( packageName, "res", locale, err) or equivalent. Typically, packageName will refer to a (.dat) file, or to a package registered with udata_setAppData(). Using a full file or directory pathname for packageName is deprecated. nullptr is used to refer to ICU data.
localeThe locale for which to open a resource bundle.
errA UErrorCode value
Stable:
ICU 2.0

◆ ResourceBundle() [5/6]

icu::ResourceBundle::ResourceBundle ( const ResourceBundle original)

Copy constructor.

Parameters
originalThe resource bundle to copy.
Stable:
ICU 2.0

◆ ResourceBundle() [6/6]

icu::ResourceBundle::ResourceBundle ( UResourceBundle res,
UErrorCode status 
)

Constructor from a C UResourceBundle.

The resource bundle is copied and not adopted. ures_close will still need to be used on the original resource bundle.

Parameters
resA pointer to the C resource bundle.
statusA UErrorCode value.
Stable:
ICU 2.0

◆ ~ResourceBundle()

virtual icu::ResourceBundle::~ResourceBundle ( )
virtual

Destructor.

Stable:
ICU 2.0

Member Function Documentation

◆ clone()

ResourceBundle * icu::ResourceBundle::clone ( ) const

Clone this object.

Clones can be used concurrently in multiple threads. If an error occurs, then nullptr is returned. The caller must delete the clone.

Returns
a clone of this object
See also
getDynamicClassID
Stable:
ICU 2.8

◆ get() [1/2]

ResourceBundle icu::ResourceBundle::get ( const char key,
UErrorCode status 
) const

Returns a resource in a resource that has a given key.

This procedure works only with table resources.

Parameters
keya key associated with the wanted resource
statusfills in the outgoing error code.
Returns
ResourceBundle object. If there is an error, resource is invalid.
Stable:
ICU 2.0

◆ get() [2/2]

ResourceBundle icu::ResourceBundle::get ( int32_t  index,
UErrorCode status 
) const

Returns the resource in a resource at the specified index.

Parameters
indexan index to the wanted resource.
statusfills in the outgoing error code
Returns
ResourceBundle object. If there is an error, resource is invalid.
Stable:
ICU 2.0

◆ getBinary()

const uint8_t * icu::ResourceBundle::getBinary ( int32_t len,
UErrorCode status 
) const

returns a binary data from a resource.

Can be used at most primitive resource types (binaries, strings, ints)

Parameters
lenfills in the length of resulting byte chunk
statusfills in the outgoing error code could be U_MISSING_RESOURCE_ERROR if the key is not found could be a warning e.g.: U_USING_FALLBACK_WARNING,U_USING_DEFAULT_WARNING
Returns
a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.
Stable:
ICU 2.0

◆ getDynamicClassID()

virtual UClassID icu::ResourceBundle::getDynamicClassID ( ) const
overridevirtual

ICU "poor man's RTTI", returns a UClassID for the actual class.

Stable:
ICU 2.2

Reimplemented from icu::UObject.

◆ getInt()

int32_t icu::ResourceBundle::getInt ( UErrorCode status) const

returns a signed integer from a resource.

This integer is originally 28 bit and the sign gets propagated.

Parameters
statusfills in the outgoing error code could be U_MISSING_RESOURCE_ERROR if the key is not found could be a warning e.g.: U_USING_FALLBACK_WARNING,U_USING_DEFAULT_WARNING
Returns
a signed integer value
Stable:
ICU 2.0

◆ getIntVector()

const int32_t * icu::ResourceBundle::getIntVector ( int32_t len,
UErrorCode status 
) const

returns an integer vector from a resource.

Parameters
lenfills in the length of resulting integer vector
statusfills in the outgoing error code could be U_MISSING_RESOURCE_ERROR if the key is not found could be a warning e.g.: U_USING_FALLBACK_WARNING,U_USING_DEFAULT_WARNING
Returns
a pointer to a vector of integers that lives in a memory mapped/DLL file.
Stable:
ICU 2.0

◆ getKey()

const char * icu::ResourceBundle::getKey ( ) const

Returns the key associated with this resource.

Not all the resources have a key - only those that are members of a table.

Returns
a key associated to this resource, or nullptr if it doesn't have a key
Stable:
ICU 2.0

◆ getLocale() [1/2]

const Locale & icu::ResourceBundle::getLocale ( ) const

Return the Locale associated with this ResourceBundle.

Returns
a Locale object
Deprecated:
ICU 2.8 Use getLocale(ULocDataLocaleType type, UErrorCode &status) overload instead.

◆ getLocale() [2/2]

const Locale icu::ResourceBundle::getLocale ( ULocDataLocaleType  type,
UErrorCode status 
) const

Return the Locale associated with this ResourceBundle.

Parameters
typeYou can choose between requested, valid and actual locale. For description see the definition of ULocDataLocaleType in uloc.h
statusjust for catching illegal arguments
Returns
a Locale object
Stable:
ICU 2.8

◆ getName()

const char * icu::ResourceBundle::getName ( ) const

Gets the locale ID of the resource bundle as a string.

Same as getLocale().getName() .

Returns
the locale ID of the resource bundle as a string
Stable:
ICU 2.0

◆ getNext()

ResourceBundle icu::ResourceBundle::getNext ( UErrorCode status)

Returns the next resource in a given resource or nullptr if there are no more resources.

Parameters
statusfills in the outgoing error code
Returns
ResourceBundle object.
Stable:
ICU 2.0

◆ getNextString() [1/2]

UnicodeString icu::ResourceBundle::getNextString ( const char **  key,
UErrorCode status 
)

Returns the next string in a resource or nullptr if there are no more resources to iterate over.

Parameters
keyfill in for key associated with this string
statusfills in the outgoing error code
Returns
an UnicodeString object.
Stable:
ICU 2.0

◆ getNextString() [2/2]

UnicodeString icu::ResourceBundle::getNextString ( UErrorCode status)

Returns the next string in a resource or nullptr if there are no more resources to iterate over.

Parameters
statusfills in the outgoing error code
Returns
an UnicodeString object.
Stable:
ICU 2.0

◆ getSize()

int32_t icu::ResourceBundle::getSize ( ) const

Returns the size of a resource.

Size for scalar types is always 1, and for vector/table types is the number of child resources.

Warning
Integer array is treated as a scalar type. There are no APIs to access individual members of an integer array. It is always returned as a whole.
Returns
number of resources in a given resource.
Stable:
ICU 2.0

◆ getStaticClassID()

static UClassID icu::ResourceBundle::getStaticClassID ( )
static

ICU "poor man's RTTI", returns a UClassID for this class.

Stable:
ICU 2.2

◆ getString()

UnicodeString icu::ResourceBundle::getString ( UErrorCode status) const

returns a string from a string resource type

Parameters
statusfills in the outgoing error code could be U_MISSING_RESOURCE_ERROR if the key is not found could be a warning e.g.: U_USING_FALLBACK_WARNING,U_USING_DEFAULT_WARNING
Returns
a pointer to a zero-terminated char16_t array which lives in a memory mapped/DLL file.
Stable:
ICU 2.0

◆ getStringEx() [1/2]

UnicodeString icu::ResourceBundle::getStringEx ( const char key,
UErrorCode status 
) const

Returns a string in a resource that has a given key.

This procedure works only with table resources.

Parameters
keya key associated with the wanted string
statusfills in the outgoing error code
Returns
an UnicodeString object. If there is an error, string is bogus
Stable:
ICU 2.0

◆ getStringEx() [2/2]

UnicodeString icu::ResourceBundle::getStringEx ( int32_t  index,
UErrorCode status 
) const

Returns the string in a given resource at the specified index.

Parameters
indexan index to the wanted string.
statusfills in the outgoing error code
Returns
an UnicodeString object. If there is an error, string is bogus
Stable:
ICU 2.0

◆ getType()

UResType icu::ResourceBundle::getType ( ) const

Returns the type of a resource.

Available types are defined in enum UResType

Returns
type of the given resource.
Stable:
ICU 2.0

◆ getUInt()

uint32_t icu::ResourceBundle::getUInt ( UErrorCode status) const

returns an unsigned integer from a resource.

This integer is originally 28 bits.

Parameters
statusfills in the outgoing error code could be U_MISSING_RESOURCE_ERROR if the key is not found could be a warning e.g.: U_USING_FALLBACK_WARNING,U_USING_DEFAULT_WARNING
Returns
an unsigned integer value
Stable:
ICU 2.0

◆ getVersion()

void icu::ResourceBundle::getVersion ( UVersionInfo  versionInfo) const

Return the version number associated with this ResourceBundle as a UVersionInfo array.

Parameters
versionInfoA UVersionInfo array that is filled with the version number as specified in the resource bundle or its parent.
Stable:
ICU 2.0

◆ getVersionNumber()

const char * icu::ResourceBundle::getVersionNumber ( ) const

Return the version number associated with this ResourceBundle as a string.

Please use getVersion, as this method is going to be deprecated.

Returns
A version number string as specified in the resource bundle or its parent. The caller does not own this string.
See also
getVersion
Deprecated:
ICU 2.8 Use getVersion instead.

◆ getWithFallback()

ResourceBundle icu::ResourceBundle::getWithFallback ( const char key,
UErrorCode status 
)

This API implements multilevel fallback.

Internal:
Do not use. This API is for internal use only.

◆ hasNext()

UBool icu::ResourceBundle::hasNext ( ) const

Checks whether the resource has another element to iterate over.

Returns
true if there are more elements, false if there is no more elements
Stable:
ICU 2.0

◆ operator=()

ResourceBundle & icu::ResourceBundle::operator= ( const ResourceBundle other)

Assignment operator.

Parameters
otherThe resource bundle to copy.
Stable:
ICU 2.0

◆ resetIterator()

void icu::ResourceBundle::resetIterator ( )

Resets the internal context of a resource so that iteration starts from the first element.

Stable:
ICU 2.0

The documentation for this class was generated from the following file: