# File lib/rexml/encoding.rb, line 57 def check_encoding str # We have to recognize UTF-16, LSB UTF-16, and UTF-8 if str[0] == 0xfe && str[1] == 0xff str[0,2] = "" return UTF_16 elsif str[0] == 0xff && str[1] == 0xfe str[0,2] = "" return UNILE end str =~ /^\s*<\?xml\s+version\s*=\s*(['"]).*?\1\s+encoding\s*=\s*(["'])(.*?)\2/um return $3.upcase if $3 return UTF_8 end