Improved hex::format
This commit is contained in:
parent
379f77af48
commit
7f5a32a83b
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user