diff --git a/src/framework/stdext/format.h b/src/framework/stdext/format.h index 3002a46e..60471ac3 100644 --- a/src/framework/stdext/format.h +++ b/src/framework/stdext/format.h @@ -40,7 +40,7 @@ template void print_ostream(std::ostringstream& stream, const T& first, const Args&... rest) { stream << "\t" << first; print_ostream(stream, rest...); } template -/// Utility for printing variables just like lua +// Utility for printing variables just like lua void print(const T&... args) { std::ostringstream buf; print_ostream(buf, args...); std::cout << buf.str() << std::endl; } template @@ -58,14 +58,27 @@ template<> struct expand_snprintf<0> { template static int call(char *s, size_t maxlen, const char *format, const Tuple& tuple, const Args&... args) { return snprintf(s, maxlen, format, args...); }}; -/// Improved snprintf that accepts std::string and other types +// Improved snprintf that accepts std::string and other types template int snprintf(char *s, size_t maxlen, const char *format, const Args&... args) { std::tuple::type...> tuple(args...); return expand_snprintf::value>::call(s, maxlen, format, tuple); } -/// Format strings with the sprintf style, accepting std::string and string convertible types for %s +template +inline int snprintf(char *s, size_t maxlen, const char *format) { + std::strncpy(s, format, maxlen); + s[maxlen-1] = 0; + return strlen(s); +} + +template +inline std::string format() { return std::string(); } + +template +inline std::string format(const std::string& format) { return format; } + +// Format strings with the sprintf style, accepting std::string and string convertible types for %s template std::string format(const std::string& format, const Args&... args) { int n, size = 1024;