Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improved recognizing patterns and some whitespace errors

  • Loading branch information...
commit b11e19e3a41ebb24f517b406ae0aba46acab56e5 1 parent 9844c72
@dermesser authored
Showing with 16 additions and 10 deletions.
  1. +2 −0  README
  2. +4 −4 example.txt
  3. +4 −4 use_this_example.txt
  4. +6 −2 whitespace.pl
View
2  README
@@ -4,6 +4,8 @@ A whitespace error is:
- tabs in an (else) empty line
- spaces in an empty line
- or both
+ - whitespaces before the newline character
+
Whitespace errors are created when working with a auto-indent
text editor like vim or some IDEs. This script removes the errors from
the file. The clean file is written back to the original file.
View
8 example.txt
@@ -1,10 +1,10 @@
-Hello,
+Hello,
-World.
+World.
-This file
+This file
-contains whitespace errors.
+contains whitespace errors.
That is if
View
8 use_this_example.txt
@@ -1,10 +1,10 @@
-Hello,
+Hello,
-World.
+World.
-This file
+This file
-contains whitespace errors.
+contains whitespace errors.
That is if
View
8 whitespace.pl
@@ -7,7 +7,8 @@
die("Usage: whitespace.pl <FILE>\n") if scalar @ARGV == 0;
-my $pat = qr/^(\t| )+$/;
+my $pat_emptyline = qr/^(\t| )+$/;
+my $pat_endofline = qr/^(.+?)( |\t)+$/;
foreach my $actual_file (@ARGV)
{
@@ -20,10 +21,13 @@
{
$i++;
- if ( $line =~ $pat )
+ if ( $line =~ $pat_emptyline )
{
#print $i." ".$line;
print $tempfile "\n";
+ } elsif ( $line =~ $pat_endofline )
+ {
+ print $tempfile $1 . "\n";
} else
{
print $tempfile $line;
Please sign in to comment.
Something went wrong with that request. Please try again.