Localepublic final class Locale extends Object implements Serializable, CloneableA Locale object represents a specific geographical, political,
or cultural region. An operation that requires a Locale to perform
its task is called locale-sensitive and uses the Locale
to tailor information for the user. For example, displaying a number
is a locale-sensitive operation--the number should be formatted
according to the customs/conventions of the user's native country,
region, or culture.
Create a Locale object using the constructors in this class:
Locale(String language)
Locale(String language, String country)
Locale(String language, String country, String variant)
The language argument is a valid ISO Language Code.
These codes are the lower-case, two-letter codes as defined by ISO-639.
You can find a full list of these codes at a number of sites, such as:
http://www.loc.gov/standards/iso639-2/englangn.html
The country argument is a valid ISO Country Code. These
codes are the upper-case, two-letter codes as defined by ISO-3166.
You can find a full list of these codes at a number of sites, such as:
http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html
The variant argument is a vendor or browser-specific code.
For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX.
Where there are two variants, separate them with an underscore, and
put the most important one first. For example, a Traditional Spanish collation
might construct a locale with parameters for language, country and variant as:
"es", "ES", "Traditional_WIN".
Because a Locale object is just an identifier for a region,
no validity check is performed when you construct a Locale .
If you want to see whether particular resources are available for the
Locale you construct, you must query those resources. For
example, ask the NumberFormat for the locales it supports
using its getAvailableLocales method.
Note: When you ask for a resource for a particular
locale, you get back the best available match, not necessarily
precisely what you asked for. For more information, look at
{@link ResourceBundle}.
The Locale class provides a number of convenient constants
that you can use to create Locale objects for commonly used
locales. For example, the following creates a Locale object
for the United States:
Locale.US
Once you've created a Locale you can query it for information about
itself. Use getCountry to get the ISO Country Code and
getLanguage to get the ISO Language Code. You can
use getDisplayCountry to get the
name of the country suitable for displaying to the user. Similarly,
you can use getDisplayLanguage to get the name of
the language suitable for displaying to the user. Interestingly,
the getDisplayXXX methods are themselves locale-sensitive
and have two versions: one that uses the default locale and one
that uses the locale specified as an argument.
The Java Platform provides a number of classes that perform locale-sensitive
operations. For example, the NumberFormat class formats
numbers, currency, or percentages in a locale-sensitive manner. Classes
such as NumberFormat have a number of convenience methods
for creating a default object of that type. For example, the
NumberFormat class provides these three convenience methods
for creating a default NumberFormat object:
NumberFormat.getInstance()
NumberFormat.getCurrencyInstance()
NumberFormat.getPercentInstance()
These methods have two variants; one with an explicit locale
and one without; the latter using the default locale.
NumberFormat.getInstance(myLocale)
NumberFormat.getCurrencyInstance(myLocale)
NumberFormat.getPercentInstance(myLocale)
A Locale is the mechanism for identifying the kind of object
(NumberFormat ) that you would like to get. The locale is
just a mechanism for identifying objects,
not a container for the objects themselves. |
Fields Summary |
---|
private static final ConcurrentHashMap | cache | public static final Locale | ENGLISHUseful constant for language. | public static final Locale | FRENCHUseful constant for language. | public static final Locale | GERMANUseful constant for language. | public static final Locale | ITALIANUseful constant for language. | public static final Locale | JAPANESEUseful constant for language. | public static final Locale | KOREANUseful constant for language. | public static final Locale | CHINESEUseful constant for language. | public static final Locale | SIMPLIFIED_CHINESEUseful constant for language. | public static final Locale | TRADITIONAL_CHINESEUseful constant for language. | public static final Locale | FRANCEUseful constant for country. | public static final Locale | GERMANYUseful constant for country. | public static final Locale | ITALYUseful constant for country. | public static final Locale | JAPANUseful constant for country. | public static final Locale | KOREAUseful constant for country. | public static final Locale | CHINAUseful constant for country. | public static final Locale | PRCUseful constant for country. | public static final Locale | TAIWANUseful constant for country. | public static final Locale | UKUseful constant for country. | public static final Locale | USUseful constant for country. | public static final Locale | CANADAUseful constant for country. | public static final Locale | CANADA_FRENCHUseful constant for country. | public static final Locale | ROOTUseful constant for the root locale. The root locale is the locale whose
language, country, and variant are empty ("") strings. This is regarded
as the base locale of all locales, and is used as the language/country
neutral locale for the locale sensitive operations. | static final long | serialVersionUIDserialization ID | private static final int | DISPLAY_LANGUAGEDisplay types for retrieving localized names from the name providers. | private static final int | DISPLAY_COUNTRY | private static final int | DISPLAY_VARIANT | private final String | language | private final String | country | private final String | variant | private volatile int | hashcodePlaceholder for the object's hash code. Always -1. | private volatile transient int | hashCodeValueCalculated hashcode to fix 4518797. | private static Locale | defaultLocale | private static volatile String[] | isoLanguages | private static volatile String[] | isoCountries |
Constructors Summary |
---|
public Locale(String language, String country, String variant)Construct a locale from language, country, variant.
NOTE: ISO 639 is not a stable standard; some of the language codes it defines
(specifically iw, ji, and in) have changed. This constructor accepts both the
old codes (iw, ji, and in) and the new codes (he, yi, and id), but all other
API on Locale will return only the OLD codes.
this.language = convertOldISOCodes(language);
this.country = toUpperCase(country).intern();
this.variant = variant.intern();
| public Locale(String language, String country)Construct a locale from language, country.
NOTE: ISO 639 is not a stable standard; some of the language codes it defines
(specifically iw, ji, and in) have changed. This constructor accepts both the
old codes (iw, ji, and in) and the new codes (he, yi, and id), but all other
API on Locale will return only the OLD codes.
this(language, country, "");
| public Locale(String language)Construct a locale from a language code.
NOTE: ISO 639 is not a stable standard; some of the language codes it defines
(specifically iw, ji, and in) have changed. This constructor accepts both the
old codes (iw, ji, and in) and the new codes (he, yi, and id), but all other
API on Locale will return only the OLD codes.
this(language, "", "");
| private Locale(String language, String country, boolean flag)Constructs a Locale using language
and country . This constructor assumes that
language and contry are interned and
it is invoked by createSingleton only. (flag is just for
avoiding the conflict with the public constructors.
this.language = language;
this.country = country;
this.variant = "";
|
Methods Summary |
---|
public java.lang.Object | clone()Overrides Cloneable
try {
Locale that = (Locale)super.clone();
return that;
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
| private static java.lang.String[] | composeList(java.text.MessageFormat format, java.lang.String[] list)Given a list of strings, return a list shortened to three elements.
Shorten it by applying the given format to the first two elements
recursively.
if (list.length <= 3) return list;
// Use the given format to compose the first two elements into one
String[] listItems = { list[0], list[1] };
String newItem = format.format(listItems);
// Form a new list one element shorter
String[] newList = new String[list.length-1];
System.arraycopy(list, 2, newList, 1, newList.length-1);
newList[0] = newItem;
// Recurse
return composeList(format, newList);
| private java.lang.String | convertOldISOCodes(java.lang.String language)
// we accept both the old and the new ISO codes for the languages whose ISO
// codes have changed, but we always store the OLD code, for backward compatibility
language = toLowerCase(language).intern();
if (language == "he") {
return "iw";
} else if (language == "yi") {
return "ji";
} else if (language == "id") {
return "in";
} else {
return language;
}
| private static java.util.Locale | createSingleton(java.lang.String key, java.lang.String language, java.lang.String country)Creates a Locale instance with the given
language and counry and puts the
instance under the given key in the cache. This
method must be called only when initializing the Locale
constants.
Locale locale = new Locale(language, country, false);
cache.put(key, locale);
return locale;
| public boolean | equals(java.lang.Object obj)Returns true if this Locale is equal to another object. A Locale is
deemed equal to another Locale with identical language, country,
and variant, and unequal to all other objects.
if (this == obj) // quick check
return true;
if (!(obj instanceof Locale))
return false;
Locale other = (Locale) obj;
return language == other.language
&& country == other.country
&& variant == other.variant;
| private static java.lang.String | formatList(java.lang.String[] stringList, java.lang.String listPattern, java.lang.String listCompositionPattern)Format a list using given pattern strings.
If either of the patterns is null, then a the list is
formatted by concatenation with the delimiter ','.
// If we have no list patterns, compose the list in a simple,
// non-localized way.
if (listPattern == null || listCompositionPattern == null) {
StringBuffer result = new StringBuffer();
for (int i=0; i<stringList.length; ++i) {
if (i>0) result.append(',");
result.append(stringList[i]);
}
return result.toString();
}
// Compose the list down to three elements if necessary
if (stringList.length > 3) {
MessageFormat format = new MessageFormat(listCompositionPattern);
stringList = composeList(format, stringList);
}
// Rebuild the argument list with the list length as the first element
Object[] args = new Object[stringList.length + 1];
System.arraycopy(stringList, 0, args, 1, stringList.length);
args[0] = new Integer(stringList.length);
// Format it using the pattern in the resource
MessageFormat format = new MessageFormat(listPattern);
return format.format(args);
| public static java.util.Locale[] | getAvailableLocales()Returns an array of all installed locales.
The returned array represents the union of locales supported
by the Java runtime environment and by installed
{@link java.util.spi.LocaleServiceProvider LocaleServiceProvider}
implementations. It must contain at least a Locale
instance equal to {@link java.util.Locale#US Locale.US}.
return LocaleServiceProviderPool.getAllAvailableLocales();
| public java.lang.String | getCountry()Returns the country/region code for this locale, which will
either be the empty string or an uppercase ISO 3166 2-letter code.
return country;
| public static java.util.Locale | getDefault()Gets the current value of the default locale for this instance
of the Java Virtual Machine.
The Java Virtual Machine sets the default locale during startup
based on the host environment. It is used by many locale-sensitive
methods if no locale is explicitly specified.
It can be changed using the
{@link #setDefault(java.util.Locale) setDefault} method.
// do not synchronize this method - see 4071298
// it's OK if more than one default locale happens to be created
if (defaultLocale == null) {
String language, region, country, variant;
language = (String) AccessController.doPrivileged(
new GetPropertyAction("user.language", "en"));
// for compatibility, check for old user.region property
region = (String) AccessController.doPrivileged(
new GetPropertyAction("user.region"));
if (region != null) {
// region can be of form country, country_variant, or _variant
int i = region.indexOf('_");
if (i >= 0) {
country = region.substring(0, i);
variant = region.substring(i + 1);
} else {
country = region;
variant = "";
}
} else {
country = (String) AccessController.doPrivileged(
new GetPropertyAction("user.country", ""));
variant = (String) AccessController.doPrivileged(
new GetPropertyAction("user.variant", ""));
}
defaultLocale = getInstance(language, country, variant);
}
return defaultLocale;
| public final java.lang.String | getDisplayCountry()Returns a name for the locale's country that is appropriate for display to the
user.
If possible, the name returned will be localized for the default locale.
For example, if the locale is fr_FR and the default locale
is en_US, getDisplayCountry() will return "France"; if the locale is en_US and
the default locale is fr_FR, getDisplayCountry() will return "Etats-Unis".
If the name returned cannot be localized for the default locale,
(say, we don't have a Japanese name for Croatia),
this function falls back on the English name, and uses the ISO code as a last-resort
value. If the locale doesn't specify a country, this function returns the empty string.
return getDisplayCountry(getDefault());
| public java.lang.String | getDisplayCountry(java.util.Locale inLocale)Returns a name for the locale's country that is appropriate for display to the
user.
If possible, the name returned will be localized according to inLocale.
For example, if the locale is fr_FR and inLocale
is en_US, getDisplayCountry() will return "France"; if the locale is en_US and
inLocale is fr_FR, getDisplayCountry() will return "Etats-Unis".
If the name returned cannot be localized according to inLocale.
(say, we don't have a Japanese name for Croatia),
this function falls back on the English name, and finally
on the ISO code as a last-resort value. If the locale doesn't specify a country,
this function returns the empty string.
return getDisplayString(country, inLocale, DISPLAY_COUNTRY);
| public final java.lang.String | getDisplayLanguage()Returns a name for the locale's language that is appropriate for display to the
user.
If possible, the name returned will be localized for the default locale.
For example, if the locale is fr_FR and the default locale
is en_US, getDisplayLanguage() will return "French"; if the locale is en_US and
the default locale is fr_FR, getDisplayLanguage() will return "anglais".
If the name returned cannot be localized for the default locale,
(say, we don't have a Japanese name for Croatian),
this function falls back on the English name, and uses the ISO code as a last-resort
value. If the locale doesn't specify a language, this function returns the empty string.
return getDisplayLanguage(getDefault());
| public java.lang.String | getDisplayLanguage(java.util.Locale inLocale)Returns a name for the locale's language that is appropriate for display to the
user.
If possible, the name returned will be localized according to inLocale.
For example, if the locale is fr_FR and inLocale
is en_US, getDisplayLanguage() will return "French"; if the locale is en_US and
inLocale is fr_FR, getDisplayLanguage() will return "anglais".
If the name returned cannot be localized according to inLocale,
(say, we don't have a Japanese name for Croatian),
this function falls back on the English name, and finally
on the ISO code as a last-resort value. If the locale doesn't specify a language,
this function returns the empty string.
return getDisplayString(language, inLocale, DISPLAY_LANGUAGE);
| public final java.lang.String | getDisplayName()Returns a name for the locale that is appropriate for display to the
user. This will be the values returned by getDisplayLanguage(), getDisplayCountry(),
and getDisplayVariant() assembled into a single string. The display name will have
one of the following forms:
language (country, variant)
language (country)
language (variant)
country (variant)
language
country
variant
depending on which fields are specified in the locale. If the language, country,
and variant fields are all empty, this function returns the empty string.
return getDisplayName(getDefault());
| public java.lang.String | getDisplayName(java.util.Locale inLocale)Returns a name for the locale that is appropriate for display to the
user. This will be the values returned by getDisplayLanguage(), getDisplayCountry(),
and getDisplayVariant() assembled into a single string. The display name will have
one of the following forms:
language (country, variant)
language (country)
language (variant)
country (variant)
language
country
variant
depending on which fields are specified in the locale. If the language, country,
and variant fields are all empty, this function returns the empty string.
OpenListResourceBundle bundle = LocaleData.getLocaleNames(inLocale);
String languageName = getDisplayLanguage(inLocale);
String countryName = getDisplayCountry(inLocale);
String[] variantNames = getDisplayVariantArray(bundle, inLocale);
// Get the localized patterns for formatting a display name.
String displayNamePattern = null;
String listPattern = null;
String listCompositionPattern = null;
try {
displayNamePattern = bundle.getString("DisplayNamePattern");
listPattern = bundle.getString("ListPattern");
listCompositionPattern = bundle.getString("ListCompositionPattern");
} catch (MissingResourceException e) {
}
// The display name consists of a main name, followed by qualifiers.
// Typically, the format is "MainName (Qualifier, Qualifier)" but this
// depends on what pattern is stored in the display locale.
String mainName = null;
String[] qualifierNames = null;
// The main name is the language, or if there is no language, the country.
// If there is neither language nor country (an anomalous situation) then
// the display name is simply the variant's display name.
if (languageName.length() != 0) {
mainName = languageName;
if (countryName.length() != 0) {
qualifierNames = new String[variantNames.length + 1];
System.arraycopy(variantNames, 0, qualifierNames, 1, variantNames.length);
qualifierNames[0] = countryName;
}
else qualifierNames = variantNames;
}
else if (countryName.length() != 0) {
mainName = countryName;
qualifierNames = variantNames;
}
else {
return formatList(variantNames, listPattern, listCompositionPattern);
}
// Create an array whose first element is the number of remaining
// elements. This serves as a selector into a ChoiceFormat pattern from
// the resource. The second and third elements are the main name and
// the qualifier; if there are no qualifiers, the third element is
// unused by the format pattern.
Object[] displayNames = {
new Integer(qualifierNames.length != 0 ? 2 : 1),
mainName,
// We could also just call formatList() and have it handle the empty
// list case, but this is more efficient, and we want it to be
// efficient since all the language-only locales will not have any
// qualifiers.
qualifierNames.length != 0 ? formatList(qualifierNames, listPattern, listCompositionPattern) : null
};
if (displayNamePattern != null) {
return new MessageFormat(displayNamePattern).format(displayNames);
}
else {
// If we cannot get the message format pattern, then we use a simple
// hard-coded pattern. This should not occur in practice unless the
// installation is missing some core files (FormatData etc.).
StringBuilder result = new StringBuilder();
result.append((String)displayNames[1]);
if (displayNames.length > 2) {
result.append(" (");
result.append((String)displayNames[2]);
result.append(')");
}
return result.toString();
}
| private java.lang.String | getDisplayString(java.lang.String code, java.util.Locale inLocale, int type)
if (code.length() == 0) {
return "";
}
if (inLocale == null) {
throw new NullPointerException();
}
try {
OpenListResourceBundle bundle = LocaleData.getLocaleNames(inLocale);
String key = (type == DISPLAY_VARIANT ? "%%"+code : code);
String result = null;
// Check whether a provider can provide an implementation that's closer
// to the requested locale than what the Java runtime itself can provide.
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(LocaleNameProvider.class);
if (pool.hasProviders()) {
result = pool.getLocalizedObject(
LocaleNameGetter.INSTANCE,
inLocale, bundle, key,
type, code);
}
if (result == null) {
result = bundle.getString(key);
}
if (result != null) {
return result;
}
}
catch (Exception e) {
// just fall through
}
return code;
| public final java.lang.String | getDisplayVariant()Returns a name for the locale's variant code that is appropriate for display to the
user. If possible, the name will be localized for the default locale. If the locale
doesn't specify a variant code, this function returns the empty string.
return getDisplayVariant(getDefault());
| public java.lang.String | getDisplayVariant(java.util.Locale inLocale)Returns a name for the locale's variant code that is appropriate for display to the
user. If possible, the name will be localized for inLocale. If the locale
doesn't specify a variant code, this function returns the empty string.
if (variant.length() == 0)
return "";
OpenListResourceBundle bundle = LocaleData.getLocaleNames(inLocale);
String names[] = getDisplayVariantArray(bundle, inLocale);
// Get the localized patterns for formatting a list, and use
// them to format the list.
String listPattern = null;
String listCompositionPattern = null;
try {
listPattern = bundle.getString("ListPattern");
listCompositionPattern = bundle.getString("ListCompositionPattern");
} catch (MissingResourceException e) {
}
return formatList(names, listPattern, listCompositionPattern);
| private java.lang.String[] | getDisplayVariantArray(sun.util.resources.OpenListResourceBundle bundle, java.util.Locale inLocale)Return an array of the display names of the variant.
// Split the variant name into tokens separated by '_'.
StringTokenizer tokenizer = new StringTokenizer(variant, "_");
String[] names = new String[tokenizer.countTokens()];
// For each variant token, lookup the display name. If
// not found, use the variant name itself.
for (int i=0; i<names.length; ++i) {
names[i] = getDisplayString(tokenizer.nextToken(),
inLocale, DISPLAY_VARIANT);
}
return names;
| private static final java.lang.String[] | getISO2Table(java.lang.String table)
int len = table.length() / 5;
String[] isoTable = new String[len];
for (int i = 0, j = 0; i < len; i++, j += 5) {
isoTable[i] = table.substring(j, j + 2);
}
return isoTable;
| private static final java.lang.String | getISO3Code(java.lang.String iso2Code, java.lang.String table)
int codeLength = iso2Code.length();
if (codeLength == 0) {
return "";
}
int tableLength = table.length();
int index = tableLength;
if (codeLength == 2) {
char c1 = iso2Code.charAt(0);
char c2 = iso2Code.charAt(1);
for (index = 0; index < tableLength; index += 5) {
if (table.charAt(index) == c1
&& table.charAt(index + 1) == c2) {
break;
}
}
}
return index < tableLength ? table.substring(index + 2, index + 5) : null;
| public java.lang.String | getISO3Country()Returns a three-letter abbreviation for this locale's country. If the locale
doesn't specify a country, this will be the empty string. Otherwise, this will
be an uppercase ISO 3166 3-letter country code.
The ISO 3166-2 country codes can be found on-line at
http://www.davros.org/misc/iso3166.txt .
String country3 = getISO3Code(country, LocaleISOData.isoCountryTable);
if (country3 == null) {
throw new MissingResourceException("Couldn't find 3-letter country code for "
+ country, "FormatData_" + toString(), "ShortCountry");
}
return country3;
| public java.lang.String | getISO3Language()Returns a three-letter abbreviation for this locale's language. If the locale
doesn't specify a language, this will be the empty string. Otherwise, this will
be a lowercase ISO 639-2/T language code.
The ISO 639-2 language codes can be found on-line at
http://www.loc.gov/standards/iso639-2/englangn.html .
String language3 = getISO3Code(language, LocaleISOData.isoLanguageTable);
if (language3 == null) {
throw new MissingResourceException("Couldn't find 3-letter language code for "
+ language, "FormatData_" + toString(), "ShortLanguage");
}
return language3;
| public static java.lang.String[] | getISOCountries()Returns a list of all 2-letter country codes defined in ISO 3166.
Can be used to create Locales.
if (isoCountries == null) {
isoCountries = getISO2Table(LocaleISOData.isoCountryTable);
}
String[] result = new String[isoCountries.length];
System.arraycopy(isoCountries, 0, result, 0, isoCountries.length);
return result;
| public static java.lang.String[] | getISOLanguages()Returns a list of all 2-letter language codes defined in ISO 639.
Can be used to create Locales.
[NOTE: ISO 639 is not a stable standard-- some languages' codes have changed.
The list this function returns includes both the new and the old codes for the
languages whose codes have changed.]
if (isoLanguages == null) {
isoLanguages = getISO2Table(LocaleISOData.isoLanguageTable);
}
String[] result = new String[isoLanguages.length];
System.arraycopy(isoLanguages, 0, result, 0, isoLanguages.length);
return result;
| static java.util.Locale | getInstance(java.lang.String language, java.lang.String country, java.lang.String variant)Returns a Locale constructed from the given
language , country and
variant . If the same Locale instance
is available in the cache, then that instance is
returned. Otherwise, a new Locale instance is
created and cached.
if (language== null || country == null || variant == null) {
throw new NullPointerException();
}
StringBuilder sb = new StringBuilder();
sb.append(language).append('_").append(country).append('_").append(variant);
String key = sb.toString();
Locale locale = cache.get(key);
if (locale == null) {
locale = new Locale(language, country, variant);
Locale l = cache.putIfAbsent(key, locale);
if (l != null) {
locale = l;
}
}
return locale;
| public java.lang.String | getLanguage()Returns the language code for this locale, which will either be the empty string
or a lowercase ISO 639 code.
NOTE: ISO 639 is not a stable standard-- some languages' codes have changed.
Locale's constructor recognizes both the new and the old codes for the languages
whose codes have changed, but this function always returns the old code. If you
want to check for a specific language whose code has changed, don't do
if (locale.getLanguage().equals("he"))
...
Instead, do
if (locale.getLanguage().equals(new Locale("he", "", "").getLanguage()))
...
return language;
| public java.lang.String | getVariant()Returns the variant code for this locale.
return variant;
| public int | hashCode()Override hashCode.
Since Locales are often used in hashtables, caches the value
for speed.
int hc = hashCodeValue;
if (hc == 0) {
hc = (language.hashCode() << 8) ^ country.hashCode() ^ (variant.hashCode() << 4);
hashCodeValue = hc;
}
return hc;
| private java.lang.Object | readResolve()Replace the deserialized Locale object with a newly
created object. Newer language codes are replaced with older ISO
codes. The country and variant codes are replaced with internalized
String copies.
return getInstance(language, country, variant);
| public static synchronized void | setDefault(java.util.Locale newLocale)Sets the default locale for this instance of the Java Virtual Machine.
This does not affect the host locale.
If there is a security manager, its checkPermission
method is called with a PropertyPermission("user.language", "write")
permission before the default locale is changed.
The Java Virtual Machine sets the default locale during startup
based on the host environment. It is used by many locale-sensitive
methods if no locale is explicitly specified.
Since changing the default locale may affect many different areas
of functionality, this method should only be used if the caller
is prepared to reinitialize locale-sensitive code running
within the same Java Virtual Machine.
if (newLocale == null)
throw new NullPointerException("Can't set default locale to NULL");
SecurityManager sm = System.getSecurityManager();
if (sm != null) sm.checkPermission(new PropertyPermission
("user.language", "write"));
defaultLocale = newLocale;
| private java.lang.String | toLowerCase(java.lang.String str)
/*
* Locale needs its own, locale insensitive version of toLowerCase to
* avoid circularity problems between Locale and String.
* The most straightforward algorithm is used. Look at optimizations later.
*/
char[] buf = new char[str.length()];
for (int i = 0; i < buf.length; i++) {
buf[i] = Character.toLowerCase(str.charAt(i));
}
return new String( buf );
| public final java.lang.String | toString()Getter for the programmatic name of the entire locale,
with the language, country and variant separated by underbars.
Language is always lower case, and country is always upper case.
If the language is missing, the string will begin with an underbar.
If both the language and country fields are missing, this function
will return the empty string, even if the variant field is filled in
(you can't have a locale with just a variant-- the variant must accompany
a valid language or country code).
Examples: "en", "de_DE", "_GB", "en_US_WIN", "de__POSIX", "fr__MAC"
boolean l = language.length() != 0;
boolean c = country.length() != 0;
boolean v = variant.length() != 0;
StringBuilder result = new StringBuilder(language);
if (c||(l&&v)) {
result.append('_").append(country); // This may just append '_'
}
if (v&&(l||c)) {
result.append('_").append(variant);
}
return result.toString();
| private java.lang.String | toUpperCase(java.lang.String str)
char[] buf = new char[str.length()];
for (int i = 0; i < buf.length; i++) {
buf[i] = Character.toUpperCase(str.charAt(i));
}
return new String( buf );
|
|