Package org.tomlj

Class TomlParseOptions

java.lang.Object
org.tomlj.TomlParseOptions

public final class TomlParseOptions extends Object
Options controlling how a TOML document is parsed.
  • Field Details

  • Method Details

    • defaults

      public static TomlParseOptions defaults()
      The default parse options: TomlVersion.LATEST, with a maximum nesting depth of 128, keeping the text of the document parsed so that it can be written back as it was read.
      Returns:
      The default parse options.
    • withVersion

      public TomlParseOptions withVersion(TomlVersion version)
      Create a copy of these options that parses at a different specification version.
      Parameters:
      version - The version level to parse at.
      Returns:
      A new set of options with the given version.
    • withMaxNestingDepth

      public TomlParseOptions withMaxNestingDepth(int maxNestingDepth)
      Create a copy of these options that allows a different maximum nesting depth.

      The depth of a value, table or array is the number of tables and arrays that enclose it, not counting the root table. For example:

      • In a = [[1]] the integer 1 is nested 2 deep (the outer and inner arrays).
      • In a.b.c = 1 the integer 1 is nested 2 deep (tables a and b).
      • The table named by [a.b] is nested 1 deep.
      • Each table of [[a.b]] is nested 2 deep (table a and array b).
      A document containing a value, table or array nested deeper than this limit is reported as a parse error.

      The limit keeps bounded the stack depth needed to parse a document and to serialize the result with toJson() and TomlTable.toToml(). Raising it lets deeper documents parse, but such documents then need a correspondingly larger thread stack to parse and serialize; without one, they fail with a StackOverflowError.

      Parameters:
      maxNestingDepth - The maximum number of tables and arrays, not counting the root table, that may enclose any value, table or array in the document. Must not be negative; with 0, every table and array must be empty and directly in the root table.
      Returns:
      A new set of options with the given maximum nesting depth.
      Throws:
      IllegalArgumentException - If maxNestingDepth is negative.
    • withoutSource

      public TomlParseOptions withoutSource()
      Create a copy of these options that keeps no source text.

      By default a parse result keeps the text it was parsed from, and records where each line it accepted sits in that text, so that TomlTable.toToml() can write the document back as it was read. The text and the record take memory that an application which only reads a document never uses, and such an application can parse with these options instead. A document parsed with them records nothing about how it was written, so toToml() writes it in the default style, as it writes a document built with the editing API.

      Returns:
      A new set of options that keeps no source text.
    • version

      public TomlVersion version()
      The version level to parse at.
      Returns:
      The version level to parse at.
    • maxNestingDepth

      public int maxNestingDepth()
      The maximum nesting depth allowed in a parsed document.
      Returns:
      The maximum number of tables and arrays, not counting the root table, that may enclose any value, table or array in the document.
      See Also:
    • retainsSource

      public boolean retainsSource()
      Whether a parse result keeps the source text of the document it was read from.
      Returns:
      true unless these options came from withoutSource().
      See Also:
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object