Class TextFormatter

  • All Implemented Interfaces:
    java.lang.Appendable

    public class TextFormatter
    extends InternalFormat.Formatter
    A class that provides the implementation of str and unicode formatting. In a limited way, it acts like a StringBuilder to which text, formatted according to the format specifier supplied at construction. These are ephemeral objects that are not, on their own, thread safe.
    • Constructor Detail

      • TextFormatter

        public TextFormatter​(java.lang.StringBuilder result,
                             InternalFormat.Spec spec)
        Construct the formatter from a client-supplied buffer, to which the result will be appended, and a specification. Sets InternalFormat.Formatter.mark to the end of the buffer.
        Parameters:
        result - destination buffer
        spec - parsed conversion specification
      • TextFormatter

        public TextFormatter​(InternalFormat.Spec spec)
        Construct the formatter from a specification, allocating a buffer internally for the result.
        Parameters:
        spec - parsed conversion specification
    • Method Detail

      • append

        public TextFormatter append​(java.lang.CharSequence csq,
                                    int start,
                                    int end)
                             throws java.lang.IndexOutOfBoundsException
        Specified by:
        append in interface java.lang.Appendable
        Overrides:
        append in class InternalFormat.Formatter
        Throws:
        java.lang.IndexOutOfBoundsException
      • format

        public TextFormatter format​(java.lang.String value)
        Format the given String into the result buffer. Largely, this is a matter of copying the value of the argument, but a subtlety arises when the string contains supplementary (non-BMP) Unicode characters, which are represented as surrogate pairs. The precision specified in the format relates to a count of Unicode characters (code points), not Java chars. The method deals with this correctly, essentially by not counting the high-surrogates in the allowance. The final value of InternalFormat.Formatter.lenWhole counts the UTF-16 units added.
        Parameters:
        value - to format
        Returns:
        this TextFormatter object