diff options
Diffstat (limited to 'src/transcode.c')
| -rw-r--r-- | src/transcode.c | 93 |
1 files changed, 49 insertions, 44 deletions
diff --git a/src/transcode.c b/src/transcode.c index ae78f20d4..e9d9b01ef 100644 --- a/src/transcode.c +++ b/src/transcode.c @@ -579,10 +579,12 @@ transcode_restartable0(mrb_state *mrb, switch (mrb_fixnum(next_info) & 0x1F) { case NOMAP: { - const unsigned char *p = inchar_start; - writebuf_off = 0; - while (p < in_p) { - TRANSCODING_WRITEBUF(tc)[writebuf_off++] = (unsigned char)*p++; + { + const unsigned char *p = inchar_start; + writebuf_off = 0; + while (p < in_p) { + TRANSCODING_WRITEBUF(tc)[writebuf_off++] = (unsigned char)*p++; + } } writebuf_len = writebuf_off; writebuf_off = 0; @@ -2085,51 +2087,54 @@ make_econv_exception(mrb_state *mrb, mrb_econv_t *ec) mrb_value mesg, exc; if (ec->last_error.result == econv_invalid_byte_sequence || ec->last_error.result == econv_incomplete_input) { - const char *err = (const char *)ec->last_error.error_bytes_start; - size_t error_len = ec->last_error.error_bytes_len; - mrb_value bytes = mrb_str_new(mrb, err, error_len); - mrb_value dumped = mrb_str_dump(mrb, bytes); - size_t readagain_len = ec->last_error.readagain_len; - mrb_value bytes2 = mrb_nil_value(); - mrb_value dumped2; - int idx; - if (ec->last_error.result == econv_incomplete_input) { - mesg = mrb_sprintf(mrb, "incomplete %s on %s", - //StringValueCStr(dumped), - mrb_string_value_cstr(mrb, &dumped), - ec->last_error.source_encoding); - } - else if (readagain_len) { - bytes2 = mrb_str_new(mrb, err+error_len, readagain_len); - dumped2 = mrb_str_dump(mrb, bytes2); - mesg = mrb_sprintf(mrb, "%s followed by %s on %s", - //StringValueCStr(dumped), - mrb_string_value_cstr(mrb, &dumped), - //StringValueCStr(dumped2), - mrb_string_value_cstr(mrb, &dumped2), - ec->last_error.source_encoding); - } - else { - mesg = mrb_sprintf(mrb, "%s on %s", - //StringValueCStr(dumped), - mrb_string_value_cstr(mrb, &dumped), - ec->last_error.source_encoding); + { + const char *err = (const char *)ec->last_error.error_bytes_start; + size_t error_len = ec->last_error.error_bytes_len; + mrb_value bytes = mrb_str_new(mrb, err, error_len); + mrb_value dumped = mrb_str_dump(mrb, bytes); + size_t readagain_len = ec->last_error.readagain_len; + mrb_value bytes2 = mrb_nil_value(); + mrb_value dumped2; + if (ec->last_error.result == econv_incomplete_input) { + mesg = mrb_sprintf(mrb, "incomplete %s on %s", + //StringValueCStr(dumped), + mrb_string_value_cstr(mrb, &dumped), + ec->last_error.source_encoding); + } + else if (readagain_len) { + bytes2 = mrb_str_new(mrb, err+error_len, readagain_len); + dumped2 = mrb_str_dump(mrb, bytes2); + mesg = mrb_sprintf(mrb, "%s followed by %s on %s", + //StringValueCStr(dumped), + mrb_string_value_cstr(mrb, &dumped), + //StringValueCStr(dumped2), + mrb_string_value_cstr(mrb, &dumped2), + ec->last_error.source_encoding); + } + else { + mesg = mrb_sprintf(mrb, "%s on %s", + //StringValueCStr(dumped), + mrb_string_value_cstr(mrb, &dumped), + ec->last_error.source_encoding); + } + + exc = mrb_exc_new3(mrb, E_INVALIDBYTESEQUENCE_ERROR, mesg); + mrb_iv_set(mrb, exc, mrb_intern(mrb, "error_bytes"), bytes); + mrb_iv_set(mrb, exc, mrb_intern(mrb, "readagain_bytes"), bytes2); + mrb_iv_set(mrb, exc, mrb_intern(mrb, "incomplete_input"), ec->last_error.result == econv_incomplete_input ? mrb_true_value() : mrb_false_value()); } - exc = mrb_exc_new3(mrb, E_INVALIDBYTESEQUENCE_ERROR, mesg); - mrb_iv_set(mrb, exc, mrb_intern(mrb, "error_bytes"), bytes); - mrb_iv_set(mrb, exc, mrb_intern(mrb, "readagain_bytes"), bytes2); - mrb_iv_set(mrb, exc, mrb_intern(mrb, "incomplete_input"), ec->last_error.result == econv_incomplete_input ? mrb_true_value() : mrb_false_value()); - set_encs: mrb_iv_set(mrb, exc, mrb_intern(mrb, "source_encoding_name"), mrb_str_new2(mrb, ec->last_error.source_encoding)); mrb_iv_set(mrb, exc, mrb_intern(mrb, "destination_encoding_name"), mrb_str_new2(mrb, ec->last_error.destination_encoding)); - idx = mrb_enc_find_index(mrb, ec->last_error.source_encoding); - if (0 <= idx) - mrb_iv_set(mrb, exc, mrb_intern(mrb, "source_encoding"), mrb_enc_from_encoding(mrb, mrb_enc_from_index(mrb, idx))); - idx = mrb_enc_find_index(mrb, ec->last_error.destination_encoding); - if (0 <= idx) - mrb_iv_set(mrb, exc, mrb_intern(mrb, "destination_encoding"), mrb_enc_from_encoding(mrb, mrb_enc_from_index(mrb, idx))); + { + int idx = mrb_enc_find_index(mrb, ec->last_error.source_encoding); + if (0 <= idx) + mrb_iv_set(mrb, exc, mrb_intern(mrb, "source_encoding"), mrb_enc_from_encoding(mrb, mrb_enc_from_index(mrb, idx))); + idx = mrb_enc_find_index(mrb, ec->last_error.destination_encoding); + if (0 <= idx) + mrb_iv_set(mrb, exc, mrb_intern(mrb, "destination_encoding"), mrb_enc_from_encoding(mrb, mrb_enc_from_index(mrb, idx))); + } return exc; } if (ec->last_error.result == econv_undefined_conversion) { |
