Is it possible to change a file’s encoding mid read?
Trying do do something along the lines of the following:
file = File.open('testfile.rb', 'r:US-ASCII')
file.each_line do |line|
if (file.lineno == 1 || file.lineno == 2) && line =~ /
^#.*coding:\s([\w-]+)/
file.force_encoding($1)
end
next if line.valid_encoding?
puts “bad encoding: [%s:%d]” % [file.path, file.lineno]
end
-Adam