private static int newLineIndex(String text) {
    int index1 = text.indexOf('\n');
    if (index1 < 0) index1 = text.length();
    int index2 = text.indexOf('\r');
    if (index2 < 0) index2 = text.length();
    return Math.min(index1, index2);
  }
private static int newLineIndex(String text)