[macruby-changes] [5170] MacRuby/trunk/sprintf.c
source_changes at macosforge.org
source_changes at macosforge.org
Sat Jan 15 06:21:25 PST 2011
Revision: 5170
http://trac.macosforge.org/projects/ruby/changeset/5170
Author: watson1978 at gmail.com
Date: 2011-01-15 06:21:18 -0800 (Sat, 15 Jan 2011)
Log Message:
-----------
Fixed the bug of sprintf with format "%# x".
Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
assert_equal(" 0x7b", sprintf("%# x", 123))
assert_equal("-0x7b", sprintf("%# x", -123))
assert_equal("0x..f85", sprintf("%#x", -123))
assert_equal("7b", sprintf("%x", 123))
assert_equal("0x7b", sprintf("%#x", 123))
assert_equal(" 7b", sprintf("% x", 123))
assert_equal("..ffff85", sprintf("%08x", -123))
puts :ok
}}}
Modified Paths:
--------------
MacRuby/trunk/sprintf.c
Modified: MacRuby/trunk/sprintf.c
===================================================================
--- MacRuby/trunk/sprintf.c 2011-01-15 08:46:14 UTC (rev 5169)
+++ MacRuby/trunk/sprintf.c 2011-01-15 14:21:18 UTC (rev 5170)
@@ -782,6 +782,7 @@
if (base != 0) {
bool sign_pad = false;
unsigned long num_index = 0;
+ unsigned long sharp_beg = 0;
VALUE zero_pad = rb_str_new2("0");
VALUE num = rb_Integer(arg);
@@ -793,6 +794,7 @@
}
if (IS_NEG(num)) {
num_index = 1;
+ sharp_beg = 1;
if (!sign_pad && negative_pad != 0) {
zero_pad = negative_pad;
num = rb_big_clone(num);
@@ -820,6 +822,7 @@
rb_str_update(arg, 0, num_index, negative_pad);
rb_str_update(arg, 0, 0, rb_str_new2(".."));
num_index = 2;
+ sharp_beg = 0;
}
if (precision_flag) {
pad_format_value(arg, num_index,
@@ -828,7 +831,7 @@
zero_pad);
}
if (sharp_flag && rb_cmpint(num, Qfalse, Qfalse) != 0) {
- rb_str_update(arg, sign_pad, 0, (VALUE)sharp_pad);
+ rb_str_update(arg, sharp_beg, 0, (VALUE)sharp_pad);
num_index += 2;
}
if (sign_pad && RBIGNUM_POSITIVE_P(num)) {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20110115/88ec6de9/attachment.html>
More information about the macruby-changes
mailing list