* transcode.c (enc_arg): extracted from str_transcode_enc_args.

(str_transcode_enc_args): use enc_arg.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19154 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-09-05 17:02:33 +00:00
Родитель 01acf18704
Коммит f2fd6d3b15
2 изменённых файлов: 32 добавлений и 16 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Sat Sep 6 02:01:59 2008 Tanaka Akira <akr@fsij.org>
* 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@fsij.org>
* include/ruby/io.h (rb_io_modestr_fmode): renamed from

Просмотреть файл

@ -2101,6 +2101,30 @@ rb_econv_open_opts(const char *source_encoding, const char *destination_encoding
return ec;
}
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,
@ -2109,29 +2133,16 @@ str_transcode_enc_args(VALUE str, VALUE arg1, VALUE arg2,
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;