summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-01 00:38:33 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-01 00:38:33 +0000
commit18e70b266f05faa7963c159842202e5c1ad4cc15 (patch)
tree5daeb4db319ee3792f293aa0257021478b4a1038 /sprintf.c
parent4e6e5a431641056c6554c79a288a4f4ec175ad96 (diff)
* sprintf.c (rb_str_format): "%#.0o" should keep prefix where
"%#.0x" should not. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15648 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/sprintf.c b/sprintf.c
index 0682c64..a100946 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -684,18 +684,21 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
pp++;
}
}
- if (prefix && !prefix[1]) {
+ if (prefix && !prefix[1]) { /* octal */
if (dots) {
prefix = 0;
}
else if (len == 1 && *s == '0') {
- if (flags & FPREC) len = 0;
- prefix = 0;
+ len = 0;
+ if (flags & FPREC) prec--;
}
else if ((flags & FPREC) && (prec > len)) {
prefix = 0;
}
}
+ else if (len == 1 && *s == '0') {
+ prefix = 0;
+ }
if (prefix) {
width -= strlen(prefix);
}
@@ -705,8 +708,8 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
}
else {
if (prec < len) {
- if ((flags & FPREC) && len == 1 && *s == '0') len = 0;
- else prec = len;
+ if (!prefix && prec == 0 && len == 1 && *s == '0') len = 0;
+ prec = len;
}
width -= prec;
}