Class LocaleIDParser

java.lang.Object
com.ibm.icu.impl.LocaleIDParser

public final class LocaleIDParser extends Object
Utility class to parse and normalize locale ids (including POSIX style)
  • Field Details

    • id

      private char[] id
      Char array representing the locale ID.
    • index

      private int index
      Current position in id (while parsing).
    • buffer

      private StringBuilder buffer
      Temporary buffer for parsed sections of data.
    • canonicalize

      private boolean canonicalize
    • hadCountry

      private boolean hadCountry
    • keywords

      Map<String,String> keywords
    • baseName

      String baseName
    • KEYWORD_SEPARATOR

      private static final char KEYWORD_SEPARATOR
      Parsing 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 DONE
      Character 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

      public LocaleIDParser(String localeID)
    • LocaleIDParser

      public LocaleIDParser(String localeID, boolean canonicalize)
  • Method Details

    • reset

      private void reset()
    • append

      private void append(char c)
      Append c to the buffer.
    • addSeparator

      private void addSeparator()
    • getString

      private String getString(int start)
      Returns the text in the buffer from start to blen as a String.
    • set

      private void set(int pos, String s)
      Set the length of the buffer to pos, then append the string.
    • append

      private void append(String s)
      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

      public String getLanguage()
      Returns the normalized language id, or the empty string.
    • getScript

      public String getScript()
      Returns the normalized script id, or the empty string.
    • getCountry

      public String getCountry()
      return the normalized country id, or the empty string.
    • getVariant

      public String getVariant()
      Returns the normalized variant id, or the empty string.
    • getLanguageScriptCountryVariant

      public String[] getLanguageScriptCountryVariant()
      Returns the language, script, country, and variant as separate strings.
    • setBaseName

      public void setBaseName(String baseName)
    • parseBaseName

      public void parseBaseName()
    • getBaseName

      public String getBaseName()
      Returns the normalized base form of the locale id. The base form does not include keywords.
    • getName

      public String 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

      private String getKeyword()
    • getValue

      private String getValue()
    • getKeyComparator

      private Comparator<String> getKeyComparator()
    • getKeywordMap

      public Map<String,String> 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

      public Iterator<String> getKeywords()
      Returns an iterator over the keywords, or null if we have an empty map.
    • getKeywordValue

      public String getKeywordValue(String keywordName)
      Returns the value for the named keyword, or null if the keyword is not present.
    • defaultKeywordValue

      public void defaultKeywordValue(String keywordName, String value)
      Set the keyword value only if it is not already set to something else.
    • setKeywordValue

      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.
    • setKeywordValue

      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).