mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* transcode.c (econv_putback): associate encoding to the result.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ca6a8b1e2c
commit
2d71485ec1
3 changed files with 34 additions and 2 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Sun Aug 31 16:57:36 2008 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* transcode.c (econv_putback): associate encoding to the result.
|
||||||
|
|
||||||
Sun Aug 31 16:43:56 2008 Koichi Sasada <ko1@atdot.net>
|
Sun Aug 31 16:43:56 2008 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* include/ruby/intern.h: rename RB_UBF_DFL to
|
* include/ruby/intern.h: rename RB_UBF_DFL to
|
||||||
|
|
|
@ -498,8 +498,8 @@ class TestEncodingConverter < Test::Unit::TestCase
|
||||||
ec = Encoding::Converter.new("utf-16le", "euc-jp")
|
ec = Encoding::Converter.new("utf-16le", "euc-jp")
|
||||||
ret = ec.primitive_convert(src="\x00\xd8\x21\x00", dst="", nil, nil)
|
ret = ec.primitive_convert(src="\x00\xd8\x21\x00", dst="", nil, nil)
|
||||||
assert_equal(:invalid_byte_sequence, ret)
|
assert_equal(:invalid_byte_sequence, ret)
|
||||||
assert_equal("\x00", ec.putback(1))
|
assert_equal("\x00".force_encoding("utf-16le"), ec.putback(1))
|
||||||
assert_equal("\x21", ec.putback(1))
|
assert_equal("\x21".force_encoding("utf-16le"), ec.putback(1))
|
||||||
assert_equal("", ec.putback(1))
|
assert_equal("", ec.putback(1))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
28
transcode.c
28
transcode.c
|
@ -2751,6 +2751,30 @@ econv_insert_output(VALUE self, VALUE string)
|
||||||
return Qnil;
|
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
|
static VALUE
|
||||||
econv_putback(int argc, VALUE *argv, VALUE self)
|
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);
|
str = rb_str_new(NULL, n);
|
||||||
rb_econv_putback(ec, (unsigned char *)RSTRING_PTR(str), n);
|
rb_econv_putback(ec, (unsigned char *)RSTRING_PTR(str), n);
|
||||||
|
|
||||||
|
if (ec->source_encoding) {
|
||||||
|
rb_enc_associate(str, ec->source_encoding);
|
||||||
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue