Updated fmt_helper::pad2()

This commit is contained in:
gabime 2020-04-12 01:40:22 +03:00
parent 34244656a6
commit 7766bc25d1

View File

@ -39,21 +39,12 @@ inline unsigned int count_digits(T n)
inline void pad2(int n, memory_buf_t &dest) inline void pad2(int n, memory_buf_t &dest)
{ {
if (n > 99) if (n >= 0 && n < 100) // 0-99
{
append_int(n, dest);
}
else if (n > 9) // 10-99
{ {
dest.push_back(static_cast<char>('0' + n / 10)); dest.push_back(static_cast<char>('0' + n / 10));
dest.push_back(static_cast<char>('0' + n % 10)); dest.push_back(static_cast<char>('0' + n % 10));
} }
else if (n >= 0) // 0-9 else // unlikely, but just in case, let fmt deal with it
{
dest.push_back('0');
dest.push_back(static_cast<char>('0' + n));
}
else // negatives (unlikely, but just in case, let fmt deal with it)
{ {
fmt::format_to(dest, "{:02}", n); fmt::format_to(dest, "{:02}", n);
} }