summaryrefslogtreecommitdiff
path: root/pack.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-30 09:19:13 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-30 09:19:13 +0000
commit93fa4cbf3d01c389c4f23408cacf05922583ed84 (patch)
treea59d4854cc7cd8889c02124fb424118ccaf143cb /pack.c
parent86c50e39838fc5831163e3b92a9047d539fb46ee (diff)
* pack.c (pack_pack): templates a, A, Z should propagate encoding
of original strings. templates b, B, h, H brings ASCII-8BIT to the result. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20057 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'pack.c')
-rw-r--r--pack.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/pack.c b/pack.c
index df25231610..2ecb2d68d6 100644
--- a/pack.c
+++ b/pack.c
@@ -519,8 +519,15 @@ pack_pack(VALUE ary, VALUE fmt)
ptr = RSTRING_PTR(from);
plen = RSTRING_LEN(from);
OBJ_INFECT(res, from);
- enc = rb_enc_compatible(res, from);
- rb_enc_associate(res, enc);
+ switch (type) {
+ case 'a': case 'A': case 'Z':
+ enc = rb_enc_compatible(res, from);
+ rb_enc_associate(res, enc);
+ break;
+ default:
+ rb_enc_associate(res, rb_ascii8bit_encoding());
+ break;
+ }
}
if (p[-1] == '*')