mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::fmt: Add snstringf() suite.
This commit is contained in:
parent
a65a033c3b
commit
2c07ed673a
1 changed files with 33 additions and 0 deletions
|
@ -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)...}
|
||||
}{}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue