colszowka/simplecov — pull request #117 by Deradon (2012-03-19 19:46:58+00:00)
Title: Encoding issues with iso-8859 encoded files

I had issues using simplecov with an file, that contained something like this:

# localized to Español thus:

Had no chance to edit this file, so I might provide a workaround here, so that simplecov can hande such files.

In one of my projects I use something like this for UTF-8 encoding:

def self.umlauts(text)
# Read more: http://stackoverflow.com/questions/2982677/ruby-1-9-invalid-byte-sequence-in-utf-8
# Switch to ruby 1.9 String#encode, with backward 1.8 compatibility
if text.respond_to?(:encode!)
text.encode!('UTF-8', 'UTF-8', :invalid => :replace)
else
require 'iconv'
text = Iconv.conv('ISO_8859-15//IGNORE//TRANSLIT', 'UTF-8', text)
end
end