Top Description Fields Constructors Methods
com.ibm.icu.impl

public final Class LocaleIDParser

extends Object
Class Inheritance
Imports
java.util.Collections, .Comparator, .Iterator, .Map, .TreeMap, com.ibm.icu.impl.locale.AsciiUtil

Utility class to parse and normalize locale ids (including POSIX style)

Field Summary

Modifier and TypeField and Description
pack-priv String
private StringBuilder
buffer

Temporary buffer for parsed sections of data.

private boolean
private static final char
private static final char
DONE

Character to indicate no more text is available in the id.

private static final char
private boolean
private static final char
private char[]
id

Char array representing the locale ID.

private int
index

Current position in id (while parsing).

private static final char
private static final char
private static final char
KEYWORD_SEPARATOR

Parsing constants.

pack-priv Map<String, String>
private static final char

Constructor Summary

AccessConstructor and Description
public
public
LocaleIDParser(String localeID, boolean canonicalize)

Method Summary

Modifier and TypeMethod and Description
private void
private void
append(char c)

Append c to the buffer.

private void
append(String s)

Append the string to the buffer.

private boolean
atTerminator()

Returns true if the character at index in the id is a terminator.

public void
defaultKeywordValue(String keywordName, String value)

Set the keyword value only if it is not already set to something else.

public String
getBaseName()

Returns the normalized base form of the locale id. The base form does not include keywords.

public String
getCountry()

return the normalized country id, or the empty string.

private Comparator<String>
private String
public Map<String, String>
getKeywordMap()

Returns a map of the keywords and values, or null if there are none.

public Iterator<String>
getKeywords()

Returns an iterator over the keywords, or null if we have an empty map.

public String
getKeywordValue(String keywordName)

Returns the value for the named keyword, or null if the keyword is not present.

public String
getLanguage()

Returns the normalized language id, or the empty string.

public String[]
getLanguageScriptCountryVariant()

Returns the language, script, country, and variant as separate strings.

public String
getName()

Returns the normalized full form of the locale id. The full form includes keywords if they are present.

public String
getScript()

Returns the normalized script id, or the empty string.

private String
getString(int start)

Returns the text in the buffer from start to blen as a String.

private String
public String
getVariant()

Returns the normalized variant id, or the empty string.

private boolean
haveExperimentalLanguagePrefix()

Returns true if the start of the buffer has an experimental or private language prefix, the pattern '[ixIX][-_].' shows the syntax checked.

private boolean
haveKeywordAssign()

Returns true if a value separator occurs at or after index.

private static boolean
private static boolean
private boolean
isTerminator(char c)

Returns true if the character is a terminator (keyword separator, dot, or DONE).

private boolean
isTerminatorOrIDSeparator(char c)

Returns true if the character is a terminator or id separator.

private char
next()

Returns the character at index in the id, and advance index.

public void
private int
parseCountry()

Advance index past country, and accumulate normalized country in buffer.

private int
parseKeywords()

Parse the keywords and return start of the string in the buffer.

private int
parseLanguage()

Advance index past language, and accumulate normalized language code in buffer.

private int
parseScript()

Advance index past script, and accumulate normalized script in buffer.

private int
parseVariant()

Advance index past variant, and accumulate normalized variant in buffer.

private void
private void
set(int pos, String s)

Set the length of the buffer to pos, then append the string.

public void
setBaseName(String baseName)

public void
setKeywordValue(String keywordName, String value)

Set the value for the named keyword, or unset it if value is null.

private void
setKeywordValue(String keywordName, String value, boolean reset)

Set the value for the named keyword, or unset it if value is null.

private boolean
setToKeywordStart()

If we have keywords, advance index to the start of the keywords and return true, otherwise return false.

private void
skipCountry()

Advance index past country.

private void
skipLanguage()

Advance index past language.

private void
skipScript()

Advance index past script.

private void
skipUntilTerminatorOrIDSeparator()

Advance index until the next terminator or id separator, and leave it there.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baseNameback to summary
pack-priv String baseName
bufferback to summary
private StringBuilder buffer

Temporary buffer for parsed sections of data.

canonicalizeback to summary
private boolean canonicalize
COMMAback to summary
private static final char COMMA
DONEback to summary
private static final char DONE

Character to indicate no more text is available in the id.

DOTback to summary
private static final char DOT
hadCountryback to summary
private boolean hadCountry
HYPHENback to summary
private static final char HYPHEN
idback to summary
private char[] id

Char array representing the locale ID.

indexback to summary
private int index

Current position in id (while parsing).

ITEM_SEPARATORback to summary
private static final char ITEM_SEPARATOR
KEYWORD_ASSIGNback to summary
private static final char KEYWORD_ASSIGN
KEYWORD_SEPARATORback to summary
private static final char KEYWORD_SEPARATOR

Parsing constants.

keywordsback to summary
pack-priv Map<String, String> keywords
UNDERSCOREback to summary
private static final char UNDERSCORE

Constructor Detail

LocaleIDParserback to summary
public LocaleIDParser(String localeID)
LocaleIDParserback to summary
public LocaleIDParser(String localeID, boolean canonicalize)

Method Detail

addSeparatorback to summary
private void addSeparator()
appendback to summary
private void append(char c)

Append c to the buffer.

appendback to summary
private void append(String s)

Append the string to the buffer.

atTerminatorback to summary
private boolean atTerminator()

Returns true if the character at index in the id is a terminator.

defaultKeywordValueback to summary
public void defaultKeywordValue(String keywordName, String value)

Set the keyword value only if it is not already set to something else.

getBaseNameback to summary
public String getBaseName()

Returns the normalized base form of the locale id. The base form does not include keywords.

