public static String normalize ( final CharSequence self ) { final String s = self . toString ( ) ; int nx = s . indexOf ( ' ' ) ; if ( nx < 0 ) { return s ; } final int len = s . length ( ) ; final StringBuilder sb = new StringBuilder ( len ) ; int i = 0 ; do { sb . append ( s , i , nx ) ; sb . append ( ' ' ) ; if ( ( i = nx + 1 ) >= len ) break ; if ( s . charAt ( i ) == ' ' ) { // skip the LF in CR LF if ( ++ i >= len ) break ; } nx = s . indexOf ( ' ' , i ) ; } while ( nx > 0 ) ; sb . append ( s , i , len ) ; return sb . toString ( ) ; }
Return a String with linefeeds and carriage returns normalized to linefeeds .