mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* transcode.c (econv_primitive_putback): new method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18671 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0051d4a077
commit
128abaede6
3 changed files with 40 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
|||
Sun Aug 17 13:40:04 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* transcode.c (econv_primitive_putback): new method.
|
||||
|
||||
Sun Aug 17 13:23:53 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* include/ruby/encoding.h (rb_econv_putbackable): declared.
|
||||
|
|
|
@ -415,4 +415,16 @@ class TestEncodingConverter < Test::Unit::TestCase
|
|||
assert_equal("\u{3042}", err.error_char)
|
||||
end
|
||||
|
||||
def test_putback
|
||||
ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
|
||||
ret = ec.primitive_convert(src="abc\xa1def", dst="", nil, 10)
|
||||
assert_equal(:invalid_byte_sequence, ret)
|
||||
assert_equal(["abc", "ef"], [dst, src])
|
||||
src = ec.primitive_putback(nil) + src
|
||||
assert_equal(["abc", "def"], [dst, src])
|
||||
ret = ec.primitive_convert(src, dst, nil, 10)
|
||||
assert_equal(:finished, ret)
|
||||
assert_equal(["abcdef", ""], [dst, src])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
24
transcode.c
24
transcode.c
|
@ -2096,6 +2096,29 @@ econv_primitive_insert_output(VALUE self, VALUE string)
|
|||
return Qtrue;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
econv_primitive_putback(VALUE self, VALUE max)
|
||||
{
|
||||
rb_econv_t *ec = check_econv(self);
|
||||
int n;
|
||||
int putbackable;
|
||||
VALUE str;
|
||||
|
||||
if (NIL_P(max))
|
||||
n = rb_econv_putbackable(ec);
|
||||
else {
|
||||
n = NUM2INT(max);
|
||||
putbackable = rb_econv_putbackable(ec);
|
||||
if (putbackable < n)
|
||||
n = putbackable;
|
||||
}
|
||||
|
||||
str = rb_str_new(NULL, n);
|
||||
rb_econv_putback(ec, (unsigned char *)RSTRING_PTR(str), n);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
void
|
||||
rb_econv_check_error(rb_econv_t *ec)
|
||||
{
|
||||
|
@ -2156,6 +2179,7 @@ Init_transcode(void)
|
|||
rb_define_method(rb_cEncodingConverter, "primitive_convert", econv_primitive_convert, -1);
|
||||
rb_define_method(rb_cEncodingConverter, "primitive_errinfo", econv_primitive_errinfo, 0);
|
||||
rb_define_method(rb_cEncodingConverter, "primitive_insert_output", econv_primitive_insert_output, 1);
|
||||
rb_define_method(rb_cEncodingConverter, "primitive_putback", econv_primitive_putback, 1);
|
||||
rb_define_const(rb_cEncodingConverter, "PARTIAL_INPUT", INT2FIX(ECONV_PARTIAL_INPUT));
|
||||
rb_define_const(rb_cEncodingConverter, "OUTPUT_FOLLOWED_BY_INPUT", INT2FIX(ECONV_OUTPUT_FOLLOWED_BY_INPUT));
|
||||
rb_define_const(rb_cEncodingConverter, "UNIVERSAL_NEWLINE_DECODER", INT2FIX(ECONV_UNIVERSAL_NEWLINE_DECODER));
|
||||
|
|
Loading…
Reference in a new issue