]> git.donarmstrong.com Git - perltidy.git/commitdiff
update output-line-ending code, part 1
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 6 Feb 2023 01:36:55 +0000 (17:36 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 6 Feb 2023 01:36:55 +0000 (17:36 -0800)
Moved from Formatter.pm to Tidy.pm, a more logical place

lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm

index ed746b0c9205c8f2a0588d9180d0b3c1c5a01c31..5bd998854ad05f48d38dbe15d7652bc20459ac4e 100644 (file)
@@ -4293,6 +4293,8 @@ sub check_options {
 EOM
     }
 
+    initialize_output_line_ending($rOpts);
+
     # Since -vt, -vtc, and -cti are abbreviations, but under
     # msdos, an unquoted input parameter like vtc=1 will be
     # seen as 2 parameters, vtc and 1, so the abbreviations
@@ -4491,6 +4493,58 @@ EOM
     return $tabsize;
 } ## end sub check_options
 
+sub initialize_output_line_ending {
+    my ($rOpts) = @_;
+
+    # TODO:
+    #   - need to call with $self
+    #   - the output_line_ending should stored in _line_separator_
+
+    my $ole = $rOpts->{'output-line-ending'};
+    if ($ole) {
+        my %endings = (
+            dos  => "\015\012",
+            win  => "\015\012",
+            mac  => "\015",
+            unix => "\012",
+        );
+
+        # Patch for RT #99514, a memoization issue.
+        # Normally, the user enters one of 'dos', 'win', etc, and we change the
+        # value in the options parameter to be the corresponding line ending
+        # character.  But, if we are using memoization, on later passes through
+        # here the option parameter will already have the desired ending
+        # character rather than the keyword 'dos', 'win', etc.  So
+        # we must check to see if conversion has already been done and, if so,
+        # bypass the conversion step.
+        my %endings_inverted = (
+            "\015\012" => 'dos',
+            "\015\012" => 'win',
+            "\015"     => 'mac',
+            "\012"     => 'unix',
+        );
+
+        if ( defined( $endings_inverted{$ole} ) ) {
+
+            # we already have valid line ending, nothing more to do
+        }
+        else {
+            $ole = lc $ole;
+            unless ( $rOpts->{'output-line-ending'} = $endings{$ole} ) {
+                my $str = join SPACE, keys %endings;
+                Die(<<EOM);
+Unrecognized line ending '$ole'; expecting one of: $str
+EOM
+            }
+            if ( $rOpts->{'preserve-line-endings'} ) {
+                Warn("Ignoring -ple; conflicts with -ole\n");
+                $rOpts->{'preserve-line-endings'} = undef;
+            }
+        }
+    }
+    return;
+} ## end sub initialize_output_line_ending
+
 sub find_file_upwards {
     my ( $search_dir, $search_file ) = @_;
 
index a0410c220a1831121ec5a2672ed33ce5955e79aa..91c839f7db7d34c5ef30ac4a7685cb18198f947b 100644 (file)
@@ -1657,49 +1657,6 @@ EOM
         $rOpts->{'long-block-line-count'} = 1_000_000;
     }
 
-    my $ole = $rOpts->{'output-line-ending'};
-    if ($ole) {
-        my %endings = (
-            dos  => "\015\012",
-            win  => "\015\012",
-            mac  => "\015",
-            unix => "\012",
-        );
-
-        # Patch for RT #99514, a memoization issue.
-        # Normally, the user enters one of 'dos', 'win', etc, and we change the
-        # value in the options parameter to be the corresponding line ending
-        # character.  But, if we are using memoization, on later passes through
-        # here the option parameter will already have the desired ending
-        # character rather than the keyword 'dos', 'win', etc.  So
-        # we must check to see if conversion has already been done and, if so,
-        # bypass the conversion step.
-        my %endings_inverted = (
-            "\015\012" => 'dos',
-            "\015\012" => 'win',
-            "\015"     => 'mac',
-            "\012"     => 'unix',
-        );
-
-        if ( defined( $endings_inverted{$ole} ) ) {
-
-            # we already have valid line ending, nothing more to do
-        }
-        else {
-            $ole = lc $ole;
-            unless ( $rOpts->{'output-line-ending'} = $endings{$ole} ) {
-                my $str = join SPACE, keys %endings;
-                Die(<<EOM);
-Unrecognized line ending '$ole'; expecting one of: $str
-EOM
-            }
-            if ( $rOpts->{'preserve-line-endings'} ) {
-                Warn("Ignoring -ple; conflicts with -ole\n");
-                $rOpts->{'preserve-line-endings'} = undef;
-            }
-        }
-    }
-
     # hashes used to simplify setting whitespace
     %tightness = (
         '{' => $rOpts->{'brace-tightness'},