Class DocumentStyle

java.lang.Object
com.ultikits.ultitools.config.document.DocumentStyle

@Internal public final class DocumentStyle extends Object
The layout facts of one config file that SnakeYAML's emitter needs to write the file the way it already looks. Each fact is read from the file once, when it is parsed; a mixed file gets one style per fact.
  • Line terminator - the file's first line break (\r\n, \r or \n); \n for a file without one.
  • Mapping indentation - the column offset of the first nested block mapping's keys from their parent key; 2 when there is none (Bukkit's default).
  • List indicator indentation - the column offset of the first block sequence's - from the key that holds it: 0 for 6.2-written files (- x under the key), the offset for bundled files that indent items ( - x).
  • Unicode escaping - a file whose scalars hold no raw non-ASCII character and at least one \u, \U or \x escape keeps writing non-ASCII text as escapes. Escapes follow the file's own form: the hex digits in the case the file uses, and a character up to U+00FF as a four-digit \u escape unless the file itself uses \x (SnakeYAML's emitter would write \x).
  • Line width - 80 (Bukkit's default, the width 6.2 folded long strings at) when the file holds a quoted or plain scalar spanning more than one line; unlimited otherwise, so a long line written by hand stays one line.
  • Byte order mark and final line break - kept as found.
Since:
6.3.0
  • Field Details

    • BUKKIT_WIDTH

      static final int BUKKIT_WIDTH
      Bukkit's YamlConfigurationOptions default width, which 6.2 wrote with.
      See Also:
    • DEFAULT_INDENT

      private static final int DEFAULT_INDENT
      See Also:
    • MAX_INDENT

      private static final int MAX_INDENT
      See Also:
    • lineBreak

      private final String lineBreak
    • indent

      private final int indent
    • indicatorIndent

      private final int indicatorIndent
    • escapeUnicode

      private final boolean escapeUnicode
    • upperCaseHex

      private final boolean upperCaseHex
    • latin1AsUnicodeEscape

      private final boolean latin1AsUnicodeEscape
    • width

      private final int width
    • byteOrderMark

      private final boolean byteOrderMark
    • finalLineBreak

      private final boolean finalLineBreak
  • Constructor Details

    • DocumentStyle

      private DocumentStyle(String lineBreak, int indent, int indicatorIndent, boolean escapeUnicode, boolean upperCaseHex, boolean latin1AsUnicodeEscape, int width, boolean byteOrderMark, boolean finalLineBreak)
  • Method Details

    • defaults

      public static DocumentStyle defaults()
      The style of a new file: what Bukkit writes, without a line width limit.
      Returns:
      the default style
    • detect

      static DocumentStyle detect(String text, org.yaml.snakeyaml.nodes.MappingNode root)
      Reads the style of a parsed file.
      Parameters:
      text - the file's text as read
      root - the composed top-level mapping, or null for a file without content
      Returns:
      the file's style
    • lineBreak

      String lineBreak()
    • upperCaseHex

      boolean upperCaseHex()
    • latin1AsUnicodeEscape

      boolean latin1AsUnicodeEscape()
    • byteOrderMark

      boolean byteOrderMark()
    • finalLineBreak

      boolean finalLineBreak()
    • dumperOptions

      org.yaml.snakeyaml.DumperOptions dumperOptions()
      The emitter options for this style, with Bukkit's flow style and comment processing.
      Returns:
      fresh dumper options
    • detectLineBreak

      private static String detectLineBreak(String text)