diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-31 07:43:19 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-31 07:43:19 +0000 |
commit | d427cf3af8dfc1af85e6e0f3a7d8a86dd7f2d35f (patch) | |
tree | 781d791cec0c28ed1147272f2efd9a7f45a116b9 /transcode.c | |
parent | 03b2fc9adf609e61550011f9de644209dd6ce021 (diff) | |
download | ruby-d427cf3af8dfc1af85e6e0f3a7d8a86dd7f2d35f.tar.gz |
* 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
Diffstat (limited to 'transcode.c')
-rw-r--r-- | transcode.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/transcode.c b/transcode.c index fb6bee7bba..429a0a4f7b 100644 --- a/transcode.c +++ b/transcode.c @@ -2711,6 +2711,25 @@ econv_primitive_errinfo(VALUE self) 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 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); ret = rb_econv_insert_output(ec, (const unsigned char *)RSTRING_PTR(string), RSTRING_LEN(string), insert_enc); - if (ret == -1) - return Qfalse; + if (ret == -1) { + rb_raise(rb_eArgError, "too big string"); + } - return Qtrue; + return Qnil; } static VALUE |