From e81c7fba77b8a82dc832852482e40771fd5a2c27 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 14 Jan 2026 16:49:01 -0500 Subject: [PATCH] xo-object2: + DString::snprintf --- include/xo/object2/DString.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 **/ ///@{