diff --git a/xo-object2/include/xo/object2/StringOps.hpp b/xo-object2/include/xo/object2/StringOps.hpp index 96d9da15..70441b4b 100644 --- a/xo-object2/include/xo/object2/StringOps.hpp +++ b/xo-object2/include/xo/object2/StringOps.hpp @@ -34,6 +34,13 @@ namespace xo { typename ASrcFacet = AGCObject> static obj clone(obj mm, obj src); + + /** wrapper for DString.printf() **/ + template + static obj printf(obj mm, + size_type cap, + const char * fmt, + Args&&... args); }; template @@ -56,6 +63,17 @@ namespace xo { { return obj(DString::clone(mm, src.data())); } + + template + obj + StringOps::printf(obj mm, + size_type cap, + const char * fmt, + Args&&... args) + { + return obj(DString::printf(mm, cap, fmt, + std::forward(args)...)); + } } } diff --git a/xo-object2/utest/StringOps.test.cpp b/xo-object2/utest/StringOps.test.cpp index 2fabb0ea..26464f90 100644 --- a/xo-object2/utest/StringOps.test.cpp +++ b/xo-object2/utest/StringOps.test.cpp @@ -81,6 +81,21 @@ namespace xo { REQUIRE(copy.data()->capacity() == src.data()->capacity()); REQUIRE(std::strcmp(copy.data()->chars(), src.data()->chars()) == 0); } + + TEST_CASE("StringOps-printf", "[object2][StringOps]") + { + ArenaConfig cfg { .name_ = "testarena", + .size_ = 4*1024 }; + DArena arena = DArena::map(cfg); + auto alloc = with_facet::mkobj(&arena); + + auto s = StringOps::printf(alloc, 32, "hello %s %d", "world", 42); + + REQUIRE(s.data() != nullptr); + REQUIRE(s.data()->capacity() == 32); + REQUIRE(s.data()->size() == 14); + REQUIRE(std::strcmp(s.data()->chars(), "hello world 42") == 0); + } } /*namespace ut*/ } /*namespace xo*/