0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 00:32:35 +01:00

ircd::fmt: Add snstringf() suite.

This commit is contained in:
Jason Volk 2017-09-23 23:59:27 -07:00
parent a65a033c3b
commit 2c07ed673a

View file

@ -34,6 +34,8 @@ namespace ircd::fmt
struct specifier;
struct snprintf;
struct vsnprintf;
struct snstringf;
struct vsnstringf;
//
// Module API
@ -131,3 +133,34 @@ struct ircd::fmt::vsnprintf
internal, buf, max, fmt, ap
}{}
};
struct ircd::fmt::vsnstringf
:std::string
{
vsnstringf(const size_t &max,
const char *const &fmt,
const va_rtti &ap)
:std::string
{
[&max, &fmt, &ap]
{
std::string ret;
ret.resize(max, char{});
ret.resize(vsnprintf(const_cast<char *>(ret.data()), ret.size() + 1, fmt, ap));
return ret;
}()
}{}
};
struct ircd::fmt::snstringf
:vsnstringf
{
template<class... args>
snstringf(const size_t &max,
const char *const &fmt,
args&&... a)
:vsnstringf
{
max, fmt, va_rtti{std::forward<args>(a)...}
}{}
};