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

ruby-changes:3789

From: ko1@a...
Date: Sun, 27 Jan 2008 22:33:52 +0900 (JST)
Subject: [ruby-changes:3789] nobu - Ruby:r15278 (trunk): * sprintf.c (rb_str_format): fix for octal with precision.

nobu	2008-01-27 22:33:41 +0900 (Sun, 27 Jan 2008)

  New Revision: 15278

  Modified files:
    trunk/ChangeLog
    trunk/sprintf.c

  Log:
    * sprintf.c (rb_str_format): fix for octal with precision.
      [ruby-dev:33411]


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15278&r2=15277&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/sprintf.c?r1=15278&r2=15277&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15277)
+++ ChangeLog	(revision 15278)
@@ -1,3 +1,8 @@
+Sun Jan 27 22:33:39 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* sprintf.c (rb_str_format): fix for octal with precision.
+	  [ruby-dev:33411]
+
 Sun Jan 27 22:31:45 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* misc/ruby-mode.el (ruby-mode-set-encoding): automatically insert
Index: sprintf.c
===================================================================
--- sprintf.c	(revision 15277)
+++ sprintf.c	(revision 15278)
@@ -535,9 +535,6 @@
 		      case 'B':
 			prefix = "0B"; break;
 		    }
-		    if (prefix) {
-			width -= strlen(prefix);
-		    }
 		}
 
 	      bin_retry:
@@ -687,15 +684,27 @@
 			pp++;
 		    }
 		}
+		if (prefix && !prefix[1]) {
+		    if (dots) {
+			prefix = 0;
+		    }
+		    else if (len == 1 && *s == '0') {
+			if (flags & FPREC) len = 0;
+			prefix = 0;
+		    }
+		    else if ((flags & FPREC) && (prec > len)) {
+			prefix = 0;
+		    }
+		}
+		if (prefix) {
+		    width -= strlen(prefix);
+		}
 		if ((flags&(FZERO|FPREC)) == FZERO) {
 		    prec = width;
 		    width = 0;
 		}
 		else {
-		    if (prec < len) {
-			if ((flags & FPREC) && len == 1 && *s == '0') len = 0;
-			else prec = len;
-		    }
+		    if (prec < len) prec = len;
 		    width -= prec;
 		}
 		if (!(flags&FMINUS)) {
@@ -705,7 +714,7 @@
 		    }
 		}
 		if (sc) PUSH(&sc, 1);
-		if (prefix && (prefix[1] || !(dots || (len && s[0] == '0')))) {
+		if (prefix) {
 		    int plen = strlen(prefix);
 		    PUSH(prefix, plen);
 		}

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

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