[macruby-changes] [4946] MacRuby/trunk/sprintf.c
source_changes at macosforge.org
source_changes at macosforge.org
Thu Nov 25 17:50:23 PST 2010
Revision: 4946
http://trac.macosforge.org/projects/ruby/changeset/4946
Author: watson1978 at gmail.com
Date: 2010-11-25 17:50:19 -0800 (Thu, 25 Nov 2010)
Log Message:
-----------
fixed the bug of sprintf() within "%<named>" format
Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
assert_equal("value", sprintf("%<key>s", :key => "value"))
assert_equal("12345", sprintf("%<test>d", :test=> 12345))
puts :ok
}}}
Modified Paths:
--------------
MacRuby/trunk/sprintf.c
Modified: MacRuby/trunk/sprintf.c
===================================================================
--- MacRuby/trunk/sprintf.c 2010-11-24 20:32:36 UTC (rev 4945)
+++ MacRuby/trunk/sprintf.c 2010-11-26 01:50:19 UTC (rev 4946)
@@ -393,14 +393,16 @@
}
UChar closing = format_str[(*i)++] + 2;
UChar *str_ptr = &format_str[*i];
+ long length = 0;
while (*i < format_len && format_str[*i] != closing) {
(*i)++;
+ length++;
}
if (*i == format_len) {
rb_raise(rb_eArgError,
"malformed name - unmatched parenthesis");
}
- VALUE substr = rb_unicode_str_new(str_ptr, str_ptr - format_str);
+ VALUE substr = rb_unicode_str_new(str_ptr, (size_t)length);
hash = rb_hash_aref(hash, ID2SYM(rb_intern_str(substr)));
return hash;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101125/fc99deef/attachment.html>
More information about the macruby-changes
mailing list