From c98cd013dfbd846da3c9bd3b23eb03f2d3344e9e Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 2 Oct 2023 07:07:40 -0700 Subject: [PATCH] cleanup some regexes --- lib/Perl/Tidy.pm | 2 +- lib/Perl/Tidy/Formatter.pm | 10 +++++----- lib/Perl/Tidy/Logger.pm | 2 +- lib/Perl/Tidy/Tokenizer.pm | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 1a08f481..0cc3f3de 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -5186,7 +5186,7 @@ sub read_config_file { strip_comment( $line, $config_file, $line_no ); last if ($death_message); next unless $line; - $line =~ s/^\s*(.*?)\s*$/$1/; # trim both ends + $line =~ s/^ \s+ | \s+ $//gx; # trim both ends next unless $line; my $body = $line; diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 91edaa30..6b89b4df 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -5354,7 +5354,7 @@ sub make_static_block_comment_pattern { # allow the user to change it if ( $rOpts->{'static-block-comment-prefix'} ) { my $prefix = $rOpts->{'static-block-comment-prefix'}; - $prefix =~ s/^\s*//; + $prefix =~ s/^\s+//; my $pattern = $prefix; # user may give leading caret to force matching left comments only @@ -5380,7 +5380,7 @@ sub make_format_skipping_pattern { my ( $opt_name, $default ) = @_; my $param = $rOpts->{$opt_name}; if ( !$param ) { $param = $default } - $param =~ s/^\s*//; + $param =~ s/^\s+//; if ( $param !~ /^#/ ) { Die("ERROR: the $opt_name parameter '$param' must begin with '#'\n"); } @@ -5404,7 +5404,7 @@ sub make_non_indenting_brace_pattern { # allow the user to change it if ( $rOpts->{'non-indenting-brace-prefix'} ) { my $prefix = $rOpts->{'non-indenting-brace-prefix'}; - $prefix =~ s/^\s*//; + $prefix =~ s/^\s+//; if ( $prefix !~ /^#/ ) { Die("ERROR: the -nibp parameter '$prefix' must begin with '#'\n"); } @@ -5751,7 +5751,7 @@ sub make_static_side_comment_pattern { # allow the user to change it if ( $rOpts->{'static-side-comment-prefix'} ) { my $prefix = $rOpts->{'static-side-comment-prefix'}; - $prefix =~ s/^\s*//; + $prefix =~ s/^\s+//; my $pattern = '^' . $prefix; if ( bad_pattern($pattern) ) { Die( @@ -32225,7 +32225,7 @@ sub add_closing_side_comment { $token = balance_csc_text($token) if $rOpts->{'closing-side-comments-balanced'}; - $token =~ s/\s*$//; # trim any trailing whitespace + $token =~ s/\s+$//; # trim any trailing whitespace # handle case of existing closing side comment if ($have_side_comment) { diff --git a/lib/Perl/Tidy/Logger.pm b/lib/Perl/Tidy/Logger.pm index b25f7507..14cc62e5 100644 --- a/lib/Perl/Tidy/Logger.pm +++ b/lib/Perl/Tidy/Logger.pm @@ -194,7 +194,7 @@ sub black_box { $structural_indentation_level = 0 if ( $structural_indentation_level < 0 ); $self->{_last_input_line_written} = $input_line_number; - ( my $out_str = $input_line ) =~ s/^\s*//; + ( my $out_str = $input_line ) =~ s/^\s+//; chomp $out_str; $out_str = ( '.' x $structural_indentation_level ) . $out_str; diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 2ad9d1d6..a88fac53 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -2,7 +2,7 @@ # # Perl::Tidy::Tokenizer reads a source and breaks it into a stream of tokens # -# Usage: +# Usage Outline: # # STEP 1: initialize or re-initialze Tokenizer with user options # Perl::Tidy::Tokenizer::check_options($rOpts); @@ -318,7 +318,7 @@ sub make_code_skipping_pattern { my ( $rOpts, $opt_name, $default ) = @_; my $param = $rOpts->{$opt_name}; if ( !$param ) { $param = $default } - $param =~ s/^\s*//; # allow leading spaces to be like format-skipping + $param =~ s/^\s+//; # allow leading spaces to be like format-skipping if ( $param !~ /^#/ ) { Die("ERROR: the $opt_name parameter '$param' must begin with '#'\n"); } @@ -1141,7 +1141,7 @@ sub get_line { # Handle <<~ targets, which are indicated here by a leading space on # the here quote character if ( $here_quote_character =~ /^\s/ ) { - $candidate_target =~ s/^\s*//; + $candidate_target =~ s/^\s+//; } if ( $candidate_target eq $here_doc_target ) { $self->[_nearly_matched_here_target_at_] = undef; @@ -6899,7 +6899,7 @@ sub peek_ahead_for_n_nonblank_pre_tokens { my ( $rpre_tokens, $rmap, $rpre_types ); while ( $line = $self->peek_ahead( $i++ ) ) { - $line =~ s/^\s*//; # trim leading blanks + $line =~ s/^\s+//; # trim leading blanks next if ( length($line) <= 0 ); # skip blank next if ( $line =~ /^#/ ); # skip comment ( $rpre_tokens, $rmap, $rpre_types ) = @@ -6918,7 +6918,7 @@ sub peek_ahead_for_nonblank_token { my $i = 0; while ( $line = $self->peek_ahead( $i++ ) ) { - $line =~ s/^\s*//; # trim leading blanks + $line =~ s/^\s+//; # trim leading blanks next if ( length($line) <= 0 ); # skip blank next if ( $line =~ /^#/ ); # skip comment @@ -9981,7 +9981,7 @@ sub write_error_indicator_pair { make_numbered_line( $line_number, $input_line, $pos ); $underline = write_on_underline( $underline, $pos - $offset, $carrat ); $self->warning( $numbered_line . "\n" ); - $underline =~ s/\s*$//; + $underline =~ s/\s+$//; $self->warning( $underline . "\n" ); return; } ## end sub write_error_indicator_pair -- 2.39.5