Merge pull request #1583 from unxed/fix-alt-keys
[far2l.git] / utils / src / StrPrintf.cpp
blob7078cdbb419aa7d35211e1db22939b3c4ddc1494
1 #include <utils.h>
3 std::string StrPrintfV(const char *format, va_list args)
5 std::string out(0x100, '#');
7 va_list args_copy;
8 va_copy(args_copy, args);
9 int rv = vsnprintf(&out[0], out.size(), format, args_copy);
10 va_end(args_copy);
12 if (rv >= 0 && rv < (int)out.size()) {
13 out.resize(rv);
14 return out;
17 out.resize(rv + 1);
18 rv = vsnprintf(&out[0], out.size(), format, args);
20 if (rv >= 0 && rv < (int)out.size()) {
21 out.resize(rv);
22 return out;
25 out = "Bad format string: ";
26 out+= format;
27 return out;
30 std::string StrPrintf(const char *format, ...)
32 va_list args;
33 va_start(args, format);
35 const std::string &out = StrPrintfV(format, args);
37 va_end(args);
39 return out;