1999-08-16 21:50:52 +00:00
|
|
|
/*
|
1999-12-09 23:27:55 +00:00
|
|
|
**********************************************************************
|
2004-05-18 22:01:41 +00:00
|
|
|
* Copyright (C) 1997-2004, International Business Machines
|
1999-12-09 23:27:55 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* File resbund.cpp
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 02/05/97 aliu Fixed bug in chopLocale. Added scanForLocaleInFile
|
|
|
|
* based on code taken from scanForLocale. Added
|
|
|
|
* constructor which attempts to read resource bundle
|
|
|
|
* from a specific file, without searching other files.
|
2001-03-21 20:44:20 +00:00
|
|
|
* 02/11/97 aliu Added UErrorCode return values to constructors. Fixed
|
1999-08-16 21:50:52 +00:00
|
|
|
* infinite loops in scanForFile and scanForLocale.
|
|
|
|
* Modified getRawResourceData to not delete storage in
|
|
|
|
* localeData and resourceData which it doesn't own.
|
|
|
|
* Added Mac compatibility #ifdefs for tellp() and
|
|
|
|
* ios::nocreate.
|
|
|
|
* 03/04/97 aliu Modified to use ExpandingDataSink objects instead of
|
|
|
|
* the highly inefficient ostrstream objects.
|
|
|
|
* 03/13/97 aliu Rewrote to load in entire resource bundle and store
|
|
|
|
* it as a Hashtable of ResourceBundleData objects.
|
|
|
|
* Added state table to govern parsing of files.
|
|
|
|
* Modified to load locale index out of new file distinct
|
|
|
|
* from default.txt.
|
|
|
|
* 03/25/97 aliu Modified to support 2-d arrays, needed for timezone data.
|
2001-03-21 20:44:20 +00:00
|
|
|
* Added support for custom file suffixes. Again, needed
|
|
|
|
* to support timezone data. Improved error handling to
|
|
|
|
* detect duplicate tags and subtags.
|
|
|
|
* 04/07/97 aliu Fixed bug in getHashtableForLocale(). Fixed handling
|
|
|
|
* of failing UErrorCode values on entry to API methods.
|
1999-08-16 21:50:52 +00:00
|
|
|
* Fixed bugs in getArrayItem() for negative indices.
|
|
|
|
* 04/29/97 aliu Update to use new Hashtable deletion protocol.
|
2001-03-21 20:44:20 +00:00
|
|
|
* 05/06/97 aliu Flattened kTransitionTable for HP compiler.
|
|
|
|
* Fixed usage of CharString.
|
1999-08-16 21:50:52 +00:00
|
|
|
* 06/11/99 stephen Removed parsing of .txt files.
|
|
|
|
* Reworked to use new binary format.
|
|
|
|
* Cleaned up.
|
|
|
|
* 06/14/99 stephen Removed methods taking a filename suffix.
|
|
|
|
* 06/22/99 stephen Added missing T_FileStream_close in parse()
|
2001-03-21 20:44:20 +00:00
|
|
|
* 11/09/99 weiv Added getLocale(), rewritten constructForLocale()
|
2000-05-15 18:39:17 +00:00
|
|
|
* March 2000 weiv complete overhaul.
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
|
|
|
|
2000-07-20 20:52:12 +00:00
|
|
|
#include "unicode/utypes.h"
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/resbund.h"
|
2004-02-23 04:36:02 +00:00
|
|
|
#include "umutex.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
#include "uresimp.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* Implementation Notes
|
|
|
|
*
|
|
|
|
* Resource bundles are read in once, and thereafter cached.
|
|
|
|
* ResourceBundle statically keeps track of which files have been
|
|
|
|
* read, so we are guaranteed that each file is read at most once.
|
|
|
|
* Resource bundles can be loaded from different data directories and
|
|
|
|
* will be treated as distinct, even if they are for the same locale.
|
|
|
|
*
|
|
|
|
* Resource bundles are lightweight objects, which have pointers to
|
|
|
|
* one or more shared Hashtable objects containing all the data.
|
|
|
|
* Copying would be cheap, but there is no copy constructor, since
|
|
|
|
* there wasn't one in the original API.
|
|
|
|
*
|
|
|
|
* The ResourceBundle parsing mechanism is implemented as a transition
|
|
|
|
* network, for easy maintenance and modification. The network is
|
|
|
|
* implemented as a matrix (instead of in code) to make this even
|
|
|
|
* easier. The matrix contains Transition objects. Each Transition
|
|
|
|
* object describes a destination node and an action to take before
|
|
|
|
* moving to the destination node. The source node is encoded by the
|
|
|
|
* index of the object in the array that contains it. The pieces
|
|
|
|
* needed to understand the transition network are the enums for node
|
|
|
|
* IDs and actions, the parse() method, which walks through the
|
|
|
|
* network and implements the actions, and the network itself. The
|
|
|
|
* network guarantees certain conditions, for example, that a new
|
|
|
|
* resource will not be closed until one has been opened first; or
|
|
|
|
* that data will not be stored into a TaggedList until a TaggedList
|
|
|
|
* has been created. Nonetheless, the code in parse() does some
|
|
|
|
* consistency checks as it runs the network, and fails with an
|
1999-10-07 00:07:53 +00:00
|
|
|
* U_INTERNAL_PROGRAM_ERROR if one of these checks fails. If the input
|
|
|
|
* data has a bad format, an U_INVALID_FORMAT_ERROR is returned. If you
|
|
|
|
* see an U_INTERNAL_PROGRAM_ERROR the transition matrix has a bug in
|
1999-08-16 21:50:52 +00:00
|
|
|
* it.
|
|
|
|
*
|
|
|
|
* Old functionality of multiple locales in a single file is still
|
|
|
|
* supported. For this reason, LOCALE names override FILE names. If
|
|
|
|
* data for en_US is located in the en.txt file, once it is loaded,
|
|
|
|
* the code will not care where it came from (other than remembering
|
|
|
|
* which directory it came from). However, if there is an en_US
|
|
|
|
* resource in en_US.txt, that will take precedence. There is no
|
|
|
|
* limit to the number or type of resources that can be stored in a
|
|
|
|
* file, however, files are only searched in a specific way. If
|
|
|
|
* en_US_CA is requested, then first en_US_CA.txt is searched, then
|
|
|
|
* en_US.txt, then en.txt, then default.txt. So it only makes sense
|
|
|
|
* to put certain locales in certain files. In this example, it would
|
|
|
|
* be logical to put en_US_CA, en_US, and en into the en.txt file,
|
|
|
|
* since they would be found there if asked for. The extreme example
|
|
|
|
* is to place all locale resources into default.txt, which should
|
|
|
|
* also work.
|
|
|
|
*
|
|
|
|
* Inheritance is implemented. For example, xx_YY_zz inherits as
|
|
|
|
* follows: xx_YY_zz, xx_YY, xx, default. Inheritance is implemented
|
|
|
|
* as an array of hashtables. There will be from 1 to 4 hashtables in
|
|
|
|
* the array.
|
|
|
|
*
|
|
|
|
* Fallback files are implemented. The fallback pattern is Language
|
|
|
|
* Country Variant (LCV) -> LC -> L. Fallback is first done for the
|
|
|
|
* requested locale. Then it is done for the default locale, as
|
|
|
|
* returned by Locale::getDefault(). Then the special file
|
|
|
|
* default.txt is searched for the default locale. The overall FILE
|
|
|
|
* fallback path is LCV -> LC -> L -> dLCV -> dLC -> dL -> default.
|
|
|
|
*
|
|
|
|
* Note that although file name searching includes the default locale,
|
|
|
|
* once a ResourceBundle object is constructed, the inheritance path
|
|
|
|
* no longer includes the default locale. The path is LCV -> LC -> L
|
|
|
|
* -> default.
|
|
|
|
*
|
|
|
|
* File parsing is lazy. Nothing is parsed unless it is called for by
|
|
|
|
* someone. So when a ResourceBundle for xx_YY_zz is constructed,
|
|
|
|
* only that locale is parsed (along with anything else in the same
|
|
|
|
* file). Later, if the FooBar tag is asked for, and if it isn't
|
|
|
|
* found in xx_YY_zz, then xx_YY.txt will be parsed and checked, and
|
|
|
|
* so forth, until the chain is exhausted or the tag is found.
|
|
|
|
*
|
|
|
|
* Thread-safety is implemented around caches, both the cache that
|
|
|
|
* stores all the resouce data, and the cache that stores flags
|
|
|
|
* indicating whether or not a file has been visited. These caches
|
|
|
|
* delete their storage at static cleanup time, when the process
|
|
|
|
* quits.
|
|
|
|
*
|
|
|
|
* ResourceBundle supports TableCollation as a special case. This
|
|
|
|
* involves having special ResourceBundle objects which DO own their
|
|
|
|
* data, since we don't want large collation rule strings in the
|
|
|
|
* ResourceBundle cache (these are already cached in the
|
|
|
|
* TableCollation cache). TableCollation files (.ctx files) have the
|
|
|
|
* same format as normal resource data files, with a different
|
|
|
|
* interpretation, from the standpoint of ResourceBundle. .ctx files
|
|
|
|
* are loaded into otherwise ordinary ResourceBundle objects. They
|
|
|
|
* don't inherit (that's implemented by TableCollation) and they own
|
|
|
|
* their data (as mentioned above). However, they still support
|
|
|
|
* possible multiple locales in a single .ctx file. (This is in
|
|
|
|
* practice a bad idea, since you only want the one locale you're
|
|
|
|
* looking for, and only one tag will be present
|
|
|
|
* ("CollationElements"), so you don't need an inheritance chain of
|
|
|
|
* multiple locales.) Up to 4 locale resources will be loaded from a
|
|
|
|
* .ctx file; everything after the first 4 is ignored (parsed and
|
|
|
|
* deleted). (Normal .txt files have no limit.) Instead of being
|
|
|
|
* loaded into the cache, and then looked up as needed, the locale
|
|
|
|
* resources are read straight into the ResourceBundle object.
|
|
|
|
*
|
|
|
|
* The Index, which used to reside in default.txt, has been moved to a
|
|
|
|
* new file, index.txt. This file contains a slightly modified format
|
|
|
|
* with the addition of the "InstalledLocales" tag; it looks like:
|
|
|
|
*
|
|
|
|
* Index {
|
|
|
|
* InstalledLocales {
|
|
|
|
* ar
|
|
|
|
* ..
|
|
|
|
* zh_TW
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2003-08-27 01:01:42 +00:00
|
|
|
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ResourceBundle)
|
2002-06-29 00:04:16 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
ResourceBundle::ResourceBundle( const UnicodeString& path,
|
|
|
|
const Locale& locale,
|
|
|
|
UErrorCode& error)
|
2004-02-23 04:36:02 +00:00
|
|
|
:UObject(), fLocale(NULL)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-07-09 21:08:25 +00:00
|
|
|
constructForLocale(path, locale, error);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-10-11 18:43:18 +00:00
|
|
|
ResourceBundle::ResourceBundle(UErrorCode &err)
|
2004-02-23 04:36:02 +00:00
|
|
|
:UObject(), fLocale(NULL)
|
2001-10-11 18:43:18 +00:00
|
|
|
{
|
2004-02-23 04:36:02 +00:00
|
|
|
fResource = ures_open(0, Locale::getDefault().getName(), &err);
|
2000-06-30 20:24:59 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
ResourceBundle::ResourceBundle( const UnicodeString& path,
|
|
|
|
UErrorCode& error)
|
2004-02-23 04:36:02 +00:00
|
|
|
:UObject(), fLocale(NULL)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-07-09 21:08:25 +00:00
|
|
|
constructForLocale(path, Locale::getDefault(), error);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-09-25 01:12:34 +00:00
|
|
|
ResourceBundle::ResourceBundle(const ResourceBundle &other)
|
2004-02-23 04:36:02 +00:00
|
|
|
:UObject(other), fLocale(NULL)
|
2001-09-25 01:12:34 +00:00
|
|
|
{
|
2000-05-15 18:39:17 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2000-05-26 18:58:00 +00:00
|
|
|
|
2004-02-23 04:36:02 +00:00
|
|
|
if (other.fResource) {
|
|
|
|
fResource = ures_copyResb(0, other.fResource, &status);
|
2001-05-25 16:08:27 +00:00
|
|
|
} else {
|
|
|
|
/* Copying a bad resource bundle */
|
2004-02-23 04:36:02 +00:00
|
|
|
fResource = NULL;
|
2001-03-06 01:27:32 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-10-11 18:43:18 +00:00
|
|
|
ResourceBundle::ResourceBundle(UResourceBundle *res, UErrorCode& err)
|
2004-02-23 04:36:02 +00:00
|
|
|
:UObject(), fLocale(NULL)
|
2001-10-11 18:43:18 +00:00
|
|
|
{
|
2001-09-25 01:12:34 +00:00
|
|
|
if (res) {
|
2004-02-23 04:36:02 +00:00
|
|
|
fResource = ures_copyResb(0, res, &err);
|
2001-09-25 01:12:34 +00:00
|
|
|
} else {
|
|
|
|
/* Copying a bad resource bundle */
|
2004-02-23 04:36:02 +00:00
|
|
|
fResource = NULL;
|
2001-09-25 01:12:34 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-07-02 23:58:34 +00:00
|
|
|
ResourceBundle::ResourceBundle(const char* path, const Locale& locale, UErrorCode& err)
|
2004-02-23 04:36:02 +00:00
|
|
|
:UObject(), fLocale(NULL)
|
2001-10-11 18:43:18 +00:00
|
|
|
{
|
2004-02-23 04:36:02 +00:00
|
|
|
fResource = ures_open(path, locale.getName(), &err);
|
2000-06-30 20:24:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
ResourceBundle& ResourceBundle::operator=(const ResourceBundle& other)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-05-15 18:39:17 +00:00
|
|
|
if(this == &other) {
|
|
|
|
return *this;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2004-02-23 04:36:02 +00:00
|
|
|
if(fResource != 0) {
|
|
|
|
ures_close(fResource);
|
|
|
|
fResource = NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2004-02-23 04:36:02 +00:00
|
|
|
if (other.fResource) {
|
|
|
|
fResource = ures_copyResb(0, other.fResource, &status);
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
2001-09-25 01:12:34 +00:00
|
|
|
/* Copying a bad resource bundle */
|
2004-02-23 04:36:02 +00:00
|
|
|
fResource = NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
return *this;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
ResourceBundle::~ResourceBundle()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2004-02-23 04:36:02 +00:00
|
|
|
if(fResource != 0) {
|
|
|
|
ures_close(fResource);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2004-02-23 04:36:02 +00:00
|
|
|
if(fLocale != NULL) {
|
|
|
|
delete(fLocale);
|
2001-10-11 18:43:18 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-11-05 02:26:49 +00:00
|
|
|
ResourceBundle *
|
|
|
|
ResourceBundle::clone() const {
|
|
|
|
return new ResourceBundle(*this);
|
|
|
|
}
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
void
|
|
|
|
ResourceBundle::constructForLocale(const UnicodeString& path,
|
2000-06-07 19:52:08 +00:00
|
|
|
const Locale& locale,
|
|
|
|
UErrorCode& error)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-09-18 23:50:55 +00:00
|
|
|
char name[300];
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2001-09-27 22:39:39 +00:00
|
|
|
if(!path.isEmpty()) {
|
2001-09-18 23:50:55 +00:00
|
|
|
path.extract(name, sizeof(name), 0, error);
|
2004-02-23 04:36:02 +00:00
|
|
|
fResource = ures_open(name, locale.getName(), &error);
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
2004-02-23 04:36:02 +00:00
|
|
|
fResource = ures_open(0, locale.getName(), &error);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
UnicodeString ResourceBundle::getString(UErrorCode& status) const {
|
|
|
|
int32_t len = 0;
|
2004-02-23 04:36:02 +00:00
|
|
|
const UChar *r = ures_getString(fResource, &len, &status);
|
2000-05-15 18:39:17 +00:00
|
|
|
return UnicodeString(TRUE, r, len);
|
|
|
|
}
|
|
|
|
|
2000-05-24 19:58:40 +00:00
|
|
|
const uint8_t *ResourceBundle::getBinary(int32_t& len, UErrorCode& status) const {
|
2004-02-23 04:36:02 +00:00
|
|
|
return ures_getBinary(fResource, &len, &status);
|
2000-05-24 19:58:40 +00:00
|
|
|
}
|
|
|
|
|
2001-08-10 21:18:07 +00:00
|
|
|
const int32_t *ResourceBundle::getIntVector(int32_t& len, UErrorCode& status) const {
|
2004-02-23 04:36:02 +00:00
|
|
|
return ures_getIntVector(fResource, &len, &status);
|
2001-08-10 21:18:07 +00:00
|
|
|
}
|
|
|
|
|
2001-09-17 23:05:08 +00:00
|
|
|
uint32_t ResourceBundle::getUInt(UErrorCode& status) const {
|
2004-02-23 04:36:02 +00:00
|
|
|
return ures_getUInt(fResource, &status);
|
2001-09-17 23:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t ResourceBundle::getInt(UErrorCode& status) const {
|
2004-02-23 04:36:02 +00:00
|
|
|
return ures_getInt(fResource, &status);
|
2001-09-17 23:05:08 +00:00
|
|
|
}
|
|
|
|
|
2004-03-30 23:17:44 +00:00
|
|
|
const char *ResourceBundle::getName(void) const {
|
2004-02-23 04:36:02 +00:00
|
|
|
return ures_getName(fResource);
|
2000-05-24 19:58:40 +00:00
|
|
|
}
|
|
|
|
|
2004-03-30 23:17:44 +00:00
|
|
|
const char *ResourceBundle::getKey(void) const {
|
2004-02-23 04:36:02 +00:00
|
|
|
return ures_getKey(fResource);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2004-03-30 23:17:44 +00:00
|
|
|
UResType ResourceBundle::getType(void) const {
|
2004-02-23 04:36:02 +00:00
|
|
|
return ures_getType(fResource);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t ResourceBundle::getSize(void) const {
|
2004-02-23 04:36:02 +00:00
|
|
|
return ures_getSize(fResource);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool ResourceBundle::hasNext(void) const {
|
2004-02-23 04:36:02 +00:00
|
|
|
return ures_hasNext(fResource);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceBundle::resetIterator(void) {
|
2004-02-23 04:36:02 +00:00
|
|
|
ures_resetIterator(fResource);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ResourceBundle ResourceBundle::getNext(UErrorCode& status) {
|
2000-06-26 22:46:15 +00:00
|
|
|
UResourceBundle r;
|
2001-02-16 21:43:46 +00:00
|
|
|
|
2002-04-17 21:19:38 +00:00
|
|
|
ures_initStackObject(&r);
|
2004-02-23 04:36:02 +00:00
|
|
|
ures_getNextResource(fResource, &r, &status);
|
2001-09-25 01:12:34 +00:00
|
|
|
ResourceBundle res(&r, status);
|
2001-09-25 01:24:52 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
ures_close(&r);
|
|
|
|
}
|
2001-09-25 01:12:34 +00:00
|
|
|
return res;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString ResourceBundle::getNextString(UErrorCode& status) {
|
|
|
|
int32_t len = 0;
|
2004-02-23 04:36:02 +00:00
|
|
|
const UChar* r = ures_getNextString(fResource, &len, 0, &status);
|
2000-05-15 18:39:17 +00:00
|
|
|
return UnicodeString(TRUE, r, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString ResourceBundle::getNextString(const char ** key, UErrorCode& status) {
|
|
|
|
int32_t len = 0;
|
2004-02-23 04:36:02 +00:00
|
|
|
const UChar* r = ures_getNextString(fResource, &len, key, &status);
|
2000-05-15 18:39:17 +00:00
|
|
|
return UnicodeString(TRUE, r, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
ResourceBundle ResourceBundle::get(int32_t indexR, UErrorCode& status) const {
|
2000-06-26 22:46:15 +00:00
|
|
|
UResourceBundle r;
|
2001-02-16 21:43:46 +00:00
|
|
|
|
2002-04-17 21:19:38 +00:00
|
|
|
ures_initStackObject(&r);
|
2004-02-23 04:36:02 +00:00
|
|
|
ures_getByIndex(fResource, indexR, &r, &status);
|
2001-09-25 01:12:34 +00:00
|
|
|
ResourceBundle res(&r, status);
|
2001-09-25 01:24:52 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
ures_close(&r);
|
|
|
|
}
|
2001-09-25 01:12:34 +00:00
|
|
|
return res;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString ResourceBundle::getStringEx(int32_t indexS, UErrorCode& status) const {
|
|
|
|
int32_t len = 0;
|
2004-02-23 04:36:02 +00:00
|
|
|
const UChar* r = ures_getStringByIndex(fResource, indexS, &len, &status);
|
2000-05-15 18:39:17 +00:00
|
|
|
return UnicodeString(TRUE, r, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
ResourceBundle ResourceBundle::get(const char* key, UErrorCode& status) const {
|
2000-06-26 22:46:15 +00:00
|
|
|
UResourceBundle r;
|
2001-02-16 21:43:46 +00:00
|
|
|
|
2002-04-17 21:19:38 +00:00
|
|
|
ures_initStackObject(&r);
|
2004-02-23 04:36:02 +00:00
|
|
|
ures_getByKey(fResource, key, &r, &status);
|
2001-09-25 01:12:34 +00:00
|
|
|
ResourceBundle res(&r, status);
|
2001-09-25 01:24:52 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
ures_close(&r);
|
|
|
|
}
|
2001-09-25 01:12:34 +00:00
|
|
|
return res;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2004-05-15 00:16:32 +00:00
|
|
|
ResourceBundle ResourceBundle::getWithFallback(const char* key, UErrorCode& status){
|
|
|
|
UResourceBundle r;
|
|
|
|
ures_initStackObject(&r);
|
|
|
|
ures_getByKeyWithFallback(fResource, key, &r, &status);
|
|
|
|
ResourceBundle res(&r, status);
|
|
|
|
if(U_SUCCESS(status)){
|
|
|
|
ures_close(&r);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
UnicodeString ResourceBundle::getStringEx(const char* key, UErrorCode& status) const {
|
|
|
|
int32_t len = 0;
|
2004-02-23 04:36:02 +00:00
|
|
|
const UChar* r = ures_getStringByKey(fResource, key, &len, &status);
|
2000-05-15 18:39:17 +00:00
|
|
|
return UnicodeString(TRUE, r, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
ResourceBundle::getVersionNumber() const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2004-02-23 04:36:02 +00:00
|
|
|
return ures_getVersionNumber(fResource);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-06-30 20:24:59 +00:00
|
|
|
void ResourceBundle::getVersion(UVersionInfo versionInfo) const {
|
2004-02-23 04:36:02 +00:00
|
|
|
ures_getVersion(fResource, versionInfo);
|
2000-06-30 20:24:59 +00:00
|
|
|
}
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
const Locale &ResourceBundle::getLocale(void) const
|
|
|
|
{
|
2004-02-23 04:36:02 +00:00
|
|
|
UBool needInit;
|
|
|
|
umtx_lock(NULL);
|
|
|
|
needInit = (fLocale == NULL);
|
|
|
|
umtx_unlock(NULL);
|
|
|
|
if(needInit) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
const char *localeName = ures_getLocale(fResource, &status);
|
|
|
|
Locale *tLocale = new Locale(localeName);
|
|
|
|
umtx_lock(NULL);
|
|
|
|
ResourceBundle *me = (ResourceBundle *)this; // semantically const
|
|
|
|
if (me->fLocale == NULL) {
|
|
|
|
me->fLocale = tLocale;
|
|
|
|
tLocale = NULL;
|
|
|
|
}
|
|
|
|
umtx_unlock(NULL);
|
|
|
|
delete tLocale;
|
|
|
|
}
|
|
|
|
return *fLocale;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-11-07 09:01:24 +00:00
|
|
|
const Locale ResourceBundle::getLocale(ULocDataLocaleType type, UErrorCode &status) const
|
|
|
|
{
|
2004-02-23 04:36:02 +00:00
|
|
|
return ures_getLocaleByType(fResource, type, &status);
|
2003-11-07 09:01:24 +00:00
|
|
|
}
|
|
|
|
|
2000-06-07 00:01:16 +00:00
|
|
|
//eof
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|