public static TextMap fromString(String text){
  final int textLength=text.length();
  final ArrayList<Integer> lines=new ArrayList<>();
  lines.add(0);
  int offset=0;
  while (offset < text.length()) {
    final int nlIndex=text.indexOf('\n',offset);
    if (nlIndex >= 0) {
      offset=nlIndex + 1;
      lines.add(offset);
    }
 else {
      break;
    }
  }
  lines.add(Integer.MAX_VALUE);
  final int[] nlOffsets=new int[lines.size()];
  for (int line=0; line < lines.size(); line++) {
    nlOffsets[line]=lines.get(line);
  }
  final boolean finalNL=textLength > 0 && (textLength == nlOffsets[nlOffsets.length - 2]);
  return new TextMap(nlOffsets,textLength,finalNL);
}

public static TextMap fromString ( String text ) { final int textLength = text . length ( ) ; final ArrayList < Integer > lines = new ArrayList < > ( ) ; lines . add ( 0 ) ; int offset = 0 ; while ( offset < text . length ( ) ) { final int nlIndex = text . indexOf ( '\n' , offset ) ; if ( nlIndex >= 0 ) { offset = nlIndex + 1 ; lines . add ( offset ) ; } else { break ; } } lines . add ( Integer . MAX_VALUE ) ; final int [ ] nlOffsets = new int [ lines . size ( ) ] ; for ( int line = 0 ; line < lines . size ( ) ; line ++ ) { nlOffsets [ line ] = lines . get ( line ) ; } final boolean finalNL = textLength > 0 && ( textLength == nlOffsets [ nlOffsets . length - 2 ] ) ; return new TextMap ( nlOffsets , textLength , finalNL ) ; }
constructs map permitting translation between 0 - based character offsets and 1 - based lines / columns .
