1
0
mirror of synced 2024-11-12 02:00:52 +01:00

Improved hex::format

This commit is contained in:
WerWolv 2020-12-21 12:36:43 +01:00
parent 379f77af48
commit 7f5a32a83b

View File

@ -48,14 +48,14 @@ namespace hex {
namespace hex {
template<typename ... Args>
inline std::string format(const std::string &format, Args ... args) {
ssize_t size = snprintf( nullptr, 0, format.c_str(), args ... );
inline std::string format(const char *format, Args ... args) {
ssize_t size = snprintf( nullptr, 0, format, args ... );
if( size <= 0 )
if (size <= 0)
return "";
std::vector<char> buffer(size + 1, 0x00);
snprintf(buffer.data(), size + 1, format.c_str(), args ...);
snprintf(buffer.data(), size + 1, format, args ...);
return std::string(buffer.data(), buffer.data() + size);
}