Method: String#xml_encode

Defined in:
lib/ronin/support/encoding/xml/core_ext/string.rb

#xml_encode(**kwargs) ⇒ String

Encodes each character in the String as an XML character.

Examples:

"abc".xml_encode
# => "abc"

Zero-padding:

"abc".xml_encode(zero_pad: true)
# => "abc"

Hexadecimal encoded characters:

"abc".xml_encode(format: :hex)
# => "abc"

Uppercase hexadecimal encoded characters:

"abc\xff".xml_encode(format: :hex, case: :upper)
# => "abcÿ"

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

Options Hash (**kwargs):

  • :format (:decimal, :hex) — default: :decimal

    The numeric format for the escaped characters.

  • :zero_pad (Boolean)

    Controls whether the escaped characters will be left-padded with up to seven 0 characters.

  • :case (:lower, :upper, nil)

    Controls whether to output lowercase or uppercase XML special characters. Defaults to lowercase hexadecimal.

Returns:

  • (String)

    The XML encoded String.

See Also:

Since:

  • 1.0.0



118
119
120
# File 'lib/ronin/support/encoding/xml/core_ext/string.rb', line 118

def xml_encode(**kwargs)
  Ronin::Support::Encoding::XML.encode(self,**kwargs)
end