зеркало из https://github.com/github/ruby.git
* transcode.c (econv_insert_output): raise ArgumentError on failure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
03b2fc9adf
Коммит
d427cf3af8
|
@ -1,3 +1,7 @@
|
||||||
|
Sun Aug 31 16:42:23 2008 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* transcode.c (econv_insert_output): raise ArgumentError on failure.
|
||||||
|
|
||||||
Sun Aug 31 16:39:17 2008 Koichi Sasada <ko1@atdot.net>
|
Sun Aug 31 16:39:17 2008 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* bootstraptest/test_thread.rb: add a test.
|
* bootstraptest/test_thread.rb: add a test.
|
||||||
|
|
|
@ -424,20 +424,20 @@ class TestEncodingConverter < Test::Unit::TestCase
|
||||||
ec = Encoding::Converter.new("EUC-JP", "ISO-2022-JP")
|
ec = Encoding::Converter.new("EUC-JP", "ISO-2022-JP")
|
||||||
ec.primitive_convert(src="\xa1\xa1", dst="", nil, 10, Encoding::Converter::PARTIAL_INPUT)
|
ec.primitive_convert(src="\xa1\xa1", dst="", nil, 10, Encoding::Converter::PARTIAL_INPUT)
|
||||||
assert_equal("\e$B!!".force_encoding("ISO-2022-JP"), dst)
|
assert_equal("\e$B!!".force_encoding("ISO-2022-JP"), dst)
|
||||||
assert_equal(true, ec.insert_output("???"))
|
assert_equal(nil, ec.insert_output("???"))
|
||||||
ec.primitive_convert("", dst, nil, 10, Encoding::Converter::PARTIAL_INPUT)
|
ec.primitive_convert("", dst, nil, 10, Encoding::Converter::PARTIAL_INPUT)
|
||||||
assert_equal("\e$B!!\e(B???".force_encoding("ISO-2022-JP"), dst)
|
assert_equal("\e$B!!\e(B???".force_encoding("ISO-2022-JP"), dst)
|
||||||
ec.primitive_convert(src="\xa1\xa2", dst, nil, 10, Encoding::Converter::PARTIAL_INPUT)
|
ec.primitive_convert(src="\xa1\xa2", dst, nil, 10, Encoding::Converter::PARTIAL_INPUT)
|
||||||
assert_equal("\e$B!!\e(B???\e$B!\"".force_encoding("ISO-2022-JP"), dst)
|
assert_equal("\e$B!!\e(B???\e$B!\"".force_encoding("ISO-2022-JP"), dst)
|
||||||
|
|
||||||
assert_equal(true, ec.insert_output("\xA1\xA1".force_encoding("EUC-JP")))
|
assert_equal(nil, ec.insert_output("\xA1\xA1".force_encoding("EUC-JP")))
|
||||||
ec.primitive_convert("", dst, nil, 10, Encoding::Converter::PARTIAL_INPUT)
|
ec.primitive_convert("", dst, nil, 10, Encoding::Converter::PARTIAL_INPUT)
|
||||||
assert_equal("\e$B!!\e(B???\e$B!\"!!".force_encoding("ISO-2022-JP"), dst)
|
assert_equal("\e$B!!\e(B???\e$B!\"!!".force_encoding("ISO-2022-JP"), dst)
|
||||||
|
|
||||||
ec.primitive_convert(src="\xa1\xa3", dst, nil, 10, Encoding::Converter::PARTIAL_INPUT)
|
ec.primitive_convert(src="\xa1\xa3", dst, nil, 10, Encoding::Converter::PARTIAL_INPUT)
|
||||||
assert_equal("\e$B!!\e(B???\e$B!\"!!!\#".force_encoding("ISO-2022-JP"), dst)
|
assert_equal("\e$B!!\e(B???\e$B!\"!!!\#".force_encoding("ISO-2022-JP"), dst)
|
||||||
|
|
||||||
assert_equal(true, ec.insert_output("\u3042"))
|
assert_equal(nil, ec.insert_output("\u3042"))
|
||||||
ec.primitive_convert("", dst, nil, 10, Encoding::Converter::PARTIAL_INPUT)
|
ec.primitive_convert("", dst, nil, 10, Encoding::Converter::PARTIAL_INPUT)
|
||||||
assert_equal("\e$B!!\e(B???\e$B!\"!!!\#$\"".force_encoding("ISO-2022-JP"), dst)
|
assert_equal("\e$B!!\e(B???\e$B!\"!!!\#$\"".force_encoding("ISO-2022-JP"), dst)
|
||||||
|
|
||||||
|
|
26
transcode.c
26
transcode.c
|
@ -2711,6 +2711,25 @@ econv_primitive_errinfo(VALUE self)
|
||||||
return ary;
|
return ary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* insert_output(string) -> nil
|
||||||
|
*
|
||||||
|
* inserts string into the encoding converter.
|
||||||
|
* The string will be output on next conversion.
|
||||||
|
*
|
||||||
|
* This method should be used only when a conversion error is occur.
|
||||||
|
*
|
||||||
|
* ec = Encoding::Converter.new("utf-8", "iso-8859-1")
|
||||||
|
* src = "HIRAGANA LETTER A is \u{3042}."
|
||||||
|
* dst = ""
|
||||||
|
* p ec.primitive_convert(src, dst) #=> :undefined_conversion
|
||||||
|
* puts "[#{dst.dump}, #{src.dump}]" #=> ["HIRAGANA LETTER A is ", "."]
|
||||||
|
* ec.insert_output("<err>")
|
||||||
|
* p ec.primitive_convert(src, dst) #=> :finished
|
||||||
|
* puts "[#{dst.dump}, #{src.dump}]" #=> ["HIRAGANA LETTER A is <err>.", ""]
|
||||||
|
*
|
||||||
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
econv_insert_output(VALUE self, VALUE string)
|
econv_insert_output(VALUE self, VALUE string)
|
||||||
{
|
{
|
||||||
|
@ -2725,10 +2744,11 @@ econv_insert_output(VALUE self, VALUE string)
|
||||||
string = rb_str_transcode(string, rb_enc_from_encoding(rb_enc_find(insert_enc)), 0);
|
string = rb_str_transcode(string, rb_enc_from_encoding(rb_enc_find(insert_enc)), 0);
|
||||||
|
|
||||||
ret = rb_econv_insert_output(ec, (const unsigned char *)RSTRING_PTR(string), RSTRING_LEN(string), insert_enc);
|
ret = rb_econv_insert_output(ec, (const unsigned char *)RSTRING_PTR(string), RSTRING_LEN(string), insert_enc);
|
||||||
if (ret == -1)
|
if (ret == -1) {
|
||||||
return Qfalse;
|
rb_raise(rb_eArgError, "too big string");
|
||||||
|
}
|
||||||
|
|
||||||
return Qtrue;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
|
Загрузка…
Ссылка в новой задаче