Fix issue 19252: avoid ridiculous format length overestimate; dynamic-width strings should estimate width 0, not int.max

This commit is contained in:
Mathis Beer 2018-09-19 15:50:54 +02:00 committed by FeepingCreature
parent e80038b9d0
commit c156f4ad95

View file

@ -6321,8 +6321,11 @@ private size_t guessLength(Char, S)(S fmtString)
if (spec.width == spec.precision)
len += spec.width;
else if (spec.width > 0 && (spec.precision == spec.UNSPECIFIED || spec.width > spec.precision))
else if (spec.width > 0 && spec.width != spec.DYNAMIC &&
(spec.precision == spec.UNSPECIFIED || spec.width > spec.precision))
{
len += spec.width;
}
else if (spec.precision != spec.UNSPECIFIED && spec.precision > spec.width)
len += spec.precision;
}
@ -6345,6 +6348,7 @@ unittest
assert(guessLength!char("%2.4f") == 4);
assert(guessLength!char("%02d:%02d:%02d") == 8);
assert(guessLength!char("%0.2f") == 7);
assert(guessLength!char("%0*d") == 0);
}
/// ditto