def self.safe_iconv(to, from, str)
iconv = Iconv.new(to, from)
out = ""
begin
out << iconv.iconv(str)
rescue Iconv::IllegalSequence => e
out << e.success
ch, str = e.failed.split(//, 2)
out << '?'
STDERR.puts("Failed to convert #{ch}")
retry
end
return out
end