Helper: Text buffer for logging/accumulating text
| 2632 | |
| 2633 | // Helper: Text buffer for logging/accumulating text |
| 2634 | void ImGuiTextBuffer::appendfv(const char* fmt, va_list args) |
| 2635 | { |
| 2636 | va_list args_copy; |
| 2637 | va_copy(args_copy, args); |
| 2638 | |
| 2639 | int len = ImFormatStringV(NULL, 0, fmt, args); // FIXME-OPT: could do a first pass write attempt, likely successful on first pass. |
| 2640 | if (len <= 0) |
| 2641 | { |
| 2642 | va_end(args_copy); |
| 2643 | return; |
| 2644 | } |
| 2645 | |
| 2646 | // Add zero-terminator the first time |
| 2647 | const int write_off = (Buf.Size != 0) ? Buf.Size : 1; |
| 2648 | const int needed_sz = write_off + len; |
| 2649 | if (write_off + len >= Buf.Capacity) |
| 2650 | { |
| 2651 | int new_capacity = Buf.Capacity * 2; |
| 2652 | Buf.reserve(needed_sz > new_capacity ? needed_sz : new_capacity); |
| 2653 | } |
| 2654 | |
| 2655 | Buf.resize(needed_sz); |
| 2656 | ImFormatStringV(&Buf[write_off - 1], (size_t)len + 1, fmt, args_copy); |
| 2657 | va_end(args_copy); |
| 2658 | } |
| 2659 | |
| 2660 | void ImGuiTextIndex::append(const char* base, int old_size, int new_size) |
| 2661 | { |
no test coverage detected