diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-04 08:52:25 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-04 08:52:25 +0000 |
commit | 106e48e5d86d20a4a288fd432d973ed69874b6d5 () | |
tree | f0cd1f65d59b159bf5541ea48be202c4d1868756 | |
parent | 9812a3a49812af438ba15705933e7474f0d242b2 (diff) |
* ext/iconv/iconv.c (iconv_iconv): fix for length argument and now
allows range. [ruby-core:17092] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ext/iconv/iconv.c | 48 |
2 files changed, 33 insertions, 20 deletions
@@ -1,3 +1,8 @@ Wed Jun 4 15:45:41 2008 Akinori MUSHA <[email protected]> * enumerator.c (enumerator_with_index, enumerator_with_memo): Fix @@ -110,7 +110,7 @@ static void iconv_dfree _((void *cd)); 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, int toidx, struct iconv_env_t* env)); static VALUE iconv_s_allocate _((VALUE klass)); static VALUE iconv_initialize _((int argc, VALUE *argv, VALUE self)); @@ -327,7 +327,7 @@ rb_str_derive(VALUE str, const char* ptr, int len) } static VALUE -iconv_convert(iconv_t cd, VALUE str, int start, int length, int toidx, struct iconv_env_t* env) { VALUE ret = Qfalse; VALUE error = Qfalse; @@ -374,17 +374,9 @@ iconv_convert(iconv_t cd, VALUE str, int start, int length, int toidx, struct ic slen = RSTRING_LEN(str); inptr = RSTRING_PTR(str); - if (start < 0 ? (start += slen) < 0 : start >= slen) - length = 0; - else if (length < 0 && (length += slen + 1) < 0) - length = 0; - else if ((length -= start) < 0) - length = 0; - else { - inptr += start; - if (length > slen) - length = slen; - } } instart = inptr; inlen = length; @@ -828,16 +820,32 @@ iconv_iconv(int argc, VALUE *argv, VALUE self) { VALUE str, n1, n2; VALUE cd = check_iconv(self); n1 = n2 = Qnil; rb_scan_args(argc, argv, "12", &str, &n1, &n2); - str = iconv_convert(VALUE2ICONV(cd), str, - NIL_P(n1) ? 0 : NUM2INT(n1), - NIL_P(n2) ? -1 : NUM2INT(n2), - ENCODING_GET(self), - NULL); - return str; } /* @@ -1034,7 +1042,7 @@ iconv_failure_failed(VALUE self) static VALUE iconv_failure_inspect(VALUE self) { - char *cname = rb_class2name(CLASS_OF(self)); VALUE success = rb_attr_get(self, rb_success); VALUE failed = rb_attr_get(self, rb_failed); VALUE str = rb_str_buf_cat2(rb_str_new2("#<"), cname); |