module Sprockets::EncodingUtils

def detect_unicode_bom(str)

no BOM was present.
Returns UTF 8/16/32 encoded String without BOM or the original String if

str - ASCII-8BIT encoded String

Public: Detect and strip BOM from possible unicode string.
def detect_unicode_bom(str)
  bom_bytes = str.byteslice(0, 4).bytes.to_a
  BOM.each do |encoding, bytes|
    if bom_bytes[0, bytes.size] == bytes
      str = str.dup
      str.force_encoding(Encoding::BINARY)
      str.slice!(0, bytes.size)
      str.force_encoding(encoding)
      return str
    end
  end
  return str
end