module Sprockets::EncodingUtils

def detect_html(str)

Returns a encoded String.

str - String.

and finally falls back to the environment's external encoding.
Attempts to parse any Unicode BOM otherwise attempt Charlock detection

Public: Detect charset from HTML document.
def detect_html(str)
  str = detect_unicode_bom(str)
  # Attempt Charlock detection
  if str.encoding == Encoding::BINARY
    charlock_detect(str)
  end
  # Fallback to environment's external encoding
  if str.encoding == Encoding::BINARY
    str.force_encoding(Encoding.default_external)
  end
  str
end