xo-object2: + StringOps.printf() + utest
This commit is contained in:
parent
ede658219c
commit
aea37f2523
2 changed files with 33 additions and 0 deletions
|
|
@ -34,6 +34,13 @@ namespace xo {
|
|||
typename ASrcFacet = AGCObject>
|
||||
static obj<AFacet,DString> clone(obj<AAllocator> mm,
|
||||
obj<ASrcFacet,DString> src);
|
||||
|
||||
/** wrapper for DString.printf() **/
|
||||
template <typename AFacet = AGCObject, typename... Args>
|
||||
static obj<AFacet,DString> printf(obj<AAllocator> mm,
|
||||
size_type cap,
|
||||
const char * fmt,
|
||||
Args&&... args);
|
||||
};
|
||||
|
||||
template <typename AFacet>
|
||||
|
|
@ -56,6 +63,17 @@ namespace xo {
|
|||
{
|
||||
return obj<AFacet,DString>(DString::clone(mm, src.data()));
|
||||
}
|
||||
|
||||
template <typename AFacet, typename... Args>
|
||||
obj<AFacet,DString>
|
||||
StringOps::printf(obj<AAllocator> mm,
|
||||
size_type cap,
|
||||
const char * fmt,
|
||||
Args&&... args)
|
||||
{
|
||||
return obj<AFacet,DString>(DString::printf(mm, cap, fmt,
|
||||
std::forward<Args>(args)...));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<AAllocator>::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*/
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue