1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* transcode.c (str_transcode_enc_args): local variables renamed.

(str_transcode0): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-09-05 17:59:32 +00:00
parent e93289c03f
commit f0d9f949e8
2 changed files with 35 additions and 30 deletions

View file

@ -1,3 +1,8 @@
Sat Sep 6 02:58:53 2008 Tanaka Akira <akr@fsij.org>
* transcode.c (str_transcode_enc_args): local variables renamed.
(str_transcode0): ditto.
Sat Sep 6 02:23:18 2008 Tanaka Akira <akr@fsij.org> Sat Sep 6 02:23:18 2008 Tanaka Akira <akr@fsij.org>
* transcode.c (econv_s_stateless_encoding): new method. * transcode.c (econv_s_stateless_encoding): new method.

View file

@ -2127,29 +2127,29 @@ enc_arg(VALUE arg, const char **name_p, rb_encoding **enc_p)
static int static int
str_transcode_enc_args(VALUE str, VALUE arg1, VALUE arg2, str_transcode_enc_args(VALUE str, VALUE arg1, VALUE arg2,
const char **sname, rb_encoding **senc, const char **sname_p, rb_encoding **senc_p,
const char **dname, rb_encoding **denc) const char **dname_p, rb_encoding **denc_p)
{ {
rb_encoding *from_enc, *to_enc; rb_encoding *senc, *denc;
const char *from_e, *to_e; const char *sname, *dname;
int from_encidx, to_encidx; int sencidx, dencidx;
to_encidx = enc_arg(arg1, &to_e, &to_enc); dencidx = enc_arg(arg1, &dname, &denc);
if (NIL_P(arg2)) { if (NIL_P(arg2)) {
from_encidx = rb_enc_get_index(str); sencidx = rb_enc_get_index(str);
from_enc = rb_enc_from_index(from_encidx); senc = rb_enc_from_index(sencidx);
from_e = rb_enc_name(from_enc); sname = rb_enc_name(senc);
} }
else { else {
from_encidx = enc_arg(arg2, &from_e, &from_enc); sencidx = enc_arg(arg2, &sname, &senc);
} }
*sname = from_e; *sname_p = sname;
*senc = from_enc; *senc_p = senc;
*dname = to_e; *dname_p = dname;
*denc = to_enc; *denc_p = denc;
return to_encidx; return dencidx;
} }
static int static int
@ -2160,35 +2160,35 @@ str_transcode0(int argc, VALUE *argv, VALUE *self, int ecflags, VALUE ecopts)
long blen, slen; long blen, slen;
unsigned char *buf, *bp, *sp; unsigned char *buf, *bp, *sp;
const unsigned char *fromp; const unsigned char *fromp;
rb_encoding *from_enc, *to_enc; rb_encoding *senc, *denc;
const char *from_e, *to_e; const char *sname, *dname;
int to_encidx; int dencidx;
if (argc < 1 || argc > 2) { if (argc < 1 || argc > 2) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc); rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
} }
to_encidx = str_transcode_enc_args(str, argv[0], argc==1 ? Qnil : argv[1], &from_e, &from_enc, &to_e, &to_enc); dencidx = str_transcode_enc_args(str, argv[0], argc==1 ? Qnil : argv[1], &sname, &senc, &dname, &denc);
if ((ecflags & (ECONV_UNIVERSAL_NEWLINE_DECODER| if ((ecflags & (ECONV_UNIVERSAL_NEWLINE_DECODER|
ECONV_CRLF_NEWLINE_ENCODER| ECONV_CRLF_NEWLINE_ENCODER|
ECONV_CR_NEWLINE_ENCODER)) == 0) { ECONV_CR_NEWLINE_ENCODER)) == 0) {
if (from_enc && from_enc == to_enc) { if (senc && senc == denc) {
return -1; return -1;
} }
if (from_enc && to_enc && rb_enc_asciicompat(from_enc) && rb_enc_asciicompat(to_enc)) { if (senc && denc && rb_enc_asciicompat(senc) && rb_enc_asciicompat(denc)) {
if (ENC_CODERANGE(str) == ENC_CODERANGE_7BIT) { if (ENC_CODERANGE(str) == ENC_CODERANGE_7BIT) {
return to_encidx; return dencidx;
} }
} }
if (encoding_equal(from_e, to_e)) { if (encoding_equal(sname, dname)) {
return -1; return -1;
} }
} }
else { else {
if (encoding_equal(from_e, to_e)) { if (encoding_equal(sname, dname)) {
from_e = ""; sname = "";
to_e = ""; dname = "";
} }
} }
@ -2198,7 +2198,7 @@ str_transcode0(int argc, VALUE *argv, VALUE *self, int ecflags, VALUE ecopts)
dest = rb_str_tmp_new(blen); dest = rb_str_tmp_new(blen);
bp = (unsigned char *)RSTRING_PTR(dest); bp = (unsigned char *)RSTRING_PTR(dest);
transcode_loop(&fromp, &bp, (sp+slen), (bp+blen), dest, str_transcoding_resize, from_e, to_e, ecflags, ecopts); transcode_loop(&fromp, &bp, (sp+slen), (bp+blen), dest, str_transcoding_resize, sname, dname, ecflags, ecopts);
if (fromp != sp+slen) { if (fromp != sp+slen) {
rb_raise(rb_eArgError, "not fully converted, %"PRIdPTRDIFF" bytes left", sp+slen-fromp); rb_raise(rb_eArgError, "not fully converted, %"PRIdPTRDIFF" bytes left", sp+slen-fromp);
} }
@ -2207,12 +2207,12 @@ str_transcode0(int argc, VALUE *argv, VALUE *self, int ecflags, VALUE ecopts)
rb_str_set_len(dest, bp - buf); rb_str_set_len(dest, bp - buf);
/* set encoding */ /* set encoding */
if (!to_enc) { if (!denc) {
to_encidx = rb_define_dummy_encoding(to_e); dencidx = rb_define_dummy_encoding(dname);
} }
*self = dest; *self = dest;
return to_encidx; return dencidx;
} }
static int static int