# File lib/sass/util.rb, line 888
    def check_sass_encoding(str)
      # On Ruby 1.8 we can't do anything complicated with encodings.
      # Instead, we just strip out a UTF-8 BOM if it exists and
      # sanitize according to Section 3.3 of CSS Syntax Level 3. We
      # don't sanitize null characters since they might be components
      # of other characters.
      if ruby1_8?
        return str.gsub(/\A\xEF\xBB\xBF/, '').gsub(/\r\n?|\f/, "\n"), nil
      end

      # Determine the fallback encoding following section 3.2 of CSS Syntax Level 3 and Encodings:
      # http://www.w3.org/TR/2013/WD-css-syntax-3-20130919/#determine-the-fallback-encoding
      # http://encoding.spec.whatwg.org/#decode
      binary = str.dup.force_encoding("BINARY")
      if binary.start_with?(UTF_8_BOM)
        binary.slice! 0, UTF_8_BOM.length
        str = binary.force_encoding('UTF-8')
      elsif binary.start_with?(UTF_16BE_BOM)
        binary.slice! 0, UTF_16BE_BOM.length
        str = binary.force_encoding('UTF-16BE')
      elsif binary.start_with?(UTF_16LE_BOM)
        binary.slice! 0, UTF_16LE_BOM.length
        str = binary.force_encoding('UTF-16LE')
      elsif binary =~ CHARSET_REGEXP
        charset = $1.force_encoding('US-ASCII')
        # Ruby 1.9.2 doesn't recognize a UTF-16 encoding without an endian marker.
        if ruby1_9_2? && charset.downcase == 'utf-16'
          encoding = Encoding.find('UTF-8')
        else
          encoding = Encoding.find(charset)
          if encoding.name == 'UTF-16' || encoding.name == 'UTF-16BE'
            encoding = Encoding.find('UTF-8')
          end
        end
        str = binary.force_encoding(encoding)
      elsif str.encoding.name == "ASCII-8BIT"
        # Normally we want to fall back on believing the Ruby string
        # encoding, but if that's just binary we want to make sure
        # it's valid UTF-8.
        str = str.force_encoding('utf-8')
      end

      find_encoding_error(str) unless str.valid_encoding?

      begin
        # If the string is valid, preprocess it according to section 3.3 of CSS Syntax Level 3.
        return str.encode("UTF-8").gsub(/\r\n?|\f/, "\n").tr("\u0000", "�"), str.encoding
      rescue EncodingError
        find_encoding_error(str)
      end
    end