* transcode.c (econv_init): accept Encoding object as source_encoding
and destination_encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18623 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d46728ec0e
commit
a6daaf16b0
@ -1,3 +1,8 @@
|
||||
Thu Aug 14 21:34:41 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* transcode.c (econv_init): accept Encoding object as source_encoding
|
||||
and destination_encoding.
|
||||
|
||||
Thu Aug 14 21:10:00 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* encoding.c (rb_filesystem_encoding): use default external encoding
|
||||
|
@ -20,6 +20,11 @@ class TestEncodingConverter < Test::Unit::TestCase
|
||||
[o, ret, i])
|
||||
end
|
||||
|
||||
def test_new
|
||||
assert_kind_of(Encoding::Converter, Encoding::Converter.new("UTF-8", "EUC-JP"))
|
||||
assert_kind_of(Encoding::Converter, Encoding::Converter.new(Encoding::UTF_8, Encoding::EUC_JP))
|
||||
end
|
||||
|
||||
def test_output_region
|
||||
ec = Encoding::Converter.new("UTF-8", "EUC-JP")
|
||||
ec.primitive_convert(src="a", dst="b", nil, 1, Encoding::Converter::PARTIAL_INPUT)
|
||||
|
40
transcode.c
40
transcode.c
@ -1412,33 +1412,49 @@ econv_s_allocate(VALUE klass)
|
||||
static VALUE
|
||||
econv_init(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE from_encoding, to_encoding, flags_v;
|
||||
const char *from_e, *to_e;
|
||||
rb_econv_t *ts;
|
||||
VALUE source_encoding, destination_encoding, flags_v;
|
||||
rb_encoding *senc, *denc;
|
||||
const char *sname, *dname;
|
||||
rb_econv_t *ec;
|
||||
int flags;
|
||||
|
||||
rb_scan_args(argc, argv, "21", &from_encoding, &to_encoding, &flags_v);
|
||||
rb_scan_args(argc, argv, "21", &source_encoding, &destination_encoding, &flags_v);
|
||||
|
||||
StringValue(from_encoding);
|
||||
StringValue(to_encoding);
|
||||
if (flags_v == Qnil)
|
||||
flags = 0;
|
||||
else
|
||||
flags = NUM2INT(flags_v);
|
||||
|
||||
from_e = RSTRING_PTR(from_encoding);
|
||||
to_e = RSTRING_PTR(to_encoding);
|
||||
senc = NULL;
|
||||
if (TYPE(source_encoding) != T_STRING) {
|
||||
senc = rb_to_encoding(source_encoding);
|
||||
}
|
||||
|
||||
denc = NULL;
|
||||
if (TYPE(destination_encoding) != T_STRING) {
|
||||
denc = rb_to_encoding(destination_encoding);
|
||||
}
|
||||
|
||||
if (senc)
|
||||
sname = senc->name;
|
||||
else
|
||||
sname = RSTRING_PTR(source_encoding);
|
||||
|
||||
if (denc)
|
||||
dname = denc->name;
|
||||
else
|
||||
dname = RSTRING_PTR(destination_encoding);
|
||||
|
||||
if (DATA_PTR(self)) {
|
||||
rb_raise(rb_eTypeError, "already initialized");
|
||||
}
|
||||
|
||||
ts = rb_econv_open(from_e, to_e, flags);
|
||||
if (!ts) {
|
||||
rb_raise(rb_eArgError, "encoding convewrter not supported (from %s to %s)", from_e, to_e);
|
||||
ec = rb_econv_open(sname, dname, flags);
|
||||
if (!ec) {
|
||||
rb_raise(rb_eArgError, "encoding convewrter not supported (from %s to %s)", sname, dname);
|
||||
}
|
||||
|
||||
DATA_PTR(self) = ts;
|
||||
DATA_PTR(self) = ec;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user