[前][次][番号順一覧][スレッド一覧]

ruby-changes:8804

From: shugo <ko1@a...>
Date: Mon, 24 Nov 2008 23:02:06 +0900 (JST)
Subject: [ruby-changes:8804] Ruby:r20340 (trunk): * strftime.c (rb_strftime): A width specifier for %t and %n should

shugo	2008-11-24 23:01:47 +0900 (Mon, 24 Nov 2008)

  New Revision: 20340

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20340

  Log:
    * strftime.c (rb_strftime): A width specifier for %t and %n should
      work.  [ruby-dev:37160]
    * test/ruby/test_time.rb (test_strftime): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/strftime.c
    trunk/test/ruby/test_time.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 20339)
+++ ChangeLog	(revision 20340)
@@ -1,3 +1,10 @@
+Mon Nov 24 22:57:25 2008  Shugo Maeda  <shugo@r...>
+
+	* strftime.c (rb_strftime): A width specifier for %t and %n should
+	  work.  [ruby-dev:37160]
+
+	* test/ruby/test_time.rb (test_strftime): ditto.
+
 Mon Nov 24 22:07:07 2008  Shugo Maeda  <shugo@r...>
 
 	* strftime.c (rb_strftime): The precision of %0N should be 9.
Index: strftime.c
===================================================================
--- strftime.c	(revision 20339)
+++ strftime.c	(revision 20340)
@@ -270,6 +270,16 @@
 				goto unknown; \
 		} while (0)
 #define NEEDS(n) do if (s + (n) >= endp - 1) goto err; while (0)
+#define FILL_PADDING(i) do { \
+	if (!(flags & BIT_OF(LEFT)) && precision > i) { \
+		NEEDS(precision); \
+		memset(s, padding ? padding : ' ', precision - i); \
+		s += precision - i; \
+	} \
+	else { \
+		NEEDS(i); \
+	} \
+} while (0);
 #define FMT(def_pad, def_prec, fmt, val) \
 		do { \
 			int l; \
@@ -540,12 +550,12 @@
 
 #ifdef SYSV_EXT
 		case 'n':	/* same as \n */
-			NEEDS(1);
+			FILL_PADDING(1);
 			*s++ = '\n';
 			continue;
 
 		case 't':	/* same as \t */
-			NEEDS(1);
+			FILL_PADDING(1);
 			*s++ = '\t';
 			continue;
 
@@ -741,14 +751,7 @@
 			break;
 		}
 		if (i) {
-			if (!(flags & BIT_OF(LEFT)) && precision > i) {
-				NEEDS(precision);
-				memset(s, padding ? padding : ' ', precision - i);
-				s += precision - i;
-			}
-			else {
-				NEEDS(i);
-			}
+			FILL_PADDING(i);
 			memcpy(s, tp, i);
 			switch (flags & (BIT_OF(UPPER)|BIT_OF(LOWER))) {
 			case BIT_OF(UPPER):
Index: test/ruby/test_time.rb
===================================================================
--- test/ruby/test_time.rb	(revision 20339)
+++ test/ruby/test_time.rb	(revision 20340)
@@ -449,5 +449,17 @@
     t = Time.mktime(1970, 1, 18)
     assert_equal("0", t.strftime("%w"))
     assert_equal("7", t.strftime("%u"))
+
+    # [ruby-dev:37160]
+    assert_equal("\t", T2000.strftime("%t"))
+    assert_equal("\t", T2000.strftime("%0t"))
+    assert_equal("\t", T2000.strftime("%1t"))
+    assert_equal("  \t", T2000.strftime("%3t"))
+    assert_equal("00\t", T2000.strftime("%03t"))
+    assert_equal("\n", T2000.strftime("%n"))
+    assert_equal("\n", T2000.strftime("%0n"))
+    assert_equal("\n", T2000.strftime("%1n"))
+    assert_equal("  \n", T2000.strftime("%3n"))
+    assert_equal("00\n", T2000.strftime("%03n"))
   end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]