def check_sass_encoding(str)
      # 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')
        encoding = Encoding.find(charset)
        if encoding.name == 'UTF-16' || encoding.name == 'UTF-16BE'
          encoding = Encoding.find('UTF-8')
        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
def check_sass_encoding(str)
      # 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')
        encoding = Encoding.find(charset)
        if encoding.name == 'UTF-16' || encoding.name == 'UTF-16BE'
          encoding = Encoding.find('UTF-8')
        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
Like {\#check\_encoding}, but also checks for a `@charset` declaration
 at the beginning of the file and uses that encoding if it exists.

 Sass follows CSS's decoding rules.

 @param str [String] The string of which to check the encoding
 @return [(String, Encoding)] The original string encoded as UTF-8,
   and the source encoding of the string
 @raise [Encoding::UndefinedConversionError] if the source encoding
   cannot be converted to UTF-8
 @raise [ArgumentError] if the document uses an unknown encoding with `@charset`
 @raise [Sass::SyntaxError] If the document declares an encoding that
   doesn't match its contents, or it doesn't declare an encoding and its
   contents are invalid in the native encoding.