mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
63846d48a9
commit
3811bb53bd
3 changed files with 28 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
|||
Fri Aug 29 02:11:46 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* transcode.c (econv_primitive_convert): accept nil as input for empty
|
||||
input.
|
||||
|
||||
Fri Aug 29 02:03:56 2008 Shugo Maeda <shugo@ruby-lang.org>
|
||||
|
||||
* strftime.c (rb_strftime): supported %s and %P.
|
||||
|
|
|
@ -79,6 +79,12 @@ class TestEncodingConverter < Test::Unit::TestCase
|
|||
}
|
||||
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)
|
||||
|
|
14
transcode.c
14
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,6 +2420,7 @@ econv_primitive_convert(int argc, VALUE *argv, VALUE self)
|
|||
flags = NUM2INT(flags_v);
|
||||
|
||||
StringValue(output);
|
||||
if (!NIL_P(input))
|
||||
StringValue(input);
|
||||
rb_str_modify(output);
|
||||
|
||||
|
@ -2440,14 +2446,20 @@ econv_primitive_convert(int argc, VALUE *argv, VALUE self)
|
|||
if (rb_str_capacity(output) < output_byteend)
|
||||
rb_str_resize(output, output_byteend);
|
||||
|
||||
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));
|
||||
if (!NIL_P(input))
|
||||
rb_str_drop_bytes(input, ip - (unsigned char *)RSTRING_PTR(input));
|
||||
|
||||
if (ec->destination_encoding) {
|
||||
|
|
Loading…
Reference in a new issue