blob: ffafca2371e800d213f9ef6b254df08667905c2b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "strfmt.h"
#include <stdarg.h>
#include <stdio.h>
#include <cassert>
namespace vespalib::slime {
std::string strfmt(const char *fmt, ...)
{
va_list ap;
std::string ret;
int size = 100;
do {
ret.resize(size + 1);
va_start(ap, fmt);
size = vsnprintf(&ret[0], ret.size(), fmt, ap);
va_end(ap);
} while (size >= (int) ret.size());
assert(size >= 0);
ret.resize(size);
return ret;
}
} // namespace vespalib::slime
|