#include <resbund.h>
Public Methods | |
ResourceBundle (const UnicodeString &path, const Locale &locale, UErrorCode &err) | |
Constructor. More... | |
ResourceBundle (const UnicodeString &path, UErrorCode &err) | |
Construct a resource bundle for the root bundle in the specified path. More... | |
ResourceBundle (UErrorCode &err) | |
Construct a resource bundle for the ICU root bundle. More... | |
ResourceBundle (const wchar_t *path, const Locale &locale, UErrorCode &err) | |
Constructs a ResourceBundle. More... | |
ResourceBundle (const char *path, const Locale &locale, UErrorCode &err) | |
Standard constructor, onstructs a resource bundle for the locale-specific bundle in the specified path. More... | |
ResourceBundle (const ResourceBundle &original) | |
Copy constructor. More... | |
ResourceBundle (UResourceBundle *res, UErrorCode &status) | |
Constructor from a C UResourceBundle. More... | |
ResourceBundle & | operator= (const ResourceBundle &other) |
Assignment operator. More... | |
~ResourceBundle () | |
Destructor. More... | |
int32_t | getSize (void) const |
Returns the size of a resource. More... | |
UnicodeString | getString (UErrorCode &status) const |
returns a string from a string resource type. More... | |
const uint8_t * | getBinary (int32_t &len, UErrorCode &status) const |
returns a binary data from a resource. More... | |
const int32_t * | getIntVector (int32_t &len, UErrorCode &status) const |
returns an integer vector from a resource. More... | |
uint32_t | getUInt (UErrorCode &status) const |
returns an unsigned integer from a resource. More... | |
int32_t | getInt (UErrorCode &status) const |
returns a signed integer from a resource. More... | |
UBool | hasNext (void) const |
Checks whether the resource has another element to iterate over. More... | |
void | resetIterator (void) |
Resets the internal context of a resource so that iteration starts from the first element. More... | |
const char * | getKey (void) |
Returns the key associated with this resource. More... | |
const char * | getName (void) |
Gets the locale ID of the resource bundle as a string. More... | |
UResType | getType (void) |
Returns the type of a resource. More... | |
ResourceBundle | getNext (UErrorCode &status) |
Returns the next resource in a given resource or NULL if there are no more resources. More... | |
UnicodeString | getNextString (UErrorCode &status) |
Returns the next string in a resource or NULL if there are no more resources to iterate over. More... | |
UnicodeString | getNextString (const char **key, UErrorCode &status) |
Returns the next string in a resource or NULL if there are no more resources to iterate over. More... | |
ResourceBundle | get (int32_t index, UErrorCode &status) const |
Returns the resource in a resource at the specified index. More... | |
UnicodeString | getStringEx (int32_t index, UErrorCode &status) const |
Returns the string in a given resource at the specified index. More... | |
ResourceBundle | get (const char *key, UErrorCode &status) const |
Returns a resource in a resource that has a given key. More... | |
UnicodeString | getStringEx (const char *key, UErrorCode &status) const |
Returns a string in a resource that has a given key. More... | |
const char * | getVersionNumber (void) const |
Return the version number associated with this ResourceBundle as a string. More... | |
void | getVersion (UVersionInfo versionInfo) const |
Return the version number associated with this ResourceBundle as a UVersionInfo array. More... | |
const Locale & | getLocale (void) const |
Return the Locale associated with this ResourceBundle. More... |
A resource bundle provides a way of accessing locale- specfic 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.
The resource bundle file is a text (ASCII or Unicode) file with the format:
The tags are used to retrieve the data later. You may not have multiple instances of the same tag.locale { tag1 {...} tag2 {...} }
Four data types are supported. These are solitary strings, comma-delimited lists of strings, 2-dimensional arrays of strings, and tagged lists of strings.
Note that all data is textual. Adjacent strings are merged by the low-level tokenizer, so that the following effects occur: foo bar, baz // 2 elements, "foo bar", and "baz" "foo" "bar", baz // 2 elements, "foobar", and "baz" Note that a single intervening space is added between merged strings, unless they are both double quoted. This extends to more than two strings in a row.
Whitespace is ignored, as in a C source file.
Solitary strings have the format:
This is indistinguishable from a comma-delimited list with only one element, and in fact may be retrieved as such (as an array, or as element 0 or an array).Tag { Data }
Comma-delimited lists have the format:
Parsing is lenient; a final string, after the last element, is allowed.Tag { Data, Data, Data }
Tagged lists have the format:
Data is retrieved by specifying the subtag.Tag { Subtag { Data } Subtag {Data} }
Two-dimensional arrays have the format:
where n is the number of rows, and m is the number of columns. Parsing is lenient (as in other data types). A final comma is always allowed after the last element; either the last string in a row, or the last row itself. Furthermore, since there is no ambiguity, the commas between the rows are entirely optional. (However, if a comma is present, there can only be one comma, no more.) It is possible to have zero columns, as follows:TwoD { { r1c1, r1c2, ..., r1cm }, { r2c1, r2c2, ..., r2cm }, ... { rnc1, rnc2, ..., rncm } }
But it is impossible to have zero rows. The smallest array is thus a 1 x 0 array, which looks like this:Odd { {} {} {} } // 3 x 0 array
The array must be strictly rectangular; that is, each row must have the same number of elements.Smallest { {} } // 1 x 0 array
This is an example for using a possible custom resource:
@stableLocale currentLocale; UErrorCode success = U_ZERO_ERROR; ResourceBundle myResources("MyResources", currentLocale, success ); UnicodeString button1Title, button2Title; myResources.getString("OkKey", button1Title, success ); myResources.getString("CancelKey", button2Title, success );
|
Constructor.
|
|
Construct a resource bundle for the root bundle in the specified path.
|
|
Construct a resource bundle for the ICU root bundle.
|
|
Constructs a ResourceBundle.
|
|
Standard constructor, onstructs a resource bundle for the locale-specific bundle in the specified path.
|
|
Copy constructor.
|
|
Constructor from a C UResourceBundle.
|
|
Destructor. @stable |
|
Returns a resource in a resource that has a given key. This procedure works only with table resources.
|
|
Returns the resource in a resource at the specified index.
|
|
returns a binary data from a resource. Can be used at most primitive resource types (binaries, strings, ints)
|
|
returns a signed integer from a resource. This integer is originally 28 bit and the sign gets propagated.
|
|
returns an integer vector from a resource.
|
|
Returns the key associated with this resource. Not all the resources have a key - only those that are members of a table.
|
|
Return the Locale associated with this ResourceBundle.
|
|
Gets the locale ID of the resource bundle as a string. Same as getLocale().getName() . @stable |
|
Returns the next resource in a given resource or NULL if there are no more resources.
|
|
Returns the next string in a resource or NULL if there are no more resources to iterate over.
|
|
Returns the next string in a resource or NULL if there are no more resources to iterate over.
|
|
Returns the size of a resource. Size for scalar types is always 1, and for vector/table types is the number of child resources.
|
|
returns a string from a string resource type.
|
|
Returns a string in a resource that has a given key. This procedure works only with table resources.
|
|
Returns the string in a given resource at the specified index.
|
|
Returns the type of a resource. Available types are defined in enum UResType
|
|
returns an unsigned integer from a resource. This integer is originally 28 bits.
|
|
Return the version number associated with this ResourceBundle as a UVersionInfo array.
|
|
Return the version number associated with this ResourceBundle as a string.
|
|
Checks whether the resource has another element to iterate over.
|
|
Assignment operator.
|
|
Resets the internal context of a resource so that iteration starts from the first element. @stable |