ruby-changes:3914
From: ko1@a...
Date: Fri, 8 Feb 2008 19:20:38 +0900 (JST)
Subject: [ruby-changes:3914] nobu - Ruby:r15404 (trunk): * ext/iconv/iconv.c (iconv_convert): added toidx argument to set
nobu 2008-02-08 19:19:57 +0900 (Fri, 08 Feb 2008) New Revision: 15404 Modified files: trunk/ChangeLog trunk/ext/iconv/iconv.c Log: * ext/iconv/iconv.c (iconv_convert): added toidx argument to set encoding of successfully converted string. [ruby-dev:33221] http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ext/iconv/iconv.c?r1=15404&r2=15403&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15404&r2=15403&diff_format=u Index: ChangeLog =================================================================== --- ChangeLog (revision 15403) +++ ChangeLog (revision 15404) @@ -1,3 +1,8 @@ +Fri Feb 8 19:19:55 2008 Nobuyoshi Nakada <nobu@r...> + + * ext/iconv/iconv.c (iconv_convert): added toidx argument to set + encoding of successfully converted string. [ruby-dev:33221] + Fri Feb 8 15:09:21 2008 Nobuyoshi Nakada <nobu@r...> * lib/mkmf.rb (xsystem): expand macros like as make. Index: ext/iconv/iconv.c =================================================================== --- ext/iconv/iconv.c (revision 15403) +++ ext/iconv/iconv.c (revision 15404) @@ -110,7 +110,8 @@ static VALUE iconv_free _((VALUE cd)); static VALUE iconv_try _((iconv_t cd, const char **inptr, size_t *inlen, char **outptr, size_t *outlen)); static VALUE rb_str_derive _((VALUE str, const char* ptr, int len)); -static VALUE iconv_convert _((iconv_t cd, VALUE str, int start, int length, struct iconv_env_t* env)); +static VALUE iconv_convert _((iconv_t cd, VALUE str, int start, int length, int toidx, + struct iconv_env_t* env)); static VALUE iconv_s_allocate _((VALUE klass)); static VALUE iconv_initialize _((int argc, VALUE *argv, VALUE self)); static VALUE iconv_s_open _((int argc, VALUE *argv, VALUE self)); @@ -129,7 +130,8 @@ * * Returns the map from canonical name to system dependent name. */ -static VALUE charset_map_get(void) +static VALUE +charset_map_get(void) { return charset_map; } @@ -270,7 +272,8 @@ #define FAILED_MAXLEN 16 -static VALUE iconv_failure_initialize(VALUE error, VALUE mesg, VALUE success, VALUE failed) +static VALUE +iconv_failure_initialize(VALUE error, VALUE mesg, VALUE success, VALUE failed) { rb_call_super(1, &mesg); rb_ivar_set(error, rb_success, success); @@ -324,7 +327,7 @@ } static VALUE -iconv_convert(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t* env) +iconv_convert(iconv_t cd, VALUE str, int start, int length, int toidx, struct iconv_env_t* env) { VALUE ret = Qfalse; VALUE error = Qfalse; @@ -335,13 +338,10 @@ char buffer[BUFSIZ]; char *outptr; size_t outlen; - int toidx = -1; if (cd == (iconv_t)-1) rb_raise(rb_eArgError, "closed iconv"); - if (env) toidx = env->toidx; - if (NIL_P(str)) { /* Reset output pointer or something. */ inptr = ""; @@ -614,12 +614,13 @@ VALUE last = 0; for (; env->argc > 0; --env->argc, ++env->argv) { - VALUE s = iconv_convert(env->cd, last = *(env->argv), 0, -1, env); + VALUE s = iconv_convert(env->cd, last = *(env->argv), + 0, -1, env->toidx, env); env->append(env->ret, s); } if (!NIL_P(last)) { - VALUE s = iconv_convert(env->cd, Qnil, 0, 0, env); + VALUE s = iconv_convert(env->cd, Qnil, 0, 0, env->toidx, env); if (RSTRING_LEN(s)) env->append(env->ret, s); } @@ -776,23 +777,20 @@ * its initial shift state. */ static VALUE -iconv_init_state(VALUE cd) +iconv_init_state(VALUE self) { - return iconv_convert(VALUE2ICONV(cd), Qnil, 0, 0, NULL); + iconv_t cd = VALUE2ICONV((VALUE)DATA_PTR(self)); + DATA_PTR(self) = NULL; + return iconv_convert(cd, Qnil, 0, 0, ENCODING_GET(self), NULL); } static VALUE iconv_finish(VALUE self) { VALUE cd = check_iconv(self); - VALUE str; if (!cd) return Qnil; - DATA_PTR(self) = NULL; - - str = rb_ensure(iconv_init_state, cd, iconv_free, cd); - ENCODING_SET(str, ENCODING_GET(self)); - return str; + return rb_ensure(iconv_init_state, self, iconv_free, cd); } /* @@ -834,8 +832,8 @@ str = iconv_convert(VALUE2ICONV(cd), str, NIL_P(n1) ? 0 : NUM2INT(n1), NIL_P(n2) ? -1 : NUM2INT(n2), + ENCODING_GET(self), NULL); - ENCODING_SET(str, ENCODING_GET(self)); return str; } @@ -852,16 +850,16 @@ { iconv_t cd = VALUE2ICONV(check_iconv(self)); VALUE str, s; + int toidx = ENCODING_GET(self); - str = iconv_convert(cd, Qnil, 0, 0, NULL); - ENCODING_SET(str, ENCODING_GET(self)); + str = iconv_convert(cd, Qnil, 0, 0, toidx, NULL); if (argc > 0) { do { - s = iconv_convert(cd, *argv++, 0, -1, NULL); + s = iconv_convert(cd, *argv++, 0, -1, toidx, NULL); if (RSTRING_LEN(s)) rb_str_buf_append(str, s); } while (--argc); - s = iconv_convert(cd, Qnil, 0, 0, NULL); + s = iconv_convert(cd, Qnil, 0, 0, toidx, NULL); if (RSTRING_LEN(s)) rb_str_buf_append(str, s); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/