ruby-changes:7292
From: akr <ko1@a...>
Date: Sun, 24 Aug 2008 16:20:36 +0900 (JST)
Subject: [ruby-changes:7292] Ruby:r18811 (trunk): * include/ruby/encoding.h (rb_econv_opts): declared.
akr 2008-08-24 16:20:21 +0900 (Sun, 24 Aug 2008) New Revision: 18811 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18811 Log: * include/ruby/encoding.h (rb_econv_opts): declared. * transcode.c (rb_econv_opts): defined. * io.c (rb_io_extract_modeenc): use rb_econv_opts. Modified files: trunk/ChangeLog trunk/include/ruby/encoding.h trunk/io.c trunk/transcode.c Index: include/ruby/encoding.h =================================================================== --- include/ruby/encoding.h (revision 18810) +++ include/ruby/encoding.h (revision 18811) @@ -253,6 +253,8 @@ int flags; } rb_econv_option_t; +void rb_econv_opts(VALUE hash, rb_econv_option_t *opts); + rb_econv_t *rb_econv_open(const char *source_encoding, const char *destination_encoding, rb_econv_option_t *opts); rb_econv_result_t rb_econv_convert(rb_econv_t *ec, const unsigned char **source_buffer_ptr, const unsigned char *source_buffer_end, Index: ChangeLog =================================================================== --- ChangeLog (revision 18810) +++ ChangeLog (revision 18811) @@ -1,3 +1,11 @@ +Sun Aug 24 16:19:25 2008 Tanaka Akira <akr@f...> + + * include/ruby/encoding.h (rb_econv_opts): declared. + + * transcode.c (rb_econv_opts): defined. + + * io.c (rb_io_extract_modeenc): use rb_econv_opts. + Sun Aug 24 16:06:30 2008 Tanaka Akira <akr@f...> * include/ruby/encoding.h (rb_econv_option_t): defined. Index: io.c =================================================================== --- io.c (revision 18810) +++ io.c (revision 18811) @@ -3850,8 +3850,8 @@ } typedef struct convconfig_t { - rb_encoding *enc; - rb_encoding *enc2; + rb_encoding *enc; + rb_encoding *enc2; } convconfig_t; static void @@ -3893,6 +3893,7 @@ if (!NIL_P(opthash)) { VALUE v; + rb_econv_option_t ecopts; v = rb_hash_aref(opthash, sym_textmode); if (RTEST(v)) flags |= FMODE_TEXTMODE; @@ -3903,32 +3904,11 @@ modenum |= O_BINARY; #endif } - v = rb_hash_aref(opthash, sym_invalid); - if (!NIL_P(v)) { - if (v == sym_replace) { - flags |= FMODE_INVALID_REPLACE; - } - else if (v == sym_ignore) { - flags |= FMODE_INVALID_IGNORE; - } - else { - v = rb_inspect(v); - rb_raise(rb_eArgError, "unexpected action for invalid byte sequence: %s", StringValueCStr(v)); - } - } - v = rb_hash_aref(opthash, sym_undef); - if (!NIL_P(v)) { - if (v == sym_replace) { - flags |= FMODE_UNDEF_REPLACE; - } - else if (v == sym_ignore) { - flags |= FMODE_UNDEF_IGNORE; - } - else { - v = rb_inspect(v); - rb_raise(rb_eArgError, "unexpected action for undefined conversion: %s", StringValueCStr(v)); - } - } + rb_econv_opts(opthash, &ecopts); + if (ecopts.flags & ECONV_INVALID_REPLACE) flags |= FMODE_INVALID_REPLACE; + if (ecopts.flags & ECONV_INVALID_IGNORE) flags |= FMODE_INVALID_IGNORE; + if (ecopts.flags & ECONV_UNDEF_REPLACE) flags |= FMODE_UNDEF_REPLACE; + if (ecopts.flags & ECONV_UNDEF_IGNORE) flags |= FMODE_UNDEF_IGNORE; if (io_extract_encoding_option(opthash, &enc, &enc2)) { if (has_enc) { Index: transcode.c =================================================================== --- transcode.c (revision 18810) +++ transcode.c (revision 18811) @@ -1711,6 +1711,12 @@ return options; } +void +rb_econv_opts(VALUE hash, rb_econv_option_t *opts) +{ + opts->flags = econv_opts(hash); +} + static int str_transcode_enc_args(VALUE str, VALUE arg1, VALUE arg2, const char **sname, rb_encoding **senc, -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/