module Sprockets::EncodingUtils

def scan_css_charset(str)

Returns encoding String name or nil.

str - ASCII-8BIT encoded String

Internal: Scan binary CSS string for @charset encoding name.
def scan_css_charset(str)
  buf = []
  i = 0
  str.each_byte.each do |byte|
    # Halt on line breaks
    break if byte == 0x0A || byte == 0x0D
    # Only ascii bytes
    next unless 0x0 < byte && byte <= 0xFF
    if i < CHARSET_SIZE
    elsif i == CHARSET_SIZE
      if buf == CHARSET_START
        buf = []
      else
        break
      end
    elsif byte == 0x22
      return buf.pack('C*')
    end
    buf << byte
    i += 1
  end
  nil
end