Skip to content

Instantly share code, notes, and snippets.

@e0da
Created January 29, 2016 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e0da/84288fbac083cb843bc9 to your computer and use it in GitHub Desktop.
Save e0da/84288fbac083cb843bc9 to your computer and use it in GitHub Desktop.
Report non-ASCII characters in a file
#!/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