ICU-185 Locale takes/returns char*. Old api's deprecated. Implementation fixed to not use deprecated api's.

X-SVN-Rev: 1134
This commit is contained in:
Steven R. Loomis 2000-04-15 21:19:44 +00:00
parent f911c8b490
commit 90d12c93b9
6 changed files with 418 additions and 263 deletions

View file

@ -23,7 +23,8 @@
* getLanguagesForCountry()
* 03/16/99 bertrand rehaul.
* 07/21/99 stephen Added U_CFUNC setDefault
* 11/09/99 weiv Added const char * getName() const;
* 11/09/99 weiv Added const char * getName() const;
* 04/12/00 srl removing unicodestring api's and cached hash code
*******************************************************************************
*/
@ -56,30 +57,30 @@ int32_t Locale::isoCountriesCount;
/**
* Constant definitions
*/
const Locale Locale::ENGLISH(UNICODE_STRING("en", 2));
const Locale Locale::FRENCH(UNICODE_STRING("fr", 2));
const Locale Locale::GERMAN(UNICODE_STRING("de", 2));
const Locale Locale::ITALIAN(UNICODE_STRING("it", 2));
const Locale Locale::JAPANESE(UNICODE_STRING("ja", 2));
const Locale Locale::KOREAN(UNICODE_STRING("ko", 2));
const Locale Locale::CHINESE(UNICODE_STRING("zh", 2));
const Locale Locale::SIMPLIFIED_CHINESE(UNICODE_STRING("zh", 2), UNICODE_STRING("CN", 2));
const Locale Locale::TRADITIONAL_CHINESE(UNICODE_STRING("zh", 2), UNICODE_STRING("TW", 2));
const Locale Locale::ENGLISH("en");
const Locale Locale::FRENCH("fr");
const Locale Locale::GERMAN("de");
const Locale Locale::ITALIAN("it");
const Locale Locale::JAPANESE("ja");
const Locale Locale::KOREAN("ko");
const Locale Locale::CHINESE("zh");
const Locale Locale::SIMPLIFIED_CHINESE("zh", "CN");
const Locale Locale::TRADITIONAL_CHINESE("zu", "TW");
// Useful constant for country.
const Locale Locale::FRANCE(UNICODE_STRING("fr", 2), UNICODE_STRING("FR", 2));
const Locale Locale::GERMANY(UNICODE_STRING("de", 2), UNICODE_STRING("DE", 2));
const Locale Locale::ITALY(UNICODE_STRING("it", 2), UNICODE_STRING("IT", 2));
const Locale Locale::JAPAN(UNICODE_STRING("ja", 2), UNICODE_STRING("JP", 2));
const Locale Locale::KOREA(UNICODE_STRING("en", 2), UNICODE_STRING("GB", 2));
const Locale Locale::CHINA(UNICODE_STRING("zh", 2), UNICODE_STRING("CN", 2));
const Locale Locale::PRC(UNICODE_STRING("zh", 2), UNICODE_STRING("CN", 2));
const Locale Locale::TAIWAN(UNICODE_STRING("zh", 2), UNICODE_STRING("TW", 2));
const Locale Locale::UK(UNICODE_STRING("en", 2), UNICODE_STRING("GB", 2));
const Locale Locale::US(UNICODE_STRING("en", 2), UNICODE_STRING("US", 2));
const Locale Locale::CANADA(UNICODE_STRING("en", 2), UNICODE_STRING("CA", 2));
const Locale Locale::CANADA_FRENCH(UNICODE_STRING("fr", 2), UNICODE_STRING("CA", 2));
const Locale Locale::FRANCE ("fr", "FR");
const Locale Locale::GERMANY ("de", "DE");
const Locale Locale::ITALY ("it", "IT");
const Locale Locale::JAPAN ("ja", "JP");
const Locale Locale::KOREA ("ko", "KR");
const Locale Locale::CHINA ("zh", "CN");
const Locale Locale::PRC ("zh", "CN");
const Locale Locale::TAIWAN ("zh", "TW");
const Locale Locale::UK ("en", "GB");
const Locale Locale::US ("en", "US");
const Locale Locale::CANADA ("en", "CA");
const Locale Locale::CANADA_FRENCH("fr", "CA");
/**
@ -117,7 +118,7 @@ const Locale Locale::CANADA_FRENCH(UNICODE_STRING("fr", 2), UNICODE_STRING("CA"
/*Character separating the posix id fields*/
const UChar sep = 0x005F; // '_'
const char sepchar = '_'; // In the platform codepage.
Locale::~Locale()
{
@ -133,79 +134,124 @@ Locale::Locale()
init(uloc_getDefault());
}
Locale::Locale( const UnicodeString& newLanguage)
Locale::Locale( const char * newLanguage,
const char * newCountry,
const char * newVariant)
{
char myLocaleID[ULOC_FULLNAME_CAPACITY];
char togo_stack[ULOC_FULLNAME_CAPACITY];
char *togo;
char *togo_heap = NULL;
int32_t size;
int32_t lsize = 0;
int32_t csize = 0;
int32_t vsize = 0;
char *p;
myLocaleID[newLanguage.extract(0, 0x7fffffff, myLocaleID, "")] = '\0';
init(myLocaleID);
}
Locale::Locale( const UnicodeString& newLanguage,
const UnicodeString& newCountry)
{
UnicodeString togo(newLanguage);
char myLocaleID[ULOC_FULLNAME_CAPACITY];
if(newCountry.length()>0) {
togo += sep;
togo += newCountry;
}
myLocaleID[togo.extract(0, 0x7fffffff, myLocaleID, "")] = '\0';
init(myLocaleID);
}
Locale::Locale( const UnicodeString& newLanguage,
const UnicodeString& newCountry,
const UnicodeString& newVariant)
{
UnicodeString togo(newLanguage);
char myLocaleID[ULOC_FULLNAME_CAPACITY];
UnicodeString newVariantCopy(newVariant);
if (newCountry.length() > 0 ||
newVariantCopy.length() > 0 )
{
togo += sep;
togo += newCountry;
}
int vsize = newVariantCopy.length();
if (vsize > 0)
{
int i = 0;
//We need to trim variant codes : (_*)$var(_*) --> $var
while ((i<vsize) && newVariantCopy[i] == sep) newVariantCopy.remove(i++, 1);
i = newVariantCopy.length() - 1;
while (i && (newVariantCopy[i] == sep)) newVariantCopy.remove(i--, 1);
if( (newLanguage==NULL) && (newCountry == NULL) && (newVariant == NULL) )
{
init(NULL); /* shortcut */
}
else
{
// Calculate the size of the resulting string.
togo += sep ;
togo += newVariantCopy ;
// Language
if ( newLanguage != NULL )
{
lsize = uprv_strlen(newLanguage);
size = lsize;
}
// _Country
if ( newCountry != NULL )
{
csize = uprv_strlen(newCountry);
size += csize;
}
// _Variant
if ( newVariant != NULL )
{
// remove leading _'s
while(newVariant[0] == sepchar)
{
newVariant++;
}
// remove trailing _'s
vsize = uprv_strlen(newVariant);
while( (vsize>1) && (newVariant[vsize-1] == sepchar) )
{
vsize--;
}
}
if( vsize > 0 )
{
size += vsize;
}
int size = togo.length();
// Separator rules:
if ( vsize > 0 )
{
size += 2; // at least: __v
}
else if ( csize > 0 )
{
size += 1; // at least: _v
}
/*if the variant is longer than our internal limit, we need
// NOW we have the full locale string..
/*if the whole string is longer than our internal limit, we need
to go to the heap for temporary buffers*/
if (size > ULOC_FULLNAME_CAPACITY)
{
char *togo_heap = new char[size+1];
togo.extract(0,size, togo_heap, "");
togo_heap[size] = '\0';
init(togo_heap);
delete []togo_heap;
}
else
{
togo.extract(0,size, myLocaleID, "");
myLocaleID[size] = '\0';
init(myLocaleID);
}
if (size > ULOC_FULLNAME_CAPACITY)
{
togo_heap = new char[size+1];
togo = togo_heap;
}
else
{
togo = togo_stack;
}
togo[0] = 0;
// Now, copy it back.
p = togo;
if ( lsize != 0 )
{
uprv_strcpy(p, newLanguage);
p += lsize;
}
if ( ( vsize != 0 ) || (csize != 0) ) // at least: __v
{ // ^
*p++ = sepchar;
}
if ( csize != 0 )
{
uprv_strcpy(p, newCountry);
p += csize;
}
if ( vsize != 0)
{
*p++ = sepchar; // at least: __v
uprv_strncpy(p, newVariant, vsize); // Must use strncpy because
p += vsize; // of trimming (above).
*p = 0; // terminate
}
// Parse it, because for example 'language' might really be a complete
// string.
init(togo);
delete [] togo_heap; /* If it was needed */
}
}
Locale::Locale(const Locale& other)
@ -227,7 +273,6 @@ Locale::Locale(const Locale& other)
/*Make the variant point to the same offset as the copied*/
variant = fullName + (other.variant - other.fullName) ;
khashCode = other.khashCode;
}
bool_t
@ -285,8 +330,6 @@ Locale& Locale::init(const char* localeID)
}
else this->variant = this->fullName + l - 1;
setHashCode();
return *this;
}
@ -308,22 +351,14 @@ Locale& Locale::operator=(const Locale& other)
/*Make the variant point to the same offset as the assigner*/
variant = fullName + (other.variant - other.fullName) ;
khashCode = other.khashCode;
return *this;
}
int32_t
Locale::hashCode() const
{
return khashCode;
}
void
Locale::setHashCode()
{
UnicodeString fullNameUString(language, "");
khashCode = fullNameUString.append(UnicodeString(country, "")).append(UnicodeString(variant, "")).hashCode();
return fullNameUString.append(UnicodeString(country, "")).append(UnicodeString(variant, "")).hashCode();
}
@ -333,14 +368,21 @@ Locale::getDefault()
return fgDefaultLocale;
}
void locale_set_default_internal(const char *id)
{
Locale::getDefault().init(id);
}
/* sfb 07/21/99 */
U_CFUNC void
locale_set_default(const char *id)
{
Locale::getDefault().init(id);
locale_set_default_internal(id);
}
/* end */
void
Locale::setDefault( const Locale& newLocale,
UErrorCode& status)
@ -352,6 +394,25 @@ Locale::setDefault( const Locale& newLocale,
fgDefaultLocale = newLocale;
}
const char *
Locale::getCountry() const
{
return country;
}
const char *
Locale::getLanguage() const
{
return language;
}
const char *
Locale::getVariant() const
{
return variant;
}
#ifndef ICU_LOCID_NO_DEPRECATES
UnicodeString&
Locale::getLanguage(UnicodeString& lang) const
{
@ -379,6 +440,7 @@ Locale::getName(UnicodeString& name) const
name = UnicodeString(fullName,"");
return name;
}
#endif
const char *
Locale::getName() const
@ -386,14 +448,20 @@ Locale::getName() const
return fullName;
}
// deprecated
UnicodeString&
Locale::getISO3Language(UnicodeString& lang) const
const char *
Locale::getISO3Language() const
{
lang = uloc_getISO3Language(fullName);
return lang;
return uloc_getISO3Language(fullName);
}
const char *
Locale::getISO3Country() const
{
return uloc_getISO3Country(fullName);
}
#ifndef ICU_LOCID_NO_DEPRECATES
UnicodeString&
Locale::getISO3Language(UnicodeString& lang, UErrorCode& status) const
{
@ -407,14 +475,6 @@ Locale::getISO3Language(UnicodeString& lang, UErrorCode& status) const
return lang;
}
// deprecated
UnicodeString&
Locale::getISO3Country(UnicodeString& cntry) const
{
cntry = uloc_getISO3Country(fullName);
return cntry;
}
UnicodeString&
Locale::getISO3Country(UnicodeString& cntry, UErrorCode& status) const
{
@ -427,6 +487,7 @@ Locale::getISO3Country(UnicodeString& cntry, UErrorCode& status) const
return cntry;
}
#endif
/**
* Return the LCID value as specified in the "LocaleID" resource for this
@ -618,11 +679,12 @@ Locale::getAvailableLocales(int32_t& count)
// for now, there is a hardcoded list, so just walk through that list and set it up.
if (localeList == 0)
{
const UnicodeString* ids = ResourceBundle::listInstalledLocales(getDataDirectory(), count);
Locale *newLocaleList = new Locale[count];
count = uloc_countAvailable();
Locale *newLocaleList = new Locale[count];
for(int32_t i = 0; i < count; i++)
newLocaleList[i].setFromPOSIXID(ids[i]);
for(int32_t i = 0; i < count; i++)
newLocaleList[i].setFromPOSIXID(uloc_getAvailable(i));
Mutex mutex;
if(localeList != 0) {
@ -637,7 +699,18 @@ Locale::getAvailableLocales(int32_t& count)
return localeList;
}
static const char* const* Locale::getISOCountries()
{
return uloc_getISOCountries();
}
static const char* const* Locale::getISOLanguages()
{
return uloc_getISOLanguages();
}
#ifndef ICU_LOCID_NO_DEPRECATES
/**
* Returns a list of all 2-letter country codes defined in ISO 3166.
* Can be used to create Locales.
@ -708,6 +781,7 @@ Locale::getISOLanguages(int32_t& count)
count = isoLanguagesCount;
return isoLanguages;
}
#endif
/**
* Given an ISO country code, returns an array of Strings containing the ISO
@ -775,24 +849,6 @@ Locale::getLanguagesForCountry(const UnicodeString& country, int32_t& count)
}
/**
* Get the path to the locale files. This path will be a platform-specific
* path name ending in a directory separator, so that file names may be
* concatenated to it.
*/
const char* Locale::getDataDirectory()
{
return u_getDataDirectory();
}
/**
* Set the path to the locale files.
*/
void Locale::setDataDirectory(const char* path)
{
u_setDataDirectory(path);
}
// ================= privates =====================================
@ -804,20 +860,86 @@ void Locale::setFromPOSIXID(const char *posixID)
init(posixID);
}
// Set the locale's data based on a posix id.
void Locale::setFromPOSIXID(const UnicodeString &posixIDString)
#ifndef ICU_LOCID_NO_DEPRECATES
// Deprecated APIs
Locale::Locale( const UnicodeString& newLanguage)
{
char onStack[20];
char* buffer;
int32_t length = posixIDString.length();
if (length >= 20) {
buffer = new char[length+1];
} else {
buffer = onStack;
}
buffer[posixIDString.extract(0, length, buffer, "")] = '\0';
init(buffer);
if (buffer != onStack) delete [] buffer;
char myLocaleID[ULOC_FULLNAME_CAPACITY];
myLocaleID[newLanguage.extract(0, 0x7fffffff, myLocaleID, "")] = '\0';
init(myLocaleID);
}
Locale::Locale( const UnicodeString& newLanguage,
const UnicodeString& newCountry)
{
UnicodeString togo(newLanguage);
char myLocaleID[ULOC_FULLNAME_CAPACITY];
if(newCountry.length()>0) {
togo += sep;
togo += newCountry;
}
myLocaleID[togo.extract(0, 0x7fffffff, myLocaleID, "")] = '\0';
init(myLocaleID);
}
Locale::Locale( const UnicodeString& newLanguage,
const UnicodeString& newCountry,
const UnicodeString& newVariant)
{
UnicodeString togo(newLanguage);
char myLocaleID[ULOC_FULLNAME_CAPACITY];
UnicodeString newVariantCopy(newVariant);
if (newCountry.length() > 0 ||
newVariantCopy.length() > 0 )
{
togo += sep;
togo += newCountry;
}
int vsize = newVariantCopy.length();
if (vsize > 0)
{
int i = 0;
//We need to trim variant codes : (_*)$var(_*) --> $var
while ((i<vsize) && newVariantCopy[i] == sep) newVariantCopy.remove(i++, 1);
i = newVariantCopy.length() - 1;
while (i && (newVariantCopy[i] == sep)) newVariantCopy.remove(i--, 1);
togo += sep ;
togo += newVariantCopy ;
}
int size = togo.length();
/*if the variant is longer than our internal limit, we need
to go to the heap for temporary buffers*/
if (size > ULOC_FULLNAME_CAPACITY)
{
char *togo_heap = new char[size+1];
togo.extract(0,size, togo_heap, "");
togo_heap[size] = '\0';
init(togo_heap);
delete []togo_heap;
}
else
{
togo.extract(0,size, myLocaleID, "");
myLocaleID[size] = '\0';
init(myLocaleID);
}
}
#endif
//eof

View file

@ -62,6 +62,8 @@
#include <iostream.h>
#include <string.h>
#include "cmemory.h"
/*-----------------------------------------------------------------------------
* Implementation Notes
*
@ -203,10 +205,13 @@ ResourceBundle::LocaleFallbackIterator::LocaleFallbackIterator(const UnicodeStri
: fLocale(startingLocale),
fRoot(root),
fUseDefaultLocale(useDefaultLocale),
// Init from the default locale, if asked for.
fDefaultLocale( (useDefaultLocale)? (Locale::getDefault().getName()) : NULL , ""),
fTriedDefaultLocale(FALSE),
fTriedRoot(FALSE)
{
if (fUseDefaultLocale) Locale::getDefault().getName(fDefaultLocale);
}
bool_t
@ -283,7 +288,7 @@ ResourceBundle::ResourceBundle( const UnicodeString& path,
* API constructor.
*/
ResourceBundle::ResourceBundle( const UnicodeString& path,
const UnicodeString& localeName,
const char *localeName,
UErrorCode& status)
: fgCache(fgUserCache),
fgVisitedFiles(fgUserVisitedFiles),
@ -304,8 +309,8 @@ ResourceBundle::ResourceBundle( const UnicodeString& path,
fLocaleIterator = 0;
// If the file doesn't exist, return an error
if(fPath.fileExists(localeName)) {
parse(fPath, localeName, saveCollationHashtable,
if(fPath.fileExists(UnicodeString(localeName,""))) {
parse(fPath, UnicodeString(localeName, ""), saveCollationHashtable,
(void*)this, fgCache, status);
}
else {
@ -373,11 +378,10 @@ ResourceBundle::constructForLocale(const PathInfo& path,
fVersionID = 0;
// fRealLocale can be inited in three ways, see 1), 2), 3)
UnicodeString returnedLocale;
locale.getName(returnedLocale);
UnicodeString returnedLocale(locale.getName(), "");
if (returnedLocale.length()!=0) {
// 1) Desired Locale has a name
fRealLocale = Locale(returnedLocale);
fRealLocale = locale;
} else {
// 2) Desired Locale name is empty, so we use default locale for the system
fRealLocale = Locale(kDefaultLocaleName);
@ -395,7 +399,14 @@ ResourceBundle::constructForLocale(const PathInfo& path,
fDataStatus[0] = U_ZERO_ERROR;
if(U_SUCCESS(error))
// 3) We're unable to get the desired Locale, so we're using what is provided (fallback occured)
fRealLocale = Locale(returnedLocale);
{
/* To avoid calling deprecated api's */
char *ch;
ch = new char[returnedLocale.size() + 1];
ch[returnedLocale.extract(0, 0x7fffffff, ch, "")] = 0;
fRealLocale = Locale(ch);
delete [] ch;
}
fLocaleIterator = new LocaleFallbackIterator(fRealLocale.getName(),
kDefaultLocaleName, FALSE);

View file

@ -20,7 +20,8 @@
* 04/24/97 aliu Numerous changes per code review.
* 08/18/98 stephen Added tokenizeString(),changed getDisplayName()
* 09/08/98 stephen Moved definition of kEmptyString for Mac Port
* 11/09/99 weiv Added const char * getName() const;
* 11/09/99 weiv Added const char * getName() const;
* 04/12/00 srl removing unicodestring api's and cached hash code
*****************************************************************************************
*/
@ -48,18 +49,13 @@ typedef struct UHashtable UHashtable;
* region, or culture.
*
* <P>
* You create a <code>Locale</code> object using one of the three constructors in
* You create a <code>Locale</code> object using the constructor in
* this class:
* <blockquote>
* <pre>
* . Locale( const UnicodeString& newLanguage);
* .
* . Locale( const UnicodeString& language,
* . const UnicodeString& country);
* .
* . Locale( const UnicodeString& language,
* . const UnicodeString& country,
* . const UnicodeString& variant);
* . Locale( const char* language,
* . const char* country,
* . const char* variant);
* </pre>
* </blockquote>
* The first argument to the constructors is a valid <STRONG>ISO
@ -200,7 +196,7 @@ public:
static const Locale KOREA;
static const Locale CHINA; // Alias for PRC
static const Locale PRC; // Peoples Republic of China
static const Locale TAIWAN; // Republic of China
static const Locale TAIWAN;
static const Locale UK;
static const Locale US;
static const Locale CANADA;
@ -220,7 +216,20 @@ public:
* @param country Uppercase two-letter ISO-3166 code. (optional)
* @param variant Uppercase vendor and browser specific code. See class
* description. (optional)
* @stable
* @draft
*/
Locale( const char * language,
const char * country = 0,
const char * variant = 0);
#ifndef ICU_LOCID_NO_DEPRECATES
/**
* Construct a locale from language, country, variant.
*
* @param language Lowercase two-letter ISO-639 code.
* @param country Uppercase two-letter ISO-3166 code. (optional)
* @param variant Uppercase vendor and browser specific code. See class
* description. (optional)
* @deprecated Remove in the first release of 2001.
*/
Locale( const UnicodeString& language,
const UnicodeString& country ,
@ -231,7 +240,7 @@ public:
*
* @param language Lowercase two-letter ISO-639 code.
* @param country Uppercase two-letter ISO-3166 code. (optional)
* @stable
* @deprecated Remove in the first release of 2001.
*/
Locale( const UnicodeString& language,
const UnicodeString& country );
@ -240,12 +249,12 @@ public:
* Construct a locale from language.
*
* @param language Lowercase two-letter ISO-639 code.
* @stable
* @deprecated Remove in the first release of 2001.
*/
Locale( const UnicodeString& language);
#endif // ICU_LOCID_NO_DEPRECATES
/**
* Initializes a Locale object from another Locale object.
*
@ -316,25 +325,71 @@ public:
static void setDefault(const Locale& newLocale,
UErrorCode& success);
/**
* Returns the locale's two-letter ISO-639 language code.
* @return An alias to the code
* @draft
*/
const char * getLanguage( ) const;
/**
* Returns the locale's two-letter ISO-3166 country code.
* @return An alias to the code
* @draft
*/
const char * getCountry( ) const;
/**
* Returns the locale's variant code.
* @return An alias to the code
* @draft
*/
const char * getVariant( ) const;
/**
* Returns the programmatic name of the entire locale, with the language,
* country and variant separated by underbars. If a field is missing, up
* to two leading underbars will occur. Example: "en", "de_DE", "en_US_WIN",
* "de__POSIX", "fr__MAC", "__MAC", "_MT", "_FR_EURO"
* @return A pointer to "name".
*/
const char * getName() const;
/**
* returns the locale's three-letter language code, as specified
* in ISO draft standard ISO-639-2..
* @return An alias to the code, or NULL
* @draft
*/
const char * getISO3Language() const;
/**
* Fills in "name" with the locale's three-letter ISO-3166 country code.
* @return An alias to the code, or NULL
* @draft
*/
const char * getISO3Country() const;
#ifndef ICU_LOCID_NO_DEPRECATES
// begin deprecated versions
/**
* Fills in "lang" with the locale's two-letter ISO-639 language code.
* @param lang Receives the language code.
* @return A reference to "lang".
* @stable
* @return A reference to "lang"
* @deprecated Remove in the first release of 2001.
*/
UnicodeString& getLanguage( UnicodeString& lang) const;
UnicodeString& getLanguage( UnicodeString& lang) const;
/**
* Fills in "cntry" with the locale's two-letter ISO-3166 country code.
* @param cntry Receives the country code.
* @return A reference to "cntry".
* @stable
* @deprecated Remove in the first release of 2001.
*/
UnicodeString& getCountry( UnicodeString& cntry) const;
UnicodeString& getCountry( UnicodeString& cntry) const;
/**
* Fills in "var" with the locale's variant code.
* @param var Receives the variant code.
* @return A reference to "var".
* @stable
* @deprecated Remove in the first release of 2001.
*/
UnicodeString& getVariant( UnicodeString& var) const;
@ -345,18 +400,10 @@ public:
* "de_POSIX", "fr_MAC"
* @param var Receives the programmatic locale name.
* @return A reference to "name".
* @stable
* @deprecated Remove in the first release of 2001.
*/
UnicodeString& getName( UnicodeString& name) const;
/**
* Returns the programmatic name of the entire locale, with the language,
* country and variant separated by underbars. If a field is missing, at
* most one underbar will occur. Example: "en", "de_DE", "en_US_WIN",
* "de_POSIX", "fr_MAC"
* @return A pointer to "name".
*/
const char * getName() const;
/**
* Fills in "name" with the locale's three-letter language code, as specified
@ -364,29 +411,21 @@ public:
* @param name Receives the three-letter language code.
* @param status An UErrorCode to receive any MISSING_RESOURCE_ERRORs
* @return A reference to "name".
* @stable
* @deprecated Remove in the first release of 2001.
*/
UnicodeString& getISO3Language(UnicodeString& name, UErrorCode& status) const;
/**
* @deprecated use getISO3Language(UnicodeString&, UErrorCode&) instead
*/
UnicodeString& getISO3Language(UnicodeString& name) const;
/**
* Fills in "name" with the locale's three-letter ISO-3166 country code.
* @param name Receives the three-letter country code.
* @param status An UErrorCode to receive any MISSING_RESOURCE_ERRORs
* @return A reference to "name".
* @stable
* @deprecated Remove in the first release of 2001.
*/
UnicodeString& getISO3Country( UnicodeString& name, UErrorCode& status) const;
/**
* @deprecated use getISO3Country(UnicodeString&, UErrorCode&); instead
*/
UnicodeString& getISO3Country( UnicodeString& name) const;
// END deprecated [ ICU_LOCID_NO_DEPRECATES ]
#endif // ICU_LOCID_NO_DEPRECATES
/**
* Returns the Windows LCID value corresponding to this locale.
* This value is stored in the resource data for the locale as a one-to-four-digit
@ -494,8 +533,7 @@ public:
UnicodeString& getDisplayName( const Locale& inLocale,
UnicodeString& name) const;
/**
* Generates a hash code for the locale. Since Locales are often used in hashtables,
* caches the value for speed.
* Generates a hash code for the locale.
* @stable
*/
int32_t hashCode(void) const;
@ -510,13 +548,35 @@ public:
*/
static const Locale* getAvailableLocales(int32_t& count);
/**
* Gets a list of all available 2-letter country codes defined in ISO 639. This is a
* pointer to an array of pointers to arrays of char. All of these pointers are
* owned by ICU-- do not delete them, and do not write through them. The array is
* terminated with a null pointer.
* @return a list of all available country codes
* @draft
*/
static const char* const* getISOCountries();
/**
* Gets a list of all available language codes defined in ISO 639. This is a pointer
* to an array of pointers to arrays of char. All of these pointers are owned
* by ICU-- do not delete them, and do not write through them. The array is
* terminated with a null pointer.
* @return a list of all available language codes
* @draft
*/
static const char* const* getISOLanguages();
#ifndef ICU_LOCID_NO_DEPRECATES
/**
* Returns a list of all 2-letter country codes defined in ISO 3166.
* Can be used to create Locales.
* @param count Receives the number of countries in the list.
* @return A pointer to an array of UnicodeString objects. The caller does NOT
* get ownership of this list, and must NOT delete it.
* @stable
* @deprecated Remove in the first release of 2001.
*/
static const UnicodeString* getISOCountries(int32_t& count);
@ -529,43 +589,12 @@ public:
* @param count Receives the number of languages in the list.
* @return A pointer to an array of UnicodeString objects. The caller does NOT
* get ownership of this list, and must NOT delete it.
* @stable
* @deprecated Remove in the first release of 2001.
*/
static const UnicodeString* getISOLanguages(int32_t& count);
/**
* Deprecated 1999dec14 - Get the path to the ResourceBundle locale files. This path will be a
* platform-specific path name ending in a directory separator, so that file
* names may be concatenated to it. This path may be changed by calling
* setDataDirectory(). If setDataDirectory() has not been called yet,
* getDataDirectory() will return a platform-dependent default path as
* specified by TPlatformUtilities::getDefaultDataDirectory().
*
* @return Current data path.
* @deprecated 1999dec14
*/
static const char* getDataDirectory(void);
/**
* Deprecated 1999dec14 - Set the path to the ResourceBundle locale files. After making this call,
* all objects in the Unicode Analytics package will read ResourceBundle
* data files in the specified directory in order to obtain locale data.
*
* @param path The new data path to be set to.
* @deprecated 1999dec14
*/
static void setDataDirectory(const char* path);
/**
* Initialize the locale object with a new name.
*
* @param cLocaleID The new locale name.
* @deprecated
*/
Locale& init(const char* cLocaleID);
#endif // ICU_LOCID_NO_DEPRECATES
protected: // only protected for testing purposes. DO NOT USE.
void setFromPOSIXID(const UnicodeString& posixID); // set it from a single string.
void setFromPOSIXID(const char *posixID); // set it from a single string.
/**
@ -588,30 +617,38 @@ protected: // only protected for testing purposes. DO NOT USE.
private:
/**
* Initializes a Locale object from a ULocale struct, which is the C locale object,
* and where the actual implementation is.
* Initialize the locale object with a new name.
* Was deprecated - used in implementation - moved internal
*
* @param cLocaleID The new locale name.
*/
Locale& init(const char* cLocaleID);
void setHashCode(void);
char language[ULOC_LANG_CAPACITY];
char country[ULOC_COUNTRY_CAPACITY];
char* variant;
char* fullName;
char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
int32_t khashCode;
static Locale *localeList;
static int32_t localeListCount;
// Begin deprecated fields
static UnicodeString *isoLanguages;
static int32_t isoLanguagesCount;
static UnicodeString *isoCountries;
static int32_t isoCountriesCount;
// End deprecated fields
static UHashtable *ctry2LangMapping;
static const UnicodeString compressedCtry2LangMapping;
static Locale fgDefaultLocale;
friend void locale_set_default_internal(const char *);
};
inline bool_t

View file

@ -509,7 +509,7 @@ private:
* mechanism.
*/
ResourceBundle( const UnicodeString& path,
const UnicodeString& localeName,
const char *localeName,
UErrorCode& status);
/**

View file

@ -739,13 +739,7 @@ UnicodeString::toUpper(const Locale& locale)
return *this;
}
UnicodeString lang;
char langChars[16];
// get char * locale language
locale.getLanguage(lang);
lang.extract(0, lang.length(), langChars, "");
langChars[lang.length()] = 0;
const char *langChars = locale.getLanguage();
UTextOffset start = 0, next = 0;
UTextOffset limit = fLength;
@ -814,13 +808,7 @@ UnicodeString::toLower(const Locale& locale)
return *this;
}
UnicodeString lang;
char langChars[16];
// get char * locale language
locale.getLanguage(lang);
lang.extract(0, lang.length(), langChars, "");
langChars[lang.length()] = 0;
const char *langChars = locale.getLanguage();
UTextOffset start = 0, next = 0;
UTextOffset limit = fLength;

View file

@ -30,26 +30,23 @@ U_CAPI UResourceBundle* ures_open( const char* myPath,
UErrorCode* status)
{
UnicodeString uPath;
Locale myLocale;
Locale myLocale(localeID); // Handles NULL properly.
if (myPath != 0) uPath = myPath;
else uPath = u_getDataDirectory();
if (localeID == 0) localeID = uloc_getDefault();
return (UResourceBundle*) new ResourceBundle(uPath, myLocale.init(localeID), *status);
return (UResourceBundle*) new ResourceBundle(uPath, myLocale, *status);
}
U_CAPI UResourceBundle* ures_openW( const wchar_t* myPath,
const char* localeID,
UErrorCode* status)
{
Locale myLocale;
Locale myLocale(localeID);
if (localeID == 0) localeID = uloc_getDefault();
return (UResourceBundle*) new ResourceBundle(myPath, myLocale.init(localeID), *status);
return (UResourceBundle*) new ResourceBundle(myPath, myLocale, *status);
}