diff options
Diffstat (limited to 'include/mbgl/util/string.hpp')
-rw-r--r-- | include/mbgl/util/string.hpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/include/mbgl/util/string.hpp b/include/mbgl/util/string.hpp new file mode 100644 index 0000000000..f17d55cec3 --- /dev/null +++ b/include/mbgl/util/string.hpp @@ -0,0 +1,24 @@ +#ifndef MBGL_UTIL_STRING +#define MBGL_UTIL_STRING + +#include <string> + +namespace mbgl { +namespace util { + +template<size_t max, typename... Args> +inline std::string sprintf(const char *msg, Args... args) { + char res[max]; + int len = snprintf(res, sizeof(res), msg, args...); + return std::string(res, len); +} + +template<size_t max, typename... Args> +inline std::string sprintf(const std::string &msg, Args... args) { + return sprintf<max>(msg.c_str(), args...); +} + +} +} + +#endif |