Enum LineSeparator

java.lang.Object
java.lang.Enum<LineSeparator>
com.github.javaparser.utils.LineSeparator
All Implemented Interfaces:
Serializable, Comparable<LineSeparator>, java.lang.constant.Constable

public enum LineSeparator extends Enum<LineSeparator>
A representation of line endings, that can be used throughout the codebase.
This is to replace Utils.EOL which is not explicit in representing the system's EOL character.
It also exposes helper methods for, e.g., detection of the line ending of a given string.
Author:
Roger Howell
See Also:
https://github.com/javaparser/javaparser/issues/2647
  • Enum Constant Details

    • CR

      public static final LineSeparator CR
      The CR \r line ending is the default line separator for classic MacOS
    • LF

      public static final LineSeparator LF
      The LF \n line ending is the default line separator for Unix and modern MacOS
    • CRLF

      public static final LineSeparator CRLF
      The CRLF \r\n line ending is the default line separator for Windows
    • SYSTEM

      public static final LineSeparator SYSTEM
      This line ending is set to whatever the host system's line separator is
    • ARBITRARY

      public static final LineSeparator ARBITRARY
      The ARBITRARY line ending can be used where we do not care about the line separator, only that we use the same one consistently
    • MIXED

      public static final LineSeparator MIXED
      The MIXED line ending is used where strings appear to have multiple different line separators e.g. "line 1\nline 2\rline 3\r\n" or "line 1\nline 2\rline 3\nline 4\n"
    • UNKNOWN

      public static final LineSeparator UNKNOWN
      The UNKNOWN line ending can be used in the case where the given string has not yet been analysed to determine its line separator
    • NONE

      public static final LineSeparator NONE
      The NONE line ending is used where there are precisely zero line endings e.g. a simple one-line string
  • Method Details

    • values

      public static LineSeparator[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static LineSeparator valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • detect

      public static LineSeparator detect(String string)
    • getLineEnding

      public static LineSeparator getLineEnding(int countCr, int countLf, int countCrLf)
    • lookup

      public static Optional<LineSeparator> lookup(String ending)
      Parameters:
      ending - A string containing ONLY the line separator needle (e.g. \r, \n, or \r\n)
      Returns:
      Where the given ending is a "standard" line separator (i.e. \r, \n, or \r\n), return that. Otherwise an empty optional.
    • lookupEscaped

      public static Optional<LineSeparator> lookupEscaped(String ending)
    • describe

      public String describe()
    • equalsString

      public boolean equalsString(LineSeparator lineSeparator)
    • isStandardEol

      public boolean isStandardEol()
    • asEscapedString

      public String asEscapedString()
    • asRawString

      public String asRawString()
    • toString

      public String toString()
      Overrides:
      toString in class Enum<LineSeparator>