Created
January 29, 2016 00:58
-
-
Save e0da/84288fbac083cb843bc9 to your computer and use it in GitHub Desktop.
Report non-ASCII characters in a file
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
#!/usr/bin/env ruby | |
# x starts at 0 because we increment x BEFORE checking the character. | |
# y starts at 1 because we only increment it when we hit a newline. | |
x, y = 0, 1 | |
puts 'Positions are 1-indexed, NOT 0-indexed.' | |
puts 'i.e. The first character in the file is at position 1:1' | |
puts | |
File.read(ARGV[0]).split('').each do |char| | |
x += 1 | |
puts "#{char} at #{y}:#{x} is not an ASCII character" unless char.ascii_only? | |
if char == "\n" | |
x = 0 | |
y += 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment