Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8317282

j.text.ChoiceFormat provides no specification on quoting behavior

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 22
    • core-libs
    • None
    • behavioral
    • minimal
    • A specification only update to ChoiceFormat to make long-standing behavior apparent.
    • Java API
    • SE

      Summary

      Make single quoting behavior within a java.text.ChoiceFormat String pattern apparent.

      Problem

      The other Format classes that take a String pattern such as DecimalFormat, CompactNumberFormat, and MessageFormat all provide specification on single quote behavior within a String pattern. ChoiceFormat does not have similar specification. This limits end users from not knowing how to use a Relation symbol and literal single quotes within a Format pattern.

      Solution

      Provide a small update at the bottom of the pattern section which describes the behavior that single quotes escape the meaning of a Relation symbol, and also how to use a literal single quote within a pattern.

      Specification

      Update the Patterns section with

      --- a/src/java.base/share/classes/java/text/ChoiceFormat.java
      +++ b/src/java.base/share/classes/java/text/ChoiceFormat.java
      @@ -187,6 +187,12 @@
        *
        * <i>Note:The relation &le; is not equivalent to &lt;&equals;</i>
        *
      + * <p>If a <i>Relation</i> symbol is to be used within a <i>Format</i> pattern,
      + * it must be single quoted. For example,
      + * {@code new ChoiceFormat("1# '#'1 ").format(1)} returns {@code " #1 "}.
      + * Use two single quotes in a row to produce a literal single quote. For example,
      + * {@code new ChoiceFormat("1# ''one'' ").format(1)} returns {@code " 'one' "}.
      + *

            jlu Justin Lu
            jlu Justin Lu
            Naoto Sato
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: