Newlines { public static Iterator<Integer> lineOffsetIterator(String input) { return new LineOffsetIterator(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 offsets() { assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\nbar\n"))) .containsExactly(0, 4, 8); assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\nbar"))).containsExactly(0, 4); assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\rbar\r"))) .containsExactly(0, 4, 8); assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\rbar"))).containsExactly(0, 4); assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\r\nbar\r\n"))) .containsExactly(0, 5, 10); assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\r\nbar"))) .containsExactly(0, 5); }
@Test public void terminalOffset() { Iterator<Integer> it = Newlines.lineOffsetIterator("foo\nbar\n"); it.next(); it.next(); it.next(); try { it.next(); fail(); } catch (NoSuchElementException e) { } it = Newlines.lineOffsetIterator("foo\nbar"); it.next(); it.next(); try { it.next(); fail(); } catch (NoSuchElementException e) { } }