getCountryback to summary
public String getCountry()

return the normalized country id, or the empty string.

getKeyComparatorback to summary
private Comparator<String> getKeyComparator()
getKeywordback to summary
private String getKeyword()
getKeywordMapback to summary
public Map<String, String> getKeywordMap()

Returns a map of the keywords and values, or null if there are none.

getKeywordsback to summary
public Iterator<String> getKeywords()

Returns an iterator over the keywords, or null if we have an empty map.

getKeywordValueback to summary
public String getKeywordValue(String keywordName)

Returns the value for the named keyword, or null if the keyword is not present.

getLanguageback to summary
public String getLanguage()

Returns the normalized language id, or the empty string.

getLanguageScriptCountryVariantback to summary
public String[] getLanguageScriptCountryVariant()

Returns the language, script, country, and variant as separate strings.

getNameback to summary
public String getName()

Returns the normalized full form of the locale id. The full form includes keywords if they are present.

getScriptback to summary
public String getScript()

Returns the normalized script id, or the empty string.

getStringback to summary
private String getString(int start)

Returns the text in the buffer from start to blen as a String.

getValueback to summary
private String getValue()
getVariantback to summary
public String getVariant()

Returns the normalized variant id, or the empty string.

haveExperimentalLanguagePrefixback to summary
private boolean haveExperimentalLanguagePrefix()

Returns true if the start of the buffer has an experimental or private language prefix, the pattern '[ixIX][-_].' shows the syntax checked.

haveKeywordAssignback to summary
private boolean haveKeywordAssign()

Returns true if a value separator occurs at or after index.

isDoneOrItemSeparatorback to summary
private static boolean isDoneOrItemSeparator(char c)
isDoneOrKeywordAssignback to summary
private static boolean isDoneOrKeywordAssign(char c)
isTerminatorback to summary
private boolean isTerminator(char c)

Returns true if the character is a terminator (keyword separator, dot, or DONE). Dot is a terminator because of the POSIX form, where dot precedes the codepage.

isTerminatorOrIDSeparatorback to summary
private boolean isTerminatorOrIDSeparator(char c)

Returns true if the character is a terminator or id separator.

nextback to summary
private char next()

Returns the character at index in the id, and advance index. The returned character is DONE if index was at the limit of the buffer. The index is advanced regardless so that decrementing the index will always 'unget' the last character returned.

parseBaseNameback to summary
public void parseBaseName()
parseCountryback to summary
private int parseCountry()

Advance index past country, and accumulate normalized country in buffer. Index must be immediately after the script (if there is one, else language) and IDSeparator. Return the start of the country code in the buffer.

parseKeywordsback to summary
private int parseKeywords()

Parse the keywords and return start of the string in the buffer.

parseLanguageback to summary
private int parseLanguage()

Advance index past language, and accumulate normalized language code in buffer. Index must be at 0 when this is called. Index is left at a terminator or id separator. Returns the start of the language code in the buffer.

parseScriptback to summary
private int parseScript()

Advance index past script, and accumulate normalized script in buffer. Index must be immediately after the language. If the item at this position is not a script (is not four characters long) leave index and buffer unchanged. Otherwise index is left at a terminator or id separator. Returns the start of the script code in the buffer (this may be equal to the buffer length, if there is no script).

parseVariantback to summary
private int parseVariant()

Advance index past variant, and accumulate normalized variant in buffer. This ignores the codepage information from POSIX ids. Index must be immediately after the country or script. Index is left at the keyword separator or at the end of the text. Return the start of the variant code in the buffer. In standard form, we can have the following forms: ll__VVVV ll_CC_VVVV ll_Ssss_VVVV ll_Ssss_CC_VVVV This also handles POSIX ids, which can have the following forms (pppp is code page id): ll_CC.pppp --> ll_CC ll_CC.pppp@VVVV --> ll_CC_VVVV ll_CC@VVVV --> ll_CC_VVVV We identify this use of '@' in POSIX ids by looking for an '=' following the '@'. If there is one, we consider '@' to start a keyword list, instead of being part of a POSIX id.

Note

since it was decided that we want an option to not handle POSIX ids, this becomes a bit more complex.

resetback to summary
private void reset()
setback to summary
private void set(int pos, String s)

Set the length of the buffer to pos, then append the string.

setBaseNameback to summary
public void setBaseName(String baseName)
setKeywordValueback to summary
public void setKeywordValue(String keywordName, String value)

Set the value for the named keyword, or unset it if value is null. If keywordName itself is null, unset all keywords. If keywordName is not null, value must not be null.

setKeywordValueback to summary
private void setKeywordValue(String keywordName, String value, boolean reset)

Set the value for the named keyword, or unset it if value is null. If keywordName itself is null, unset all keywords. If keywordName is not null, value must not be null. If reset is true, ignore any previous value for the keyword, otherwise do not change the keyword (including removal of one or all keywords).

setToKeywordStartback to summary
private boolean setToKeywordStart()

If we have keywords, advance index to the start of the keywords and return true, otherwise return false.

skipCountryback to summary
private void skipCountry()

Advance index past country. Index must be immediately after the script (if there is one, else language) and IDSeparator.

skipLanguageback to summary
private void skipLanguage()

Advance index past language. Index must be at 0 when this is called. Index is left at a terminator or id separator.

skipScriptback to summary
private void skipScript()

Advance index past script. Index must be immediately after the language and IDSeparator. If the item at this position is not a script (is not four characters long) leave index. Otherwise index is left at a terminator or id separator.

skipUntilTerminatorOrIDSeparatorback to summary
private void skipUntilTerminatorOrIDSeparator()

Advance index until the next terminator or id separator, and leave it there.