Accept number format strings like "%i%%" (results in "30%" if i == 30).

Fallout from #17349
This commit is contained in:
Henrik Rydgård 2023-04-30 10:39:21 +02:00
parent fcb394398f
commit efa167e2b4

View file

@ -197,11 +197,16 @@ static bool IsValidNumberFormatString(const std::string &s) {
size_t percentCount = 0;
for (int i = 0; i < (int)s.size(); i++) {
if (s[i] == '%') {
percentCount++;
if (i < s.size() - 1) {
if (s[i] == 's')
if (s[i + 1] == 's')
return false;
if (s[i + 1] == '%') {
// Next is another % sign, so it's an escape to emit a % sign, which is fine.
i++;
continue;
}
}
percentCount++;
}
}
return percentCount == 1;