summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-05 17:02:33 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-05 17:02:33 +0000
commitf2fd6d3b15541e0ea66942d79e2bd3458a83b66c (patch)
treefd4e1c5912625e66994fc39fcf86c1c1a88dca00
parent01acf1870403c8b925d06a0c188e52f1aedada03 (diff)
* 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
-rw-r--r--ChangeLog5
-rw-r--r--transcode.c43
2 files changed, 32 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index e394def40d..e4308a3639 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/transcode.c b/transcode.c
index 178ed02f44..6d9cd7ba5f 100644
--- a/transcode.c
+++ b/transcode.c
@@ -2102,6 +2102,30 @@ rb_econv_open_opts(const char *source_encoding, const char *destination_encoding
}
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 @@ 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;