class CodeRay::Scanners::Scanner

def encode_with_encoding code, target_encoding

def encode_with_encoding code, target_encoding
  if code.encoding == target_encoding
    if code.valid_encoding?
      return to_unix(code)
    else
      source_encoding = guess_encoding code
    end
  else
    source_encoding = code.encoding
  end
  # print "encode_with_encoding from #{source_encoding} to #{target_encoding}"
  code.encode target_encoding, source_encoding, :universal_newline => true, :undef => :replace, :invalid => :replace
end