Package org.pkl.core

Class ValueFormatter


  • public final class ValueFormatter
    extends java.lang.Object
    • Constructor Detail

      • ValueFormatter

        public ValueFormatter​(boolean useMultilineStrings,
                              boolean useCustomStringDelimiters)
        Constructs an instance of a ValueFormatter.

        If useMultilineStrings is true, string values containing newline characters are formatted as multiline string literals.

        If useCustomStringDelimiters is true, custom string delimiters (such as #"..."#) are preferred over escaping quotes and backslashes.

    • Method Detail

      • basic

        public static ValueFormatter basic()
        Equivalent to new ValueFormatter(false, false).
      • withCustomStringDelimiters

        public static ValueFormatter withCustomStringDelimiters()
        Equivalent to new ValueFormatter(false, true).
      • formatStringValue

        public java.lang.String formatStringValue​(java.lang.String value,
                                                  java.lang.CharSequence lineIndent)
        Formats value as a Pkl/Pcf string literal (including quotes).

        If value contains a \n character, a multiline string literal is returned, and subsequent lines are indented by lineIndent. Otherwise, a single line string literal is returned.

      • formatStringValue

        public void formatStringValue​(java.lang.String value,
                                      java.lang.CharSequence lineIndent,
                                      java.lang.StringBuilder builder)
        Same as formatStringValue(String, CharSequence), except that output goes to builder.
      • formatStringValue

        public void formatStringValue​(java.lang.String value,
                                      java.lang.CharSequence lineIndent,
                                      java.lang.Appendable appendable)
                               throws java.io.IOException
        Same as formatStringValue(String, CharSequence), except that output goes to appendable (which may cause IOException).
        Throws:
        java.io.IOException