Package com.ibm.icu.impl
Class LocaleIDParser
java.lang.Object
com.ibm.icu.impl.LocaleIDParser
Utility class to parse and normalize locale ids (including POSIX style)
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) Stringprivate StringBuilderTemporary buffer for parsed sections of data.private booleanprivate static final charprivate static final charCharacter to indicate no more text is available in the id.private static final charprivate booleanprivate static final charprivate char[]Char array representing the locale ID.private intCurrent position inid(while parsing).private static final charprivate static final charprivate static final charParsing constants.private static final intprivate static final char -
Constructor Summary
ConstructorsConstructorDescriptionLocaleIDParser(String localeID) LocaleIDParser(String localeID, boolean canonicalize) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprivate voidappend(char c) Append c to the buffer.private voidAppend the string to the buffer.private booleanReturns true if the character at index in the id is a terminator.voiddefaultKeywordValue(String keywordName, String value) Set the keyword value only if it is not already set to something else.Returns the normalized base form of the locale id.return the normalized country id, or the empty string.private Comparator<String> private StringReturns a map of the keywords and values, or null if there are none.Returns an iterator over the keywords, or null if we have an empty map.getKeywordValue(String keywordName) Returns the value for the named keyword, or null if the keyword is not present.Returns the normalized language id, or the empty string.String[]Returns the language, script, country, and variant as separate strings.getName()Returns the normalized full form of the locale id.Returns the normalized script id, or the empty string.private StringgetString(int start) Returns the text in the buffer from start to blen as a String.private StringgetValue()Returns the normalized variant id, or the empty string.private booleanReturns true if the start of the buffer has an experimental or private language prefix, the pattern '[ixIX][-_].' shows the syntax checked.private booleanReturns true if a value separator occurs at or after index.private static booleanisDoneOrItemSeparator(char c) private static booleanisDoneOrKeywordAssign(char c) private booleanisTerminator(char c) Returns true if the character is a terminator (keyword separator, dot, or DONE).private booleanisTerminatorOrIDSeparator(char c) Returns true if the character is a terminator or id separator.private charnext()Returns the character at index in the id, and advance index.voidprivate intAdvance index past country, and accumulate normalized country in buffer.private intParse the keywords and return start of the string in the buffer.private intAdvance index past language, and accumulate normalized language code in buffer.private intAdvance index past script, and accumulate normalized script in buffer.private intAdvance index past variant, and accumulate normalized variant in buffer.private voidreset()private voidSet the length of the buffer to pos, then append the string.voidsetBaseName(String baseName) voidsetKeywordValue(String keywordName, String value) Set the value for the named keyword, or unset it if value is null.private voidsetKeywordValue(String keywordName, String value, boolean reset) Set the value for the named keyword, or unset it if value is null.private booleanIf we have keywords, advance index to the start of the keywords and return true, otherwise return false.private voidAdvance index past country.private voidAdvance index past language.private voidAdvance index past script.private voidAdvance index until the next terminator or id separator, and leave it there.
-
Field Details
-
id
private char[] idChar array representing the locale ID. -
index
private int indexCurrent position inid(while parsing). -
buffer
Temporary buffer for parsed sections of data. -
canonicalize
private boolean canonicalize -
hadCountry
private boolean hadCountry -
keywords
-
baseName
String baseName -
KEYWORD_SEPARATOR
private static final char KEYWORD_SEPARATORParsing constants.- See Also:
-
HYPHEN
private static final char HYPHEN- See Also:
-
KEYWORD_ASSIGN
private static final char KEYWORD_ASSIGN- See Also:
-
COMMA
private static final char COMMA- See Also:
-
ITEM_SEPARATOR
private static final char ITEM_SEPARATOR- See Also:
-
DOT
private static final char DOT- See Also:
-
UNDERSCORE
private static final char UNDERSCORE- See Also:
-
DONE
private static final char DONECharacter to indicate no more text is available in the id.- See Also:
-
MAX_VARIANTS_LENGTH
private static final int MAX_VARIANTS_LENGTH- See Also:
-
-
Constructor Details
-
LocaleIDParser
-
LocaleIDParser
-
-
Method Details
-
reset
private void reset() -
append
private void append(char c) Append c to the buffer. -
addSeparator
private void addSeparator() -
getString
Returns the text in the buffer from start to blen as a String. -
set
Set the length of the buffer to pos, then append the string. -
append
Append the string to the buffer. -
next
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. -
skipUntilTerminatorOrIDSeparator
private void skipUntilTerminatorOrIDSeparator()Advance index until the next terminator or id separator, and leave it there. -
atTerminator
private boolean atTerminator()Returns true if the character at index in the id is a terminator. -
isTerminator
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. -
isTerminatorOrIDSeparator
private boolean isTerminatorOrIDSeparator(char c) Returns true if the character is a terminator or id separator. -
haveExperimentalLanguagePrefix
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. -
haveKeywordAssign
private boolean haveKeywordAssign()Returns true if a value separator occurs at or after index. -
parseLanguage
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. -
skipLanguage
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. -
parseScript
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). -
skipScript
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. -
parseCountry
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. -
skipCountry
private void skipCountry()Advance index past country. Index must be immediately after the script (if there is one, else language) and IDSeparator. -
parseVariant
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. -
getLanguage
Returns the normalized language id, or the empty string. -
getScript
Returns the normalized script id, or the empty string. -
getCountry
return the normalized country id, or the empty string. -
getVariant
Returns the normalized variant id, or the empty string. -
getLanguageScriptCountryVariant
Returns the language, script, country, and variant as separate strings. -
setBaseName
-
parseBaseName
public void parseBaseName() -
getBaseName
Returns the normalized base form of the locale id. The base form does not include keywords. -
getName
Returns the normalized full form of the locale id. The full form includes keywords if they are present. -
setToKeywordStart
private boolean setToKeywordStart()If we have keywords, advance index to the start of the keywords and return true, otherwise return false. -
isDoneOrKeywordAssign
private static boolean isDoneOrKeywordAssign(char c) -
isDoneOrItemSeparator
private static boolean isDoneOrItemSeparator(char c) -
getKeyword
-
getValue
-
getKeyComparator
-
getKeywordMap
Returns a map of the keywords and values, or null if there are none. -
parseKeywords
private int parseKeywords()Parse the keywords and return start of the string in the buffer. -
getKeywords
Returns an iterator over the keywords, or null if we have an empty map. -
getKeywordValue
Returns the value for the named keyword, or null if the keyword is not present. -
defaultKeywordValue
Set the keyword value only if it is not already set to something else. -
setKeywordValue
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. -
setKeywordValue
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).
-