Class PatternStringUtils


  • public class PatternStringUtils
    extends java.lang.Object
    Assorted utilities relating to decimal formatting pattern strings.
    • Constructor Detail

      • PatternStringUtils

        public PatternStringUtils()
    • Method Detail

      • ignoreRoundingIncrement

        public static boolean ignoreRoundingIncrement​(java.math.BigDecimal roundIncrDec,
                                                      int maxFrac)
        Determine whether a given roundingIncrement should be ignored for formatting based on the current maxFrac value (maximum fraction digits). For example a roundingIncrement of 0.01 should be ignored if maxFrac is 1, but not if maxFrac is 2 or more. Note that roundingIncrements are rounded up in significance, so a roundingIncrement of 0.006 is treated like 0.01 for this determination, i.e. it should not be ignored if maxFrac is 2 or more (but a roundingIncrement of 0.005 is treated like 0.001 for significance). This test is needed for both NumberPropertyMapper.oldToNew and PatternStringUtils.propertiesToPatternString, but NumberPropertyMapper is package-private so we have it here.
        Parameters:
        roundIncrDec - The roundingIncrement to be checked. Must be non-null.
        maxFrac - The current maximum fraction digits value.
        Returns:
        true if roundIncr should be ignored for formatting.
      • propertiesToPatternString

        public static java.lang.String propertiesToPatternString​(DecimalFormatProperties properties)
        Creates a pattern string from a property bag.

        Since pattern strings support only a subset of the functionality available in a property bag, a new property bag created from the string returned by this function may not be the same as the original property bag.

        Parameters:
        properties - The property bag to serialize.
        Returns:
        A pattern string approximately serializing the property bag.
      • escapePaddingString

        private static int escapePaddingString​(java.lang.CharSequence input,
                                               java.lang.StringBuilder output,
                                               int startIndex)
        Returns:
        The number of chars inserted.
      • convertLocalized

        public static java.lang.String convertLocalized​(java.lang.String input,
                                                        DecimalFormatSymbols symbols,
                                                        boolean toLocalized)
        Converts a pattern between standard notation and localized notation. Localized notation means that instead of using generic placeholders in the pattern, you use the corresponding locale-specific characters instead. For example, in locale fr-FR, the period in the pattern "0.000" means "decimal" in standard notation (as it does in every other locale), but it means "grouping" in localized notation.

        A greedy string-substitution strategy is used to substitute locale symbols. If two symbols are ambiguous or have the same prefix, the result is not well-defined.

        Locale symbols are not allowed to contain the ASCII quote character.

        This method is provided for backwards compatibility and should not be used in any new code.

        Parameters:
        input - The pattern to convert.
        symbols - The symbols corresponding to the localized pattern.
        toLocalized - true to convert from standard to localized notation; false to convert from localized to standard notation.
        Returns:
        The pattern expressed in the other notation.
      • patternInfoToStringBuilder

        public static void patternInfoToStringBuilder​(AffixPatternProvider patternInfo,
                                                      boolean isPrefix,
                                                      PatternStringUtils.PatternSignType patternSignType,
                                                      boolean approximately,
                                                      StandardPlural plural,
                                                      boolean perMilleReplacesPercent,
                                                      java.lang.StringBuilder output)
        This method contains the heart of the logic for rendering LDML affix strings. It handles sign-always-shown resolution, whether to use the positive or negative subpattern, permille substitution, and plural forms for CurrencyPluralInfo.