ruby-changes:7633
From: akr <ko1@a...>
Date: Sat, 6 Sep 2008 02:02:53 +0900 (JST)
Subject: [ruby-changes:7633] Ruby:r19154 (trunk): * transcode.c (enc_arg): extracted from str_transcode_enc_args.
akr 2008-09-06 02:02:33 +0900 (Sat, 06 Sep 2008) New Revision: 19154 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19154 Log: * transcode.c (enc_arg): extracted from str_transcode_enc_args. (str_transcode_enc_args): use enc_arg. Modified files: trunk/ChangeLog trunk/transcode.c Index: ChangeLog =================================================================== --- ChangeLog (revision 19153) +++ ChangeLog (revision 19154) @@ -1,3 +1,8 @@ +Sat Sep 6 02:01:59 2008 Tanaka Akira <akr@f...> + + * transcode.c (enc_arg): extracted from str_transcode_enc_args. + (str_transcode_enc_args): use enc_arg. + Fri Sep 5 20:27:17 2008 Tanaka Akira <akr@f...> * include/ruby/io.h (rb_io_modestr_fmode): renamed from Index: transcode.c =================================================================== --- transcode.c (revision 19153) +++ transcode.c (revision 19154) @@ -2102,6 +2102,30 @@ } static int +enc_arg(VALUE arg, const char **name_p, rb_encoding **enc_p) +{ + rb_encoding *enc; + const char *n; + int encidx; + VALUE encval; + + if ((encidx = rb_to_encoding_index(encval = arg)) < 0) { + enc = NULL; + encidx = 0; + n = StringValueCStr(encval); + } + else { + enc = rb_enc_from_index(encidx); + n = rb_enc_name(enc); + } + + *name_p = n; + *enc_p = enc; + + return encidx; +} + +static int str_transcode_enc_args(VALUE str, VALUE arg1, VALUE arg2, const char **sname, rb_encoding **senc, const char **dname, rb_encoding **denc) @@ -2109,29 +2133,16 @@ rb_encoding *from_enc, *to_enc; const char *from_e, *to_e; int from_encidx, to_encidx; - VALUE from_encval, to_encval; - if ((to_encidx = rb_to_encoding_index(to_encval = arg1)) < 0) { - to_enc = 0; - to_encidx = 0; - to_e = StringValueCStr(to_encval); - } - else { - to_enc = rb_enc_from_index(to_encidx); - to_e = rb_enc_name(to_enc); - } + to_encidx = enc_arg(arg1, &to_e, &to_enc); + if (NIL_P(arg2)) { from_encidx = rb_enc_get_index(str); from_enc = rb_enc_from_index(from_encidx); from_e = rb_enc_name(from_enc); } - else if ((from_encidx = rb_to_encoding_index(from_encval = arg2)) < 0) { - from_enc = 0; - from_e = StringValueCStr(from_encval); - } else { - from_enc = rb_enc_from_index(from_encidx); - from_e = rb_enc_name(from_enc); + from_encidx = enc_arg(arg2, &from_e, &from_enc); } *sname = from_e; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/