From ae1b02a8da630762436d190355ed24ec0db0976e Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 24 Aug 2008 10:49:36 +0000 Subject: * include/ruby/encoding.h (rb_econv_t): use rb_econv_option_t. * transcode.c: follow the rb_econv_t change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ include/ruby/encoding.h | 10 +++++----- transcode.c | 19 +++++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 57ffcb55be..8cc73cd3cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Aug 24 19:48:46 2008 Tanaka Akira + + * include/ruby/encoding.h (rb_econv_t): use rb_econv_option_t. + + * transcode.c: follow the rb_econv_t change. + Sun Aug 24 19:40:13 2008 Tanaka Akira * io.c (rb_io_init_copy): copy encs. diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h index 9ad7d3b53a..55b5bde354 100644 --- a/include/ruby/encoding.h +++ b/include/ruby/encoding.h @@ -216,6 +216,11 @@ typedef struct { typedef struct { int flags; + /* replacement character, etc. */ +} rb_econv_option_t; + +typedef struct { + rb_econv_option_t opts; const char *source_encoding_name; const char *destination_encoding_name; @@ -247,11 +252,6 @@ typedef struct { rb_encoding *destination_encoding; } rb_econv_t; -typedef struct { - int flags; - /* replacement character, etc. */ -} rb_econv_option_t; - VALUE rb_str_transcode(VALUE str, VALUE to, rb_econv_option_t *ecopts); void rb_econv_opts(VALUE hash, rb_econv_option_t *opts); diff --git a/transcode.c b/transcode.c index 15755a07c8..c0133c20e8 100644 --- a/transcode.c +++ b/transcode.c @@ -677,7 +677,7 @@ rb_econv_open_by_transcoder_entries(int n, transcoder_entry_t **entries) } ec = ALLOC(rb_econv_t); - ec->flags = 0; + ec->opts.flags = 0; ec->source_encoding_name = NULL; ec->destination_encoding_name = NULL; ec->in_buf_start = NULL; @@ -783,7 +783,10 @@ rb_econv_open(const char *from, const char *to, rb_econv_option_t *opts) if (!ec) return NULL; - ec->flags = flags; + if (!opts) + ec->opts.flags = 0; + else + ec->opts = *opts; ec->source_encoding_name = from; ec->destination_encoding_name = to; @@ -1065,10 +1068,10 @@ resume: if (ret == econv_invalid_byte_sequence) { /* deal with invalid byte sequence */ /* todo: add more alternative behaviors */ - if (ec->flags&ECONV_INVALID_IGNORE) { + if (ec->opts.flags&ECONV_INVALID_IGNORE) { goto resume; } - else if (ec->flags&ECONV_INVALID_REPLACE) { + else if (ec->opts.flags&ECONV_INVALID_REPLACE) { if (output_replacement_character(ec) == 0) goto resume; } @@ -1078,10 +1081,10 @@ resume: /* valid character in source encoding * but no related character(s) in destination encoding */ /* todo: add more alternative behaviors */ - if (ec->flags&ECONV_UNDEF_IGNORE) { + if (ec->opts.flags&ECONV_UNDEF_IGNORE) { goto resume; } - else if (ec->flags&ECONV_UNDEF_REPLACE) { + else if (ec->opts.flags&ECONV_UNDEF_REPLACE) { if (output_replacement_character(ec) == 0) goto resume; } @@ -1391,7 +1394,7 @@ rb_econv_str_convert(rb_econv_t *ec, VALUE src, int flags) void rb_econv_binmode(rb_econv_t *ec) { - if (ec->flags & ECONV_UNIVERSAL_NEWLINE_DECODER) { + if (ec->opts.flags & ECONV_UNIVERSAL_NEWLINE_DECODER) { int i = ec->num_trans-1; rb_transcoding_close(ec->elems[i].tc); xfree(ec->elems[i].out_buf_start); @@ -1402,7 +1405,7 @@ rb_econv_binmode(rb_econv_t *ec) ec->elems[i].out_buf_end = NULL; ec->num_trans--; } - if (ec->flags & (ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER)) { + if (ec->opts.flags & (ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER)) { rb_transcoding_close(ec->elems[0].tc); xfree(ec->elems[0].out_buf_start); MEMMOVE(&ec->elems[0], &ec->elems[1], rb_econv_elem_t, ec->num_trans-1); -- cgit v1.2.3