Class Newlines


  • public class Newlines
    extends java.lang.Object
    Platform-independent newline handling.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static com.google.common.collect.ImmutableSet<java.lang.String> BREAKS  
    • Constructor Summary

      Constructors 
      Constructor Description
      Newlines()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean containsBreaks​(java.lang.String text)
      Returns true if the input contains any line breaks.
      static int count​(java.lang.String input)
      Returns the number of line breaks in the input.
      static int firstBreak​(java.lang.String input)
      Returns the index of the first break in the input, or -1.
      static java.lang.String getLineEnding​(java.lang.String input)
      Returns the terminating line break in the input, or null if the input does not end in a break.
      static java.lang.String guessLineSeparator​(java.lang.String text)
      Returns the first line separator in the text, or "\n" if the text does not contain a single line separator.
      static int hasNewlineAt​(java.lang.String input, int idx)
      Returns the length of the newline sequence at the current offset, or -1.
      static boolean isNewline​(java.lang.String input)
      Returns true if the entire input string is a recognized line break.
      static java.util.Iterator<java.lang.String> lineIterator​(java.lang.String input)
      Returns an iterator over lines in the input, including trailing whitespace.
      static java.util.Iterator<java.lang.Integer> lineOffsetIterator​(java.lang.String input)
      Returns an iterator over the start offsets of lines in the input.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • BREAKS

        private static final com.google.common.collect.ImmutableSet<java.lang.String> BREAKS
    • Constructor Detail

      • Newlines

        public Newlines()
    • Method Detail

      • count

        public static int count​(java.lang.String input)
        Returns the number of line breaks in the input.
      • firstBreak

        public static int firstBreak​(java.lang.String input)
        Returns the index of the first break in the input, or -1.
      • isNewline

        public static boolean isNewline​(java.lang.String input)
        Returns true if the entire input string is a recognized line break.
      • hasNewlineAt

        public static int hasNewlineAt​(java.lang.String input,
                                       int idx)
        Returns the length of the newline sequence at the current offset, or -1.
      • getLineEnding

        public static java.lang.String getLineEnding​(java.lang.String input)
        Returns the terminating line break in the input, or null if the input does not end in a break.
      • guessLineSeparator

        public static java.lang.String guessLineSeparator​(java.lang.String text)
        Returns the first line separator in the text, or "\n" if the text does not contain a single line separator.
      • containsBreaks

        public static boolean containsBreaks​(java.lang.String text)
        Returns true if the input contains any line breaks.
      • lineOffsetIterator

        public static java.util.Iterator<java.lang.Integer> lineOffsetIterator​(java.lang.String input)
        Returns an iterator over the start offsets of lines in the input.
      • lineIterator

        public static java.util.Iterator<java.lang.String> lineIterator​(java.lang.String input)
        Returns an iterator over lines in the input, including trailing whitespace.