* transcode.c (econv_init): don't create dummy encoding if
rb_econv_open is failed. (make_dummy_encoding): new function extracted from make_encoding. (make_encoding): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
51c7947bde
commit
520cd6d186
@ -1,3 +1,10 @@
|
|||||||
|
Fri Aug 15 09:03:54 2008 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* transcode.c (econv_init): don't create dummy encoding if
|
||||||
|
rb_econv_open is failed.
|
||||||
|
(make_dummy_encoding): new function extracted from make_encoding.
|
||||||
|
(make_encoding): removed.
|
||||||
|
|
||||||
Fri Aug 15 01:07:16 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
Fri Aug 15 01:07:16 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* common.mk ({$(srcdir)}.y.c): escape backslash.
|
* common.mk ({$(srcdir)}.y.c): escape backslash.
|
||||||
|
@ -25,6 +25,19 @@ class TestEncodingConverter < Test::Unit::TestCase
|
|||||||
assert_kind_of(Encoding::Converter, Encoding::Converter.new(Encoding::UTF_8, Encoding::EUC_JP))
|
assert_kind_of(Encoding::Converter, Encoding::Converter.new(Encoding::UTF_8, Encoding::EUC_JP))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_new_fail
|
||||||
|
name1 = "encoding-which-is-not-exist-1"
|
||||||
|
name2 = "encoding-which-is-not-exist-2"
|
||||||
|
|
||||||
|
assert_raise(ArgumentError) {
|
||||||
|
Encoding::Converter.new(name1, name2)
|
||||||
|
}
|
||||||
|
|
||||||
|
encoding_list = Encoding.list.map {|e| e.name }
|
||||||
|
assert(!encoding_list.include?(name1))
|
||||||
|
assert(!encoding_list.include?(name2))
|
||||||
|
end
|
||||||
|
|
||||||
def test_get_encoding
|
def test_get_encoding
|
||||||
ec = Encoding::Converter.new("UTF-8", "EUC-JP")
|
ec = Encoding::Converter.new("UTF-8", "EUC-JP")
|
||||||
assert_equal(Encoding::UTF_8, ec.source_encoding)
|
assert_equal(Encoding::UTF_8, ec.source_encoding)
|
||||||
|
43
transcode.c
43
transcode.c
@ -1413,16 +1413,12 @@ econv_s_allocate(VALUE klass)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static rb_encoding *
|
static rb_encoding *
|
||||||
make_encoding(VALUE encoding)
|
make_dummy_encoding(const char *name)
|
||||||
{
|
{
|
||||||
int idx = rb_to_encoding_index(encoding);
|
|
||||||
rb_encoding *enc;
|
rb_encoding *enc;
|
||||||
if (0 <= idx)
|
int idx;
|
||||||
|
idx = rb_define_dummy_encoding(name);
|
||||||
enc = rb_enc_from_index(idx);
|
enc = rb_enc_from_index(idx);
|
||||||
else {
|
|
||||||
idx = rb_define_dummy_encoding(StringValueCStr(encoding));
|
|
||||||
enc = rb_enc_from_index(idx);
|
|
||||||
}
|
|
||||||
return enc;
|
return enc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1458,6 +1454,8 @@ static VALUE
|
|||||||
econv_init(int argc, VALUE *argv, VALUE self)
|
econv_init(int argc, VALUE *argv, VALUE self)
|
||||||
{
|
{
|
||||||
VALUE source_encoding, destination_encoding, flags_v;
|
VALUE source_encoding, destination_encoding, flags_v;
|
||||||
|
int sidx, didx;
|
||||||
|
const char *sname, *dname;
|
||||||
rb_encoding *senc, *denc;
|
rb_encoding *senc, *denc;
|
||||||
rb_econv_t *ec;
|
rb_econv_t *ec;
|
||||||
int flags;
|
int flags;
|
||||||
@ -1469,18 +1467,41 @@ econv_init(int argc, VALUE *argv, VALUE self)
|
|||||||
else
|
else
|
||||||
flags = NUM2INT(flags_v);
|
flags = NUM2INT(flags_v);
|
||||||
|
|
||||||
senc = make_encoding(source_encoding);
|
senc = NULL;
|
||||||
denc = make_encoding(destination_encoding);
|
sidx = rb_to_encoding_index(source_encoding);
|
||||||
|
if (0 <= sidx) {
|
||||||
|
senc = rb_enc_from_index(sidx);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
StringValue(source_encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
denc = NULL;
|
||||||
|
didx = rb_to_encoding_index(destination_encoding);
|
||||||
|
if (0 <= didx) {
|
||||||
|
denc = rb_enc_from_index(didx);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
StringValue(destination_encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
sname = senc ? senc->name : StringValueCStr(source_encoding);
|
||||||
|
dname = denc ? denc->name : StringValueCStr(destination_encoding);
|
||||||
|
|
||||||
if (DATA_PTR(self)) {
|
if (DATA_PTR(self)) {
|
||||||
rb_raise(rb_eTypeError, "already initialized");
|
rb_raise(rb_eTypeError, "already initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
ec = rb_econv_open(senc->name, denc->name, flags);
|
ec = rb_econv_open(sname, dname, flags);
|
||||||
if (!ec) {
|
if (!ec) {
|
||||||
rb_raise(rb_eArgError, "encoding convewrter not supported (from %s to %s)", senc->name, denc->name);
|
rb_raise(rb_eArgError, "encoding convewrter not supported (from %s to %s)", sname, dname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!senc)
|
||||||
|
senc = make_dummy_encoding(sname);
|
||||||
|
if (!denc)
|
||||||
|
denc = make_dummy_encoding(dname);
|
||||||
|
|
||||||
ec->source_encoding = senc;
|
ec->source_encoding = senc;
|
||||||
ec->destination_encoding = denc;
|
ec->destination_encoding = denc;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user