diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | sprintf.c | 25 |
2 files changed, 22 insertions, 8 deletions
@@ -1,3 +1,8 @@ +Sun Jan 27 22:33:39 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * sprintf.c (rb_str_format): fix for octal with precision. + [ruby-dev:33411] + Sun Jan 27 22:31:45 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> * misc/ruby-mode.el (ruby-mode-set-encoding): automatically insert @@ -535,9 +535,6 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) case 'B': prefix = "0B"; break; } - if (prefix) { - width -= strlen(prefix); - } } bin_retry: @@ -687,15 +684,27 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) 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 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) } } if (sc) PUSH(&sc, 1); - if (prefix && (prefix[1] || !(dots || (len && s[0] == '0')))) { + if (prefix) { int plen = strlen(prefix); PUSH(prefix, plen); } |