Helper: Text buffer for logging/accumulating text
| 2510 | |
| 2511 | // Helper: Text buffer for logging/accumulating text |
| 2512 | void ImGuiTextBuffer::appendfv(const char* fmt, va_list args) |
| 2513 | { |
| 2514 | va_list args_copy; |
| 2515 | va_copy(args_copy, args); |
| 2516 | |
| 2517 | int len = ImFormatStringV(NULL, 0, fmt, args); // FIXME-OPT: could do a first pass write attempt, likely successful on first pass. |
| 2518 | if (len <= 0) |
| 2519 | { |
| 2520 | va_end(args_copy); |
| 2521 | return; |
| 2522 | } |
| 2523 | |
| 2524 | // Add zero-terminator the first time |
| 2525 | const int write_off = (Buf.Size != 0) ? Buf.Size : 1; |
| 2526 | const int needed_sz = write_off + len; |
| 2527 | if (write_off + len >= Buf.Capacity) |
| 2528 | { |
| 2529 | int new_capacity = Buf.Capacity * 2; |
| 2530 | Buf.reserve(needed_sz > new_capacity ? needed_sz : new_capacity); |
| 2531 | } |
| 2532 | |
| 2533 | Buf.resize(needed_sz); |
| 2534 | ImFormatStringV(&Buf[write_off - 1], (size_t)len + 1, fmt, args_copy); |
| 2535 | va_end(args_copy); |
| 2536 | } |
| 2537 | |
| 2538 | void ImGuiTextIndex::append(const char* base, int old_size, int new_size) |
| 2539 | { |
no test coverage detected