Sha256: 3fe03037396f950ed4d383f48e34d475f34c2a5c69989c79ade2cdd296f65f92
Contents?: true
Size: 999 Bytes
Versions: 26
Compression:
Stored size: 999 Bytes
Contents
class String alias_method( :unpack_from_orgin, :unpack ) # Upack with offset. Extends #unpack to allow a string # to be unpacked starting at an offset position within it. # def unpack(format, offset=nil) if offset.nil? unpack_from_orgin(format) else self[offset..-1].unpack_from_orgin(format) end end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TCString < Test::Unit::TestCase def test_unpack str, fmt = "abc\0", "Z*" assert_equal "abc", str.unpack(fmt).first assert_equal "abc", str.unpack(fmt, 0).first assert_equal "bc", str.unpack(fmt, 1).first assert_equal "bc", str.unpack(fmt, -3).first assert_equal "c", str.unpack(fmt, 2).first assert_equal "c", str.unpack(fmt, -2).first assert_equal "", str.unpack(fmt, 3).first assert_equal "", str.unpack(fmt, -1).first end end =end
Version data entries
26 entries across 26 versions & 1 rubygems