diff options
Diffstat (limited to 'src/utils/stringutils.h')
-rw-r--r-- | src/utils/stringutils.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 3af0bfa5..89d3d7e9 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -74,6 +74,17 @@ template<typename T> std::string toString(const T &arg) const char *ipToString(int address); /** + * A safe version of sprintf that returns a std::string of the result. + */ +std::string strprintf(char const *, ...) +#ifdef __GNUC__ + /* This attribute is nice: it even works through gettext invokation. For + example, gcc will complain that strprintf(_("%s"), 42) is ill-formed. */ + __attribute__((format(printf, 1, 2))) +#endif +; + +/** * Removes bad characters from a string * * @param str the string to remove the bad chars from |