Sha256: 1ea74bc5762df83510135016d80832f05560ddbe5d64902d76b04f3630403acd

Contents?: true

Size: 587 Bytes

Versions: 3

Compression:

Stored size: 587 Bytes

Contents

module Ethon
  class Easy # :nodoc:

    # This module contains small helpers.
    module Util

      # Escapes zero bytes in strings.
      #
      # @example Escape zero bytes.
      #   Util.escape_zero_byte("1\0")
      #   #=> "1\\0"
      #
      # @param [ Object ] value The value to escape.
      #
      # @return [ String, Object ] Escaped String if
      #   zero byte found, original object if not.
      def escape_zero_byte(value)
        return value unless value.to_s.include?(0.chr)
        value.to_s.gsub(0.chr, '\\\0')
      end

      extend self
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ethon-0.5.0 lib/ethon/easy/util.rb
ethon-0.4.4 lib/ethon/easy/util.rb
ethon-0.4.3 lib/ethon/easy/util.rb