diff --git a/lib/jkqtcommon/jkqtpstringtools.cpp b/lib/jkqtcommon/jkqtpstringtools.cpp index f6f59a15f4..029f4ba71a 100644 --- a/lib/jkqtcommon/jkqtpstringtools.cpp +++ b/lib/jkqtcommon/jkqtpstringtools.cpp @@ -81,19 +81,10 @@ std::string jkqtp_tolower(const std::string& s){ return d; }; - std::string jkqtp_format(const std::string& templ, ...){ - va_list ap; - char buffer[4096]; - va_start (ap, templ); - vsnprintf(buffer, 4096, templ.c_str(), ap); - va_end (ap); - std::string ret(buffer); - return ret; -}; std::string jkqtp_bytestostr(double bytes){ - double data=bytes; + double data=bytes; std::string form="%.0lf"; std::string res=jkqtp_format(form,data); form="%.3lf"; diff --git a/lib/jkqtcommon/jkqtpstringtools.h b/lib/jkqtcommon/jkqtpstringtools.h index 3c8a5cec2c..0910a204f1 100644 --- a/lib/jkqtcommon/jkqtpstringtools.h +++ b/lib/jkqtcommon/jkqtpstringtools.h @@ -89,7 +89,42 @@ JKQTCOMMON_LIB_EXPORT std::string jkqtp_toupper(const std::string& s); /** \brief std::string wrapper around sprintf() * \ingroup jkqtptools_string */ -JKQTCOMMON_LIB_EXPORT std::string jkqtp_format(const std::string& templ, ...); +template +inline std::string jkqtp_format(const std::string& templ, T1 d1) { + char buffer[4096]; + snprintf(buffer, 4096, templ.c_str(), d1); + return std::string(buffer); +}; + +/** \brief std::string wrapper around sprintf() + * \ingroup jkqtptools_string + */ +template +inline std::string jkqtp_format(const std::string& templ, T1 d1, T2 d2) { + char buffer[4096]; + snprintf(buffer, 4096, templ.c_str(), d1, d2); + return std::string(buffer); +}; + +/** \brief std::string wrapper around sprintf() + * \ingroup jkqtptools_string + */ +template +inline std::string jkqtp_format(const std::string& templ, T1 d1, T2 d2, T3 d3) { + char buffer[4096]; + snprintf(buffer, 4096, templ.c_str(), d1, d2, d3); + return std::string(buffer); +}; + +/** \brief std::string wrapper around sprintf() + * \ingroup jkqtptools_string + */ +template +inline std::string jkqtp_format(const std::string& templ, T1 d1, T2 d2, T3 d3, T4 d4) { + char buffer[4096]; + snprintf(buffer, 4096, templ.c_str(), d1, d2, d3, d4); + return std::string(buffer); +}; /** \brief convert a number of bytes to a string, formatting e.g. 1024 as 1kB, ... * \ingroup jkqtptools_string