summaryrefslogtreecommitdiffstats
path: root/transcode.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-31 07:59:03 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-31 07:59:03 +0000
commitca31fb0e58e453e91c6ed258e909c37b0f6bb433 (patch)
tree7a7036d0da3815cfe3c3eb186022a0a94b794798 /transcode.c
parenta7a4f63d9b6e6af365a7add9351713336d95bb64 (diff)
downloadruby-ca31fb0e58e453e91c6ed258e909c37b0f6bb433.tar.gz
ruby-ca31fb0e58e453e91c6ed258e909c37b0f6bb433.tar.xz
ruby-ca31fb0e58e453e91c6ed258e909c37b0f6bb433.zip
* transcode.c (econv_putback): associate encoding to the result.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'transcode.c')
-rw-r--r--transcode.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/transcode.c b/transcode.c
index 429a0a4f7..2afed2c77 100644
--- a/transcode.c
+++ b/transcode.c
@@ -2751,6 +2751,30 @@ econv_insert_output(VALUE self, VALUE string)
return Qnil;
}
+/*
+ * call-seq
+ * putback => string
+ * putback(max_numbytes) => string
+ *
+ * put back the bytes which will be converted.
+ *
+ * The bytes are caused by invalid_byte_sequence error.
+ * When invalid_byte_sequence error, some bytes are discarded and
+ * some bytes may be converted again.
+ * The latter bytes can be put back.
+ * It can be observed by
+ * Encoding::InvalidByteSequence#readagain_bytes and
+ * Encoding::Converter#primitive_errinfo.
+ *
+ * ec = Encoding::Converter.new("utf-16le", "iso-8859-1")
+ * src = "\x00\xd8\x61\x00"
+ * dst = ""
+ * p ec.primitive_convert(src, dst) #=> :invalid_byte_sequence
+ * p ec.primitive_errinfo #=> [:invalid_byte_sequence, "UTF-16LE", "UTF-8", "\x00\xD8", "a\x00"]
+ * p ec.putback #=> "a\x00"
+ * p ec.putback #=> "" # no more bytes to put back
+ *
+ */
static VALUE
econv_putback(int argc, VALUE *argv, VALUE self)
{
@@ -2773,6 +2797,10 @@ econv_putback(int argc, VALUE *argv, VALUE self)
str = rb_str_new(NULL, n);
rb_econv_putback(ec, (unsigned char *)RSTRING_PTR(str), n);
+ if (ec->source_encoding) {
+ rb_enc_associate(str, ec->source_encoding);
+ }
+
return str;
}