[macruby-changes] [4949] MacRuby/trunk/sprintf.c

source_changes at macosforge.org source_changes at macosforge.org
Fri Nov 26 02:34:54 PST 2010


Revision: 4949
          http://trac.macosforge.org/projects/ruby/changeset/4949
Author:   watson1978 at gmail.com
Date:     2010-11-26 02:34:50 -0800 (Fri, 26 Nov 2010)
Log Message:
-----------
sprintf() will be given the positional arguments and precision tokens given for one format.

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

assert_equal("0", sprintf("%2$1d", 1, 0))
assert_equal("001", sprintf("%2$03d", 0, 1))

assert_equal("0.00", sprintf("%2$.2f", 1, 0))
assert_equal("1.00", sprintf("%2$.2f", 0, 1))

assert_raise(ArgumentError){ sprintf("%1$<key>s", :key => "value") }
assert_raise(ArgumentError){ sprintf("%5d %<key>s", 10, :key => "value") }

puts :ok
}}}

Modified Paths:
--------------
    MacRuby/trunk/sprintf.c

Modified: MacRuby/trunk/sprintf.c
===================================================================
--- MacRuby/trunk/sprintf.c	2010-11-26 04:34:44 UTC (rev 4948)
+++ MacRuby/trunk/sprintf.c	2010-11-26 10:34:50 UTC (rev 4949)
@@ -322,7 +322,7 @@
     ((type) == REL_REF ? "relative" : (type) == ABS_REF ? "absolute" : "named")
 
 #define SET_REF_TYPE(type) \
-    if (ref_type != 0 && (type) != ref_type) { \
+    if (arg == 0 && ref_type != 0 && (type) != ref_type) { \
 	rb_raise(rb_eArgError, "can't mix %s references with %s references", \
 		REF_NAME(type), REF_NAME(ref_type)); \
     } \
@@ -615,6 +615,9 @@
 		    if (named_flag) {
 			rb_raise(rb_eArgError, "named given twice");
 		    }
+		    if (ref_type != 0) {
+			rb_raise(rb_eArgError, "named after numbered");
+		    }
 		    named_flag = true;
 		    SET_REF_TYPE(NAMED_REF);
 		    arg = get_named_arg(format_str, format_len, &i,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101126/1f95c52b/attachment-0001.html>


More information about the macruby-changes mailing list