Method: Rex::Text.to_utf8

Defined in:
lib/rex/text.rb

.to_utf8(str) ⇒ Object

Converts ISO-8859-1 to UTF-8



378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/rex/text.rb', line 378

def self.to_utf8(str)

  if str.respond_to?(:encode)
    # Skip over any bytes that fail to convert to UTF-8
    return str.encode('utf-8', { :invalid => :replace, :undef => :replace, :replace => '' })
  end

  begin
    Iconv.iconv("utf-8","iso-8859-1", str).join(" ")
  rescue
    raise ::RuntimeError, "Your installation does not support iconv (needed for utf8 conversion)"
  end
end