mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-21 12:40:02 +00:00
ICU-564 Updated some comments and fixed a static memory leak.
X-SVN-Rev: 2460
This commit is contained in:
parent
81e2c44077
commit
ccdc82a514
3 changed files with 60 additions and 56 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 1997-1999, International Business Machines
|
||||
* Copyright (C) 1997-2000, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
*
|
||||
|
@ -20,6 +20,7 @@
|
|||
|
||||
|
||||
#include "unicode/uloc.h"
|
||||
#include "unicode/locid.h"
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "uresimp.h"
|
||||
|
@ -41,7 +42,7 @@ U_CFUNC int32_t T_UnicodeString_length(const UnicodeString *s);
|
|||
U_CAPI int32_t
|
||||
T_UnicodeString_extract(const UnicodeString *s, char *dst);
|
||||
|
||||
/* Locale stuff */
|
||||
/* Locale stuff from locid.cpp */
|
||||
U_CAPI void locale_set_default(const char *id);
|
||||
|
||||
/* These strings describe the resources we attempt to load from
|
||||
|
@ -62,7 +63,8 @@ static const UChar comma[] = { (UChar)0x002C /* space */, (UChar)0x0020 /* , */,
|
|||
static const UChar closeParen[] = { (UChar)0x0029 /* ( */, (UChar)0x0000};
|
||||
|
||||
|
||||
static char* _defaultLocale = NULL;
|
||||
static char _defaultLocale[ULOC_FULLNAME_CAPACITY] = "en_US";
|
||||
static UBool _emptyDefaultLocale = TRUE;
|
||||
|
||||
static char** _installedLocales = NULL;
|
||||
static int32_t _installedLocalesCount = 0;
|
||||
|
@ -204,24 +206,23 @@ static int16_t _findIndex(const char* list, int32_t listLength, const char* key)
|
|||
|
||||
const char* uloc_getDefault()
|
||||
{
|
||||
const char* result = _defaultLocale;
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
|
||||
/*lazy evaluates _defaultLocale*/
|
||||
if (result == NULL)
|
||||
if (_emptyDefaultLocale)
|
||||
{
|
||||
uloc_setDefault(NULL, &err);
|
||||
result = _defaultLocale;
|
||||
}
|
||||
|
||||
return result;
|
||||
return _defaultLocale;
|
||||
}
|
||||
|
||||
void uloc_setDefault(const char* newDefaultLocale,
|
||||
UErrorCode* err)
|
||||
{
|
||||
|
||||
if (U_FAILURE(*err)) return;
|
||||
if (U_FAILURE(*err))
|
||||
return;
|
||||
/* the error code isn't currently used for anything by this function*/
|
||||
|
||||
if (newDefaultLocale == NULL)
|
||||
|
@ -230,12 +231,9 @@ void uloc_setDefault(const char* newDefaultLocale,
|
|||
}
|
||||
|
||||
umtx_lock(NULL);
|
||||
if(_defaultLocale == NULL)
|
||||
_defaultLocale = (char*)uprv_malloc(sizeof(char) * (uprv_strlen(newDefaultLocale) + 1));
|
||||
else
|
||||
_defaultLocale = (char*)uprv_realloc(_defaultLocale,
|
||||
sizeof(char) * (uprv_strlen(newDefaultLocale) + 1));
|
||||
uprv_strcpy(_defaultLocale, newDefaultLocale);
|
||||
uprv_strncpy(_defaultLocale, newDefaultLocale, ULOC_FULLNAME_CAPACITY - 1);
|
||||
_defaultLocale[ULOC_FULLNAME_CAPACITY - 1] = 0;
|
||||
_emptyDefaultLocale = FALSE;
|
||||
umtx_unlock(NULL);
|
||||
|
||||
/* propagate change to C++ */
|
||||
|
|
|
@ -29,15 +29,19 @@
|
|||
#define LOCID_H
|
||||
|
||||
|
||||
#include "unicode/unistr.h"
|
||||
|
||||
typedef struct ULocale ULocale;
|
||||
typedef struct UHashtable UHashtable;
|
||||
#include "unicode/putil.h"
|
||||
|
||||
#define ULOC_LANG_CAPACITY 3
|
||||
#define ULOC_COUNTRY_CAPACITY 3
|
||||
#define ULOC_FULLNAME_CAPACITY 50
|
||||
|
||||
#ifdef XP_CPLUSPLUS
|
||||
|
||||
#include "unicode/unistr.h"
|
||||
|
||||
typedef struct ULocale ULocale;
|
||||
typedef struct UHashtable UHashtable;
|
||||
|
||||
/**
|
||||
*
|
||||
* A <code>Locale</code> object represents a specific geographical, political,
|
||||
|
@ -194,8 +198,8 @@ public:
|
|||
static const Locale ITALY;
|
||||
static const Locale JAPAN;
|
||||
static const Locale KOREA;
|
||||
static const Locale CHINA; // Alias for PRC
|
||||
static const Locale PRC; // Peoples Republic of China
|
||||
static const Locale CHINA; /* Alias for PRC */
|
||||
static const Locale PRC; /* Peoples Republic of China */
|
||||
static const Locale TAIWAN;
|
||||
static const Locale UK;
|
||||
static const Locale US;
|
||||
|
@ -254,7 +258,7 @@ public:
|
|||
Locale( const UnicodeString& language);
|
||||
|
||||
|
||||
#endif // ICU_LOCID_NO_DEPRECATES
|
||||
#endif /* ICU_LOCID_NO_DEPRECATES */
|
||||
/**
|
||||
* Initializes a Locale object from another Locale object.
|
||||
*
|
||||
|
@ -369,7 +373,7 @@ public:
|
|||
const char * getISO3Country() const;
|
||||
|
||||
#ifndef ICU_LOCID_NO_DEPRECATES
|
||||
// begin deprecated versions
|
||||
/* begin deprecated versions */
|
||||
|
||||
/**
|
||||
* Fills in "lang" with the locale's two-letter ISO-639 language code.
|
||||
|
@ -424,8 +428,8 @@ public:
|
|||
*/
|
||||
UnicodeString& getISO3Country( UnicodeString& name, UErrorCode& status) const;
|
||||
|
||||
// END deprecated [ ICU_LOCID_NO_DEPRECATES ]
|
||||
#endif // ICU_LOCID_NO_DEPRECATES
|
||||
/* 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
|
||||
|
@ -592,10 +596,10 @@ public:
|
|||
* @deprecated Remove in the first release of 2001.
|
||||
*/
|
||||
static const UnicodeString* getISOLanguages(int32_t& count);
|
||||
#endif // ICU_LOCID_NO_DEPRECATES
|
||||
#endif /* ICU_LOCID_NO_DEPRECATES */
|
||||
|
||||
protected: // only protected for testing purposes. DO NOT USE.
|
||||
void setFromPOSIXID(const char *posixID); // set it from a single string.
|
||||
protected: /* only protected for testing purposes. DO NOT USE. */
|
||||
void setFromPOSIXID(const char *posixID); /* set it from a single string. */
|
||||
|
||||
/**
|
||||
* Given an ISO country code, returns an array of Strings containing the ISO
|
||||
|
@ -635,12 +639,12 @@ private:
|
|||
static Locale *localeList;
|
||||
static int32_t localeListCount;
|
||||
|
||||
// Begin deprecated fields
|
||||
/* Begin deprecated fields */
|
||||
static UnicodeString *isoLanguages;
|
||||
static int32_t isoLanguagesCount;
|
||||
static UnicodeString *isoCountries;
|
||||
static int32_t isoCountriesCount;
|
||||
// End deprecated fields
|
||||
/* End deprecated fields */
|
||||
|
||||
static UHashtable *ctry2LangMapping;
|
||||
static const UnicodeString compressedCtry2LangMapping;
|
||||
|
@ -657,6 +661,7 @@ Locale::operator!=(const Locale& other) const
|
|||
return !operator==(other);
|
||||
}
|
||||
|
||||
#endif /* XP_CPLUSPLUS */
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -170,13 +170,13 @@
|
|||
*
|
||||
* Useful constants for language.
|
||||
*/
|
||||
#define ULOC_ENGLISH "en"
|
||||
#define ULOC_FRENCH "fr"
|
||||
#define ULOC_GERMAN "de"
|
||||
#define ULOC_ITALIAN "it"
|
||||
#define ULOC_JAPANESE "ja"
|
||||
#define ULOC_KOREAN "ko"
|
||||
#define ULOC_CHINESE "zh"
|
||||
#define ULOC_CHINESE "zh"
|
||||
#define ULOC_ENGLISH "en"
|
||||
#define ULOC_FRENCH "fr"
|
||||
#define ULOC_GERMAN "de"
|
||||
#define ULOC_ITALIAN "it"
|
||||
#define ULOC_JAPANESE "ja"
|
||||
#define ULOC_KOREAN "ko"
|
||||
#define ULOC_SIMPLIFIED_CHINESE "zh_CN"
|
||||
#define ULOC_TRADITIONAL_CHINESE "zh_TW"
|
||||
|
||||
|
@ -184,27 +184,28 @@
|
|||
*
|
||||
* Useful constants for country.
|
||||
*/
|
||||
#define ULOC_FRANCE "fr_FR"
|
||||
#define ULOC_GERMANY "de_DE"
|
||||
#define ULOC_ITALY "it_IT"
|
||||
#define ULOC_JAPAN "ja_JP"
|
||||
#define ULOC_KOREA "ko_KR"
|
||||
#define ULOC_CHINA "zh_CN"
|
||||
#define ULOC_PRC "zh_CN"
|
||||
#define ULOC_TAIWAN "zh_TW"
|
||||
#define ULOC_UK "en_GB"
|
||||
#define ULOC_US "en_US"
|
||||
#define ULOC_CANADA "en_CA"
|
||||
#define ULOC_CANADA_FRENCH "fr_CA"
|
||||
#define ULOC_CANADA "en_CA"
|
||||
#define ULOC_CANADA_FRENCH "fr_CA"
|
||||
#define ULOC_CHINA "zh_CN"
|
||||
#define ULOC_PRC "zh_CN"
|
||||
#define ULOC_FRANCE "fr_FR"
|
||||
#define ULOC_GERMANY "de_DE"
|
||||
#define ULOC_ITALY "it_IT"
|
||||
#define ULOC_JAPAN "ja_JP"
|
||||
#define ULOC_KOREA "ko_KR"
|
||||
#define ULOC_TAIWAN "zh_TW"
|
||||
#define ULOC_UK "en_GB"
|
||||
#define ULOC_US "en_US"
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the system's default locale. This pointer may become invalid if the uloc_setDefault()
|
||||
* is called.
|
||||
* Gets ICU's default locale. This pointer and/or the contents of the pointer may
|
||||
* become invalid if the uloc_setDefault() is called, so copy the contents of the
|
||||
* pointer before calling uloc_setDefault().
|
||||
*
|
||||
* @return the system default locale
|
||||
* @return the ICU default locale
|
||||
* @system
|
||||
* @stable
|
||||
*/
|
||||
|
@ -213,10 +214,10 @@ U_CAPI const char* U_EXPORT2
|
|||
uloc_getDefault(void);
|
||||
|
||||
/**
|
||||
* Sets the system's default locale. Call this once during setup or program initialization.
|
||||
* This is a system API.
|
||||
* Sets ICU's default locale. Call this once during setup or program initialization.
|
||||
*
|
||||
* @param localeID the new system default locale
|
||||
* @param localeID the new ICU default locale. A value of NULL will try to get
|
||||
* the system's default locale.
|
||||
* @param status the error information if the setting of default locale fails
|
||||
* @system
|
||||
* @stable
|
||||
|
@ -464,7 +465,7 @@ uloc_getISOCountries(void);
|
|||
* Deprecated 1999dec14 - Gets the directory containing the locale data files.
|
||||
*
|
||||
* @return the locale data file directory
|
||||
* @deprecated 1999dec14
|
||||
* @deprecated 1999dec14 - Remove after 2000dec14
|
||||
*/
|
||||
#define uloc_getDataDirectory u_getDataDirectory
|
||||
|
||||
|
@ -472,7 +473,7 @@ uloc_getISOCountries(void);
|
|||
* Deprecated 1999dec14 - Sets the directory containing the locale data files.
|
||||
*
|
||||
* @return the new directory to fetch locale data from
|
||||
* @deprecated 1999dec14
|
||||
* @deprecated 1999dec14 - Remove after 2000dec14
|
||||
*/
|
||||
#define uloc_setDataDirectory u_setDataDirectory
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue