Skip to content

Commit

Permalink
Merge pull request #6673 from BBasile/issue-18838
Browse files Browse the repository at this point in the history
fix issue 18838 - Formatting the number zero with separator doesn't obey width specifier
merged-on-behalf-of: Nathan Sashihara <n8sh@users.noreply.github.com>
  • Loading branch information
dlang-bot committed Aug 19, 2018
2 parents daeea66 + 6b6d5c1 commit a86b123
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion std/format.d
Expand Up @@ -2356,13 +2356,14 @@ private void formatUnsigned(Writer, T, Char)
size_t leftpad = 0;
size_t rightpad = 0;

immutable size_t dlen = digits.length == 0 ? 0 : digits.length - 1;
immutable ptrdiff_t spacesToPrint =
fs.width - (
(prefix1 != 0)
+ (prefix2 != 0)
+ zerofill
+ digits.length
+ ((fs.flSeparator != 0) * ((digits.length - 1) / fs.separators))
+ ((fs.flSeparator != 0) * (dlen / fs.separators))
);
if (spacesToPrint > 0) // need to do some padding
{
Expand Down Expand Up @@ -2429,6 +2430,11 @@ private void formatUnsigned(Writer, T, Char)
put(w, ' ');
}

@safe pure unittest // bugzilla 18838
{
assert("%12,d".format(0) == " 0");
}

@safe pure unittest
{
assert(collectExceptionMsg!FormatException(format("%c", 5)).back == 'c');
Expand Down

0 comments on commit a86b123

Please sign in to comment.