1
0
mirror of https://github.com/gabime/spdlog.git synced 2025-01-16 01:37:58 +00:00

Compare commits

...

4 Commits

Author SHA1 Message Date
Gabi Melman
34244656a6
Update test_fmt_helper.cpp 2020-04-11 21:09:48 +03:00
gabime
619849c793 fixed comment 2020-04-11 20:15:04 +03:00
gabime
927b2b3942 Fixed conversion warnings 2020-04-11 20:07:40 +03:00
gabime
76389e057f Optimize fmt_helper::pad3() 2020-04-11 19:50:19 +03:00
2 changed files with 20 additions and 1 deletions

View File

@ -73,7 +73,18 @@ inline void pad_uint(T n, unsigned int width, memory_buf_t &dest)
template<typename T>
inline void pad3(T n, memory_buf_t &dest)
{
pad_uint(n, 3, dest);
static_assert(std::is_unsigned<T>::value, "pad3 must get unsigned T");
if(n < 1000)
{
dest.push_back(static_cast<char>(n / 100 + '0'));
n = n % 100;
dest.push_back(static_cast<char>((n / 10) + '0'));
dest.push_back(static_cast<char>((n % 10) + '0'));
}
else
{
append_int(n, dest);
}
}
template<typename T>

View File

@ -36,7 +36,10 @@ TEST_CASE("pad2", "[fmt_helper]")
{
test_pad2(0, "00");
test_pad2(3, "03");
test_pad2(10, "10");
test_pad2(23, "23");
test_pad2(99, "99");
test_pad2(100, "100");
test_pad2(123, "123");
test_pad2(1234, "1234");
test_pad2(-5, "-5");
@ -46,8 +49,13 @@ TEST_CASE("pad3", "[fmt_helper]")
{
test_pad3(0, "000");
test_pad3(3, "003");
test_pad3(10, "010");
test_pad3(23, "023");
test_pad3(99, "099");
test_pad3(100, "100");
test_pad3(123, "123");
test_pad3(999, "999");
test_pad3(1000, "1000");
test_pad3(1234, "1234");
}