A class representing a collection of resource information pertaining to a given locale
A class representing a collection of resource information pertaining to a given locale. 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:
. locale { . tag1 {...} . tag2 {...} . }The tags are used to retrieve the data later. You may not have multiple instances of the same tag.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:
. Tag { Data }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).Comma-delimited lists have the format:
. Tag { Data, Data, Data }Parsing is lenient; a final string, after the last element, is allowed.Tagged lists have the format:
. Tag { Subtag { Data } Subtag {Data} }Data is retrieved by specifying the subtag.Two-dimensional arrays have the format:
. TwoD { . { r1c1, r1c2, ..., r1cm }, . { r2c1, r2c2, ..., r2cm }, . ... . { rnc1, rnc2, ..., rncm } . }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:. Odd { {} {} {} } // 3 x 0 arrayBut it is impossible to have zero rows. The smallest array is thus a 1 x 0 array, which looks like this:. Smallest { {} } // 1 x 0 arrayThe array must be strictly rectangular; that is, each row must have the same number of elements.This is an example for using a possible custom resource:
. Locale currentLocale; . UErrorCode success = ZERO_ERROR; . ResourceBundle myResources("MyResources", currentLocale, success ); . . UnicodeString button1Title, button2Title; . myResources.getString("OkKey", button1Title, success ); . myResources.getString("CancelKey", button2Title, success );
void getString( const UnicodeString& resourceTag, UnicodeString& theString, UErrorCode& err) const
theString - Receives the actual data in the resource
err - Set to MISSING_RESOURCE_ERROR if a resource with the
specified tag couldn't be found. const UnicodeString* getString( const UnicodeString& resourceTag, UErrorCode& err) const
err - Set to MISSING_RESOURCE_ERROR if a resource with the
specified tag couldn't be found.
const UnicodeString* getStringArray( const UnicodeString& resourceTag, int32_t& numArrayItems, UErrorCode& err) const
numArrayItems - Receives the number of items in the array the function
returns.
err - Set to MISSING_RESOURCE_ERROR if a resource with the
specified tag couldn't be found.
void getArrayItem( const UnicodeString& resourceTag, int32_t index, UnicodeString& theArrayItem, UErrorCode& err) const
index - The index (zero-based) of the particular array item the user
wants to extract from the resource.
theArrayItem - Receives the actual text of the desired array item.
err - Set to MISSING_RESOURCE_ERROR if a resource with the
specified tag couldn't be found, or if the index was out of range. const UnicodeString* getArrayItem( const UnicodeString& resourceTag, int32_t index, UErrorCode& err) const
index - The index (zero-based) of the particular array item the user
wants to extract from the resource.
err - Set to MISSING_RESOURCE_ERROR if a resource with the
specified tag couldn't be found, or if the index was out of range.
const UnicodeString** get2dArray(const UnicodeString& resourceTag, int32_t& rowCount, int32_t& columnCount, UErrorCode& err) const
rowCount - Receives the number of rows in the array the function
returns.
columnCount - Receives the number of columns in the array the function
returns.
err - Set to MISSING_RESOURCE_ERROR if a resource with the
specified tag couldn't be found.
void get2dArrayItem(const UnicodeString& resourceTag, int32_t rowIndex, int32_t columnIndex, UnicodeString& theArrayItem, UErrorCode& err) const
rowIndex - The row index (zero-based) of the array item the user wants
to extract from the resource.
columnIndex - The column index (zero-based) of the array item the user
wants to extract from the resource.
theArrayItem - Receives the actual text of the desired array item.
err - Set to MISSING_RESOURCE_ERROR if a resource with the
specified tag couldn't be found, if the resource data was in
the wrong format, or if either index is out of bounds. const UnicodeString* get2dArrayItem( const UnicodeString& resourceTag, int32_t rowIndex, int32_t columnIndex, UErrorCode& err) const
rowIndex - The row index (zero-based) of the array item the user wants
to extract from the resource.
columnIndex - The column index (zero-based) of the array item the user
wants to extract from the resource.
err - Set to MISSING_RESOURCE_ERROR if a resource with the
specified tag couldn't be found, if the resource data was in
the wrong format, or if either index is out of bounds.
void getTaggedArrayItem( const UnicodeString& resourceTag, const UnicodeString& itemTag, UnicodeString& theArrayItem, UErrorCode& err) const
itemTag - The item tag for the item the caller wants to extract.
theArrayItem - Receives the text of the desired array item.
err - Set to MISSING_RESOURCE_ERROR if a resource with the
specified resource tag couldn't be found, or if an item
with the specified item tag couldn't be found in the resource. const UnicodeString* getTaggedArrayItem( const UnicodeString& resourceTag, const UnicodeString& itemTag, UErrorCode& err) const
itemTag - The item tag for the item the caller wants to extract.
err - Set to MISSING_RESOURCE_ERROR if a resource with the
specified resource tag couldn't be found, or if an item
with the specified item tag coldn't be found in the resource.
void getTaggedArray( const UnicodeString& resourceTag, UnicodeString*& itemTags, UnicodeString*& items, int32_t& numItems, UErrorCode& err) const
itemTags - Set to point to an array of UnicodeStrings representing the
tags in the specified resource. The caller DOES own this array,
and must delete it.
items - Set to point to an array of UnicodeStrings containing the
individual resource items themselves. itemTags[i] will
contain the tag corresponding to items[i]. The caller DOES
own this array, and must delete it.
numItems - Receives the number of items in the arrays pointed to by
items and itemTags.
err - Set to MISSING_RESOURCE_ERROR if a resource with the
specified tag couldn't be found. const char* getVersionNumber(void) const
alphabetic index hierarchy of classes
this page has been generated automatically by doc++
(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de