def check_haml_encoding(str, &block)
      str = str.dup if str.frozen?

      bom, encoding = parse_haml_magic_comment(str)
      if encoding; str.force_encoding(encoding)
      elsif bom; str.force_encoding(Encoding::UTF_8)
      end

      return check_encoding(str, &block)
    end
def check_haml_encoding(str, &block)
      str = str.dup if str.frozen?

      bom, encoding = parse_haml_magic_comment(str)
      if encoding; str.force_encoding(encoding)
      elsif bom; str.force_encoding(Encoding::UTF_8)
      end

      return check_encoding(str, &block)
    end
Like {\#check\_encoding}, but also checks for a Ruby-style `-# coding:` comment
 at the beginning of the template and uses that encoding if it exists.

 The Haml encoding rules are simple.
 If a `-# coding:` comment exists,
 we assume that that's the original encoding of the document.
 Otherwise, we use whatever encoding Ruby has.

 Haml uses the same rules for parsing coding comments as Ruby.
 This means that it can understand Emacs-style comments
 (e.g. `-*- encoding: "utf-8" -*-`),
 and also that it cannot understand non-ASCII-compatible encodings
 such as `UTF-16` and `UTF-32`.

 @param str [String] The Haml template of which to check the encoding
 @yield [msg] A block in which an encoding error can be raised.
   Only yields if there is an encoding error
 @yieldparam msg [String] The error message to be raised
 @return [String] The original string encoded properly
 @raise [ArgumentError] if the document declares an unknown encoding