diff --git a/include/xo/object2/DString.hpp b/include/xo/object2/DString.hpp index b7be708..bf8f04f 100644 --- a/include/xo/object2/DString.hpp +++ b/include/xo/object2/DString.hpp @@ -81,6 +81,24 @@ namespace xo { DString * s2); #endif + /** create string using printf-style formatting. + * Use memory from allocator @p mm with capacity @p cap. + * Truncates if result exceeds capacity. + * @return pointer to newly created DString + **/ + template + static DString * snprintf(obj mm, + size_type cap, + const char * fmt, + Args&&... args) + { + DString * result = DString::empty(mm, cap); + if (result) { + result->sprintf(fmt, std::forward(args)...); + } + return result; + } + ///@} /** @defgroup dstring-access access methods **/ ///@{