diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-28 17:13:49 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-28 17:13:49 +0000 |
commit | 3811bb53bdc604ec6abe1252787c3fb381a711d6 (patch) | |
tree | a4b78cdd67db724a935501dd5473e7cd94fa6348 /transcode.c | |
parent | 63846d48a9b2044ad2fb3062ca8551de078d3508 (diff) | |
download | ruby-3811bb53bdc604ec6abe1252787c3fb381a711d6.tar.gz |
* transcode.c (econv_primitive_convert): accept nil as input for empty
input.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'transcode.c')
-rw-r--r-- | transcode.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/transcode.c b/transcode.c index 861c285eed..c6f7b73e6a 100644 --- a/transcode.c +++ b/transcode.c @@ -2339,8 +2339,13 @@ econv_result_to_symbol(rb_econv_result_t res) * * primitive_convert converts source_buffer into destination_buffer. * - * source_buffer and destination_buffer should be a string. + * source_buffer should be a string or nil. + * nil means a empty string. + * + * adestination_buffer should be a string. + * * destination_byteoffset should be an integer or nil. + * * destination_bytesize and flags should be an integer. * * primitive_convert convert the content of source_buffer from beginning @@ -2415,7 +2420,8 @@ econv_primitive_convert(int argc, VALUE *argv, VALUE self) flags = NUM2INT(flags_v); StringValue(output); - StringValue(input); + if (!NIL_P(input)) + StringValue(input); rb_str_modify(output); if (output_byteoffset_v == Qnil) @@ -2440,15 +2446,21 @@ econv_primitive_convert(int argc, VALUE *argv, VALUE self) if (rb_str_capacity(output) < output_byteend) rb_str_resize(output, output_byteend); - ip = (const unsigned char *)RSTRING_PTR(input); - is = ip + RSTRING_LEN(input); + if (NIL_P(input)) { + ip = is = NULL; + } + else { + ip = (const unsigned char *)RSTRING_PTR(input); + is = ip + RSTRING_LEN(input); + } op = (unsigned char *)RSTRING_PTR(output) + output_byteoffset; os = op + output_bytesize; res = rb_econv_convert(ec, &ip, is, &op, os, flags); rb_str_set_len(output, op-(unsigned char *)RSTRING_PTR(output)); - rb_str_drop_bytes(input, ip - (unsigned char *)RSTRING_PTR(input)); + if (!NIL_P(input)) + rb_str_drop_bytes(input, ip - (unsigned char *)RSTRING_PTR(input)); if (ec->destination_encoding) { rb_enc_associate(output, ec->destination_encoding); |