protected int countLinesInString(final String stringToSearch,final boolean countBlankLines){
  assert (stringToSearch != null);
  int length=stringToSearch.length();
  int count=0;
  char character=0;
  boolean foundNonSpaceChar=false;
  for (int i=0; i < length; i++) {
    character=stringToSearch.charAt(i);
    if (character == '\r' && (i + 1) < length && stringToSearch.charAt(i + 1) == '\n') {
      i++;
    }
    if (character == '\n' || character == '\r') {
      if (countBlankLines) {
        count++;
      }
 else {
        if (foundNonSpaceChar) {
          count++;
        }
      }
      foundNonSpaceChar=false;
    }
 else     if (character != ' ' && character != '\t') {
      foundNonSpaceChar=true;
    }
  }
  if (character != '\n' && character != '\r') {
    count++;
  }
  return count;
}

protected int countLinesInString ( final String stringToSearch , final boolean countBlankLines ) { assert ( stringToSearch != null ) ; int length = stringToSearch . length ( ) ; int count = 0 ; char character = 0 ; boolean foundNonSpaceChar = false ; for ( int i = 0 ; i < length ; i ++ ) { character = stringToSearch . charAt ( i ) ; if ( character == '\r' && ( i + 1 ) < length && stringToSearch . charAt ( i + 1 ) == '\n' ) { i ++ ; } if ( character == '\n' || character == '\r' ) { if ( countBlankLines ) { count ++ ; } else { if ( foundNonSpaceChar ) { count ++ ; } } foundNonSpaceChar = false ; } else if ( character != ' ' && character != '\t' ) { foundNonSpaceChar = true ; } } if ( character != '\n' && character != '\r' ) { count ++ ; } return count ; }
counts the number of distinct lines in a string .
