public static int findSplitpoint(String s,int width){
  int in=s.indexOf(NEWLINE);
  if (in < 0) {
    in=s.length();
  }
  if (in < width) {
    return in;
  }
  int iw=s.lastIndexOf(' ',width);
  if (iw >= 0 && iw < width) {
    return iw;
  }
  int bp=nextPosition(s.indexOf(' ',width),s.indexOf(NEWLINE,width));
  if (bp >= 0) {
    return bp;
  }
  return s.length();
}

public static int findSplitpoint ( String s , int width ) { int in = s . indexOf ( NEWLINE ) ; if ( in < 0 ) { in = s . length ( ) ; } if ( in < width ) { return in ; } int iw = s . lastIndexOf ( ' ' , width ) ; if ( iw >= 0 && iw < width ) { return iw ; } int bp = nextPosition ( s . indexOf ( ' ' , width ) , s . indexOf ( NEWLINE , width ) ) ; if ( bp >= 0 ) { return bp ; } return s . length ( ) ; }
find the first space before position w or if there is none after w .
