question: public static String unifyLineSeparators ( String s , String ls ) { if ( s == null ) { return null ; } if ( ls == null ) { ls = System . getProperty ( "line.separator" ) ; } if ( ! ( ls . equals ( "\n" ) || ls . equals ( "\r" ) || ls . equals ( "\r\n" ) ) ) { throw new IllegalArgumentException ( "Requested line separator is invalid." ) ; } int length = s . length ( ) ; StringBuilder buffer = new StringBuilder ( length ) ; for ( int i = 0 ; i < length ; i ++ ) { if ( s . charAt ( i ) == '\r' ) { if ( ( i + 1 ) < length && s . charAt ( i + 1 ) == '\n' ) { i ++ ; } buffer . append ( ls ) ; } else if ( s . charAt ( i ) == '\n' ) { buffer . append ( ls ) ; } else { buffer . append ( s . charAt ( i ) ) ; } } return buffer . toString ( ) ; }
target:  Parses the given String and replaces all occurrences of '\n', '\r' and '\r\n' with the given line separator.