com.ibm.icu.util
public static final class ULocale.Builder extends java.lang.Object
Builder supports the 'langtag' production of RFC 4646. Language tags consist of the ASCII digits, upper and lower case letters, and hyphen (which appears only as a field separator). As a convenience, underscores are accepted and normalized to hyphen. Values with any other character are ill-formed. Since language tags are case-insensitive, they are normalized to lower case, case distinctions are not preserved by the builder.
Note that since this implements 'langtag' and not 'Language-Tag',
grandfathered language tags are not supported by the builder.
Clients should use ULocale.forLanguageTag(java.lang.String)
instead.
Builders can be reused; clear()
resets all fields
to their default values.
Constructor and Description |
---|
ULocale.Builder()
Constructs an empty Builder.
|
Modifier and Type | Method and Description |
---|---|
ULocale.Builder |
clear()
Resets the builder to its initial, default state.
|
ULocale.Builder |
clearExtensions()
Resets the extensions to their initial, default state.
|
ULocale |
create()
Returns an instance of locale created from the fields set
on this builder.
|
ULocale.Builder |
setExtension(char key,
java.lang.String value)
Sets the extension for the given key.
|
ULocale.Builder |
setLanguage(java.lang.String language)
Sets the language.
|
ULocale.Builder |
setLanguageTag(java.lang.String langtag)
Resets the builder to match the provided language tag.
|
ULocale.Builder |
setLDMLExtensionValue(java.lang.String key,
java.lang.String value)
Sets the LDML keyword value ('type') for the given key.
|
ULocale.Builder |
setLocale(ULocale loc)
Resets the builder to match the provided locale.
|
ULocale.Builder |
setRegion(java.lang.String region)
Sets the region.
|
ULocale.Builder |
setScript(java.lang.String script)
Sets the script.
|
ULocale.Builder |
setVariant(java.lang.String variant)
Sets the variant.
|
public ULocale.Builder()
public ULocale.Builder setLocale(ULocale loc)
loc
- the localeIllformedLocaleException
- if loc
has any ill-formed
fields.public ULocale.Builder setLanguageTag(java.lang.String langtag)
langtag
- the language tagIllformedLocaleException
- if langtag
is ill-formed.ULocale.forLanguageTag(String)
public ULocale.Builder setLanguage(java.lang.String language)
language
- the languageIllformedLocaleException
- if language
is ill-formedpublic ULocale.Builder setScript(java.lang.String script)
script
- the scriptIllformedLocaleException
- if script
is ill-formedpublic ULocale.Builder setRegion(java.lang.String region)
region
- the regionIllformedLocaleException
- if region
is ill-formedpublic ULocale.Builder setVariant(java.lang.String variant)
variant
- the variantIllformedLocaleException
- if variant
is ill-formedpublic ULocale.Builder setExtension(char key, java.lang.String value)
[0-9A-WY-Za-wy-z]
. Well-formed
values are any series of fields of two to eight
alphanumeric characters, separated by hyphen or underscore.
note:The extension 'u' is used for LDML Keywords. Setting the 'u' extension replaces any existing LDML keywords with those defined in the extension. To be well-formed, a value for the 'u' extension must meet the additional constraint that the number of fields be even (fields represent key value pairs, where the value is mandatory), and that the keys and values be legal locale extension keys and values.
key
- the extension keyvalue
- the extension valueIllformedLocaleException
- if key
is illegal
or value
is ill-formedsetLDMLExtensionValue(java.lang.String, java.lang.String)
public ULocale.Builder setLDMLExtensionValue(java.lang.String key, java.lang.String value)
Note:Setting the 'u' extension replaces all LDML keywords with those defined in the extension.
key
- the LDML extension keyvalue
- the LDML extension valueIllformedLocaleException
- if key
or value
is ill-formedsetExtension(char, String)
public ULocale.Builder clear()
public ULocale.Builder clearExtensions()
setExtension(char, String)
public ULocale create()
Copyright (c) 2009 IBM Corporation and others.