private string ReplaceNewLines( string str ) {
if ( str == null ) {
return null;
}
StringBuilder sb = null;
int start = 0;
int i;
for ( i = 0; i < str.Length; i++ ) {
char ch;
if ( ( ch = str[i] ) >= 0x20 ) {
continue;
}
if ( ch == '\n' ) {
if ( newLineChars == "\n" ) {
continue;
}
if ( sb == null ) {
sb = new StringBuilder( str.Length + 5 );
}
sb.Append( str, start, i - start );
}
else if ( ch == '\r' ) {
if ( i + 1 < str.Length && str[i+1] == '\n' ) {
if ( newLineChars == "\r\n" ) {
i++;
continue;
}
if ( sb == null ) {
sb = new StringBuilder( str.Length + 5 );
}
sb.Append( str, start, i - start );
i++;
}
else {
if ( newLineChars == "\r" ) {
continue;
}
if ( sb == null ) {
sb = new StringBuilder( str.Length + 5 );
}
sb.Append( str, start, i - start );
}
}
else {
continue;
}
sb.Append( newLineChars );
start = i + 1;
}
if ( sb == null ) {
return str;
}
else {
sb.Append( str, start, i - start );
return sb.ToString();
}
}