| 31 | |
| 32 | |
| 33 | std::string fV(const char* format, va_list args) { |
| 34 | // va_lists cannot be reused but we need it twice, so clone args. |
| 35 | va_list args2; |
| 36 | va_copy(args2, args); |
| 37 | DEFER({va_end(args2);}); |
| 38 | // Compute size of required buffer |
| 39 | int size = vsnprintf(NULL, 0, format, args); |
| 40 | if (size < 0) |
| 41 | return ""; |
| 42 | // Create buffer |
| 43 | std::string s; |
| 44 | s.resize(size); |
| 45 | vsnprintf(&s[0], size + 1, format, args2); |
| 46 | return s; |
| 47 | } |
| 48 | |
| 49 | |
| 50 | std::string lowercase(const std::string& s) { |