Class DateTimePatternGenerator.FormatParser

java.lang.Object
com.ibm.icu.text.DateTimePatternGenerator.FormatParser
Enclosing class:
DateTimePatternGenerator

@Deprecated public static class DateTimePatternGenerator.FormatParser extends Object
Deprecated.
This API is ICU internal only.
This class provides mechanisms for parsing a SimpleDateFormat pattern or generating a new pattern, while handling the quoting. It represents the result of the parse as a list of items, where each item is either a literal string or a variable field. When parsing It can be used to find out which variable fields are in a date format, and in what order, such as for presentation in a UI as separate text entry fields. It can also be used to construct new SimpleDateFormats.

Example:

    public boolean containsZone(String pattern) {
        for (Iterator it = formatParser.set(pattern).getItems().iterator(); it.hasNext();) {
            Object item = it.next();
            if (item instanceof VariableField) {
                VariableField variableField = (VariableField) item;
                if (variableField.getType() == DateTimePatternGenerator.ZONE) {
                    return true;
                }
            }
        }
        return false;
    }
  
  • Constructor Details

    • FormatParser

      @Deprecated public FormatParser()
      Deprecated.
      This API is ICU internal only.
      Construct an empty date format parser, to which strings and variables can be added with set(...).
  • Method Details

    • set

      Deprecated.
      This API is ICU internal only.
      Parses the string into a list of items.
      Parameters:
      string - The string to parse.
      Returns:
      this, for chaining
    • set

      @Deprecated public DateTimePatternGenerator.FormatParser set(String string, boolean strict)
      Deprecated.
      This API is ICU internal only.
      Parses the string into a list of items, taking into account all of the quoting that may be going on.
      Parameters:
      string - The string to parse.
      strict - If true, then only allows exactly those lengths specified by CLDR for variables. For example, "hh:mm aa" would throw an exception.
      Returns:
      this, for chaining
    • getItems

      @Deprecated public List<Object> getItems()
      Deprecated.
      This API is ICU internal only.
      Returns modifiable list which is a mixture of Strings and VariableFields, in the order found during parsing. The strings represent literals, and have all quoting removed. Thus the string "dd 'de' MM" will parse into three items:
       VariableField: dd
       String: " de "
       VariableField: MM
       
      The list is modifiable, so you can add any strings or variables to it, or remove any items.
      Returns:
      modifiable list of items.
    • toString

      @Deprecated public String toString()
      Deprecated.
      This API is ICU internal only.
      Provide display form of formatted input. Each literal string is quoted if necessary.. That is, if the input was "hh':'mm", the result would be "hh:mm", since the ":" doesn't need quoting. See quoteLiteral().
      Overrides:
      toString in class Object
      Returns:
      printable output string
    • toString

      @Deprecated public String toString(int start, int limit)
      Deprecated.
      This API is ICU internal only.
      Provide display form of a segment of the parsed input. Each literal string is minimally quoted. That is, if the input was "hh':'mm", the result would be "hh:mm", since the ":" doesn't need quoting. See quoteLiteral().
      Parameters:
      start - item to start from
      limit - last item +1
      Returns:
      printable output string
    • hasDateAndTimeFields

      @Deprecated public boolean hasDateAndTimeFields()
      Deprecated.
      This API is ICU internal only.
      Returns true if it has a mixture of date and time variable fields: that is, at least one date variable and at least one time variable.
      Returns:
      true or false
    • quoteLiteral

      @Deprecated public Object quoteLiteral(String string)
      Deprecated.
      This API is ICU internal only.
      Each literal string is quoted as needed. That is, the ' quote marks will only be added if needed. The exact pattern of quoting is not guaranteed, thus " de la " could be quoted as " 'de la' " or as " 'de' 'la' ".
      Parameters:
      string - The string to check.
      Returns:
      string with quoted literals