diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-12 22:43:17 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-12 22:43:17 +0000 |
commit | 9d4bb3b969799e314197c70b3e33223564258bc8 (patch) | |
tree | 519edd4816a66a773e785303b5cf8858fe6f7db4 /transcode.c | |
parent | 85c41f4fbcd58d3515a02d639f6e18b658c09034 (diff) | |
download | ruby-9d4bb3b969799e314197c70b3e33223564258bc8.tar.gz |
* transcode.c (rb_trans_conv): report last transcode_obuf_full.
(econv_max_output): new method Encoding::Converter#max_output.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18547 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'transcode.c')
-rw-r--r-- | transcode.c | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/transcode.c b/transcode.c index 5f361e7753..478b52ae53 100644 --- a/transcode.c +++ b/transcode.c @@ -749,7 +749,7 @@ rb_trans_conv(rb_trans_t *ts, int flags) { int i; - int start, err_index, no_error; + int start, err_index; unsigned char empty_buf; unsigned char *empty_ptr = &empty_buf; @@ -764,20 +764,11 @@ rb_trans_conv(rb_trans_t *ts, output_stop = empty_ptr; } - no_error = 1; err_index = -1; for (i = ts->num_trans-1; 0 <= i; i--) { - if (ts->elems[i].last_result == transcode_invalid_input || - ts->elems[i].last_result == transcode_undefined_conversion) { - if (no_error) { - /* last error */ - no_error = 0; - } - else { - /* second last error */ - err_index = i; - break; - } + if (ts->elems[i].last_result != transcode_ibuf_empty) { + err_index = i; + break; } } @@ -786,12 +777,14 @@ rb_trans_conv(rb_trans_t *ts, err_index = trans_sweep(ts, input_ptr, input_stop, output_ptr, output_stop, flags, start); } while (err_index != -1 && err_index != ts->num_trans-1); - if (err_index == ts->num_trans-1) - return ts->elems[ts->num_trans-1].last_result; - else if (start == 0) - return ts->elems[ts->num_trans-1].last_result; - else - return ts->elems[start-1].last_result; + for (i = ts->num_trans-1; 0 <= i; i--) { + if (ts->elems[i].last_result != transcode_ibuf_empty) { + rb_trans_result_t res = ts->elems[i].last_result; + ts->elems[i].last_result = transcode_ibuf_empty; + return res; + } + } + return transcode_ibuf_empty; } static void @@ -1303,6 +1296,16 @@ econv_primitive_convert(VALUE self, VALUE input, VALUE output, VALUE flags_v) } } +static VALUE +econv_max_output(VALUE self) +{ + rb_trans_t *ts = check_econv(self); + int n; + n = ts->elems[ts->num_trans-1].tc->transcoder->max_output; + + return INT2FIX(n); +} + void Init_transcode(void) { @@ -1323,5 +1326,6 @@ Init_transcode(void) rb_define_alloc_func(rb_cEncodingConverter, econv_s_allocate); rb_define_method(rb_cEncodingConverter, "initialize", econv_init, 2); rb_define_method(rb_cEncodingConverter, "primitive_convert", econv_primitive_convert, 3); + rb_define_method(rb_cEncodingConverter, "max_output", econv_max_output, 0); rb_define_const(rb_cEncodingConverter, "PARTIAL_INPUT", INT2FIX(PARTIAL_INPUT)); } |