Permalink
Browse files

2339: strip_whitespace now fixes surplus EOF newlines.

  • Loading branch information...
1 parent f6d5119 commit 2645659c8b6fde5bfbd767abd651592a7f07f97b @JDougherty JDougherty committed with smichr May 15, 2012
Showing with 11 additions and 0 deletions.
  1. +11 −0 bin/strip_whitespace
View
@@ -15,6 +15,7 @@ def strip_file(filename, write, report):
lines = f.readlines()
hit = False
cr = False
+ extra = 0
for index, line in enumerate(lines):
if line.endswith(" \n"):
if report:
@@ -38,6 +39,16 @@ def strip_file(filename, write, report):
if write:
hit = True
+ # correct multiple newlines at eof
+ while len(lines) > 1 and lines[-1] == "\n" and lines[-2].endswith("\n"):
+ if write:
+ hit = True
+ lines.pop()
+ extra += 1
+
+ if extra > 0 and report:
+ print "%s, %d extra newlines at eof" % (filename, extra)
+
if write and hit:
# without "b" the lines may be written in sys-dep format
with open(filename, "wb") as f:

0 comments on commit 2645659

Please sign in to comment.