Created
June 28, 2010 21:00
-
-
Save spraints/456348 to your computer and use it in GitHub Desktop.
This doesn't work. It says everything is a unix newline.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def report_newlines filename, io | |
| windows_newlines = 0 | |
| unix_newlines = 0 | |
| last_line_is_bare = false | |
| while line = io.gets | |
| last_line_is_bare = false | |
| if line =~ /\r\n$/ | |
| windows_newlines += 1 | |
| elsif line =~ /\n$/ | |
| unix_newlines += 1 | |
| else | |
| last_line_is_bare = true | |
| end | |
| end | |
| puts "#{filename}: windows #{windows_newlines} - #{unix_newlines} unix#{last_line_is_bare ? ' (no newline at EOF)' : ''}" | |
| end | |
| ARGV.each do |filename| | |
| begin | |
| open filename do |f| | |
| report_newlines filename, f | |
| end | |
| rescue => e | |
| puts "#{filename}: #{e}" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment