Newlines { public static Iterator<String> lineIterator(String input) { return new LineIterator(input); }  static int count(String input); static int firstBreak(String input); static boolean isNewline(String input); static int hasNewlineAt(String input, int idx); static String getLineEnding(String input); static String guessLineSeparator(String text); static boolean containsBreaks(String text); static Iterator<Integer> lineOffsetIterator(String input); static Iterator<String> lineIterator(String input);  }
@Test public void lines() { assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\nbar\n"))) .containsExactly("foo\n", "bar\n"); assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\nbar"))) .containsExactly("foo\n", "bar"); assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\rbar\r"))) .containsExactly("foo\r", "bar\r"); assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\rbar"))) .containsExactly("foo\r", "bar"); assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\r\nbar\r\n"))) .containsExactly("foo\r\n", "bar\r\n"); assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\r\nbar"))) .containsExactly("foo\r\n", "bar"); }
@Test public void terminalLine() { Iterator<String> it = Newlines.lineIterator("foo\nbar\n"); it.next(); it.next(); try { it.next(); fail(); } catch (NoSuchElementException e) { } it = Newlines.lineIterator("foo\nbar"); it.next(); it.next(); try { it.next(); fail(); } catch (NoSuchElementException e) { } }