diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-01 13:08:20 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-01 13:08:20 +0000 |
commit | 0dd9c302d9374f52abb09662b554e4ee95011444 () | |
tree | 58a26d5d86ba98caa360b4d319e5092f6a5ba2b1 /pack.c | |
parent | 74495cfa11743a9cd1b27da81968cfbc00538bc4 (diff) |
Supports `buffer` and `offset` in `Array#pack`
* pack.c (pack_pack): Supports `buffer` and `offset` in `Array#pack`. [Feature #12754] [ruby-dev:49798] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | pack.c | 61 |
1 files changed, 56 insertions, 5 deletions
@@ -140,7 +140,9 @@ rb_str_associated(VALUE str) /* * call-seq: - * arr.pack ( aTemplateString ) -> aBinaryString * * Packs the contents of <i>arr</i> into a binary sequence according to * the directives in <i>aTemplateString</i> (see the table below) @@ -162,6 +164,18 @@ rb_str_associated(VALUE str) * a.pack("a3a3a3") #=> "a\000\000b\000\000c\000\000" * n.pack("ccc") #=> "ABC" * * Directives for +pack+. * * Integer | Array | @@ -255,12 +269,12 @@ rb_str_associated(VALUE str) */ static VALUE -pack_pack(VALUE ary, VALUE fmt) { static const char nul10[] = "\0\0\0\0\0\0\0\0\0\0"; static const char spc10[] = " "; const char *p, *pend; - VALUE res, from, associates = 0; char type; long len, idx, plen; const char *ptr; @@ -270,10 +284,47 @@ pack_pack(VALUE ary, VALUE fmt) #endif int integer_size, bigendian_p; StringValue(fmt); p = RSTRING_PTR(fmt); pend = p + RSTRING_LEN(fmt); - res = rb_str_buf_new(0); idx = 0; @@ -1948,7 +1999,7 @@ utf8_to_uv(const char *p, long *lenp) void Init_pack(void) { - rb_define_method(rb_cArray, "pack", pack_pack, 1); rb_define_method(rb_cString, "unpack", pack_unpack, 1); id_associated = rb_make_internal_id(); |