ruby-changes:7391
From: akr <ko1@a...>
Date: Fri, 29 Aug 2008 02:16:55 +0900 (JST)
Subject: [ruby-changes:7391] Ruby:r18910 (trunk): * transcode.c (econv_primitive_convert): accept nil as input for empty
akr 2008-08-29 02:13:49 +0900 (Fri, 29 Aug 2008) New Revision: 18910 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18910 Log: * transcode.c (econv_primitive_convert): accept nil as input for empty input. Modified files: trunk/ChangeLog trunk/test/ruby/test_econv.rb trunk/transcode.c Index: ChangeLog =================================================================== --- ChangeLog (revision 18909) +++ ChangeLog (revision 18910) @@ -1,3 +1,8 @@ +Fri Aug 29 02:11:46 2008 Tanaka Akira <akr@f...> + + * transcode.c (econv_primitive_convert): accept nil as input for empty + input. + Fri Aug 29 02:03:56 2008 Shugo Maeda <shugo@r...> * strftime.c (rb_strftime): supported %s and %P. Index: test/ruby/test_econv.rb =================================================================== --- test/ruby/test_econv.rb (revision 18909) +++ test/ruby/test_econv.rb (revision 18910) @@ -79,6 +79,12 @@ } end + def test_nil_input + ec = Encoding::Converter.new("UTF-8", "EUC-JP") + ret = ec.primitive_convert(nil, dst="", nil, 10) + assert_equal(:finished, ret) + end + def test_partial_input ec = Encoding::Converter.new("UTF-8", "EUC-JP") ret = ec.primitive_convert(src="", dst="", nil, 10, Encoding::Converter::PARTIAL_INPUT) Index: transcode.c =================================================================== --- transcode.c (revision 18909) +++ transcode.c (revision 18910) @@ -2339,8 +2339,13 @@ * * 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 @@ 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 @@ 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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/