From: Steve Hancock Date: Wed, 27 Sep 2023 15:12:35 +0000 (-0700) Subject: move conversion of CR-LF to LF line endings upstream X-Git-Tag: 20230912.02~7 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=4917d00733a5ecce48662f7b11dae0520f06aae1;p=perltidy.git move conversion of CR-LF to LF line endings upstream --- diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 8b47cedf..1f18d133 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -1809,29 +1809,40 @@ sub set_line_separator { else { } } - # Now change the line separator if requested if ( defined($input_line_separator) ) { + # Remember the input line separator if needed if ( $rOpts->{'preserve-line-endings'} ) { $line_separator = $input_line_separator; } - # patch to read raw mac files under unix, dos - if ( $input_line_separator ne "\n" && $input_line_separator eq $CR ) { - - # if this file is currently a single line .. + # Convert line endings to "\n" for processing if necessary. + if ( $input_line_separator ne "\n" ) { my @lines = split /^/, ${$rinput_string}; - if ( @lines == 1 ) { - # and becomes multiple lines with the change .. - @lines = map { $_ . "\n" } split /$CR/, ${$rinput_string}; - if ( @lines > 1 ) { + # try to convert CR to \n + if ( $input_line_separator eq $CR ) { + + # if this file is currently a single line .. + if ( @lines == 1 ) { - # then make the change - my $buf = join EMPTY_STRING, @lines; - $rinput_string = \$buf; + # and becomes multiple lines with the change .. + @lines = map { $_ . "\n" } split /$CR/, ${$rinput_string}; + if ( @lines > 1 ) { + + # then make the change + my $buf = join EMPTY_STRING, @lines; + $rinput_string = \$buf; + } } } + + # convert CR-LF to LF + elsif ( ( $input_line_separator eq $CRLF ) && ( "\n" eq $LF ) ) { + foreach my $line (@lines) { $line =~ s/$CRLF$/\n/ } + my $buf = join EMPTY_STRING, @lines; + $rinput_string = \$buf; + } } }