Sets the encoding of string based on the magic comment
# File lib/rdoc/encoding.rb, line 86
def self.set_encoding string
remove_frozen_string_literal string
string =~ /\A(?:#!.*\n)?(.*\n)/
first_line = $1
name = case first_line
when /^<\?xml[^?]*encoding=(["'])(.*?)\11// then $2
when /\b(?:en)?coding[=:]\s*([^\s;]+)/ then $1
else return
end
string.sub! first_line, ''
remove_frozen_string_literal string
enc = Encoding.find name
string.force_encoding enc if enc
end