| 240 | } |
| 241 | |
| 242 | int vsformat(std::string& outputString, const char* form, va_list args) { |
| 243 | char buf[200]; |
| 244 | |
| 245 | va_list args2; |
| 246 | va_copy(args2, args); |
| 247 | int size = vsnprintf(buf, sizeof(buf), form, args2); |
| 248 | va_end(args2); |
| 249 | |
| 250 | if (size >= 0 && size < sizeof(buf)) { |
| 251 | outputString = std::string(buf, size); |
| 252 | return size; |
| 253 | } |
| 254 | |
| 255 | #ifdef _WIN32 |
| 256 | // Microsoft's non-standard vsnprintf doesn't return a correct size, but just an error, so determine the necessary |
| 257 | // size |
| 258 | va_copy(args2, args); |
| 259 | size = _vscprintf(form, args2); |
| 260 | va_end(args2); |
| 261 | #endif |
| 262 | |
| 263 | if (size < 0) { |
| 264 | return -1; |
| 265 | } |
| 266 | |
| 267 | CODE_PROBE(true, "large format result"); |
| 268 | |
| 269 | outputString.resize(size + 1); |
| 270 | size = vsnprintf(&outputString[0], outputString.size(), form, args); |
| 271 | if (size < 0 || size >= outputString.size()) { |
| 272 | return -1; |
| 273 | } |
| 274 | |
| 275 | outputString.resize(size); |
| 276 | return size; |
| 277 | } |
| 278 | |
| 279 | std::string format(const char* form, ...) { |
| 280 | va_list args; |