Helper: Text buffer for logging/accumulating text
| 2811 | |
| 2812 | // Helper: Text buffer for logging/accumulating text |
| 2813 | void ImGuiTextBuffer::appendfv(const char* fmt, va_list args) |
| 2814 | { |
| 2815 | va_list args_copy; |
| 2816 | va_copy(args_copy, args); |
| 2817 | |
| 2818 | int len = ImFormatStringV(NULL, 0, fmt, args); // FIXME-OPT: could do a first pass write attempt, likely successful on first pass. |
| 2819 | if (len <= 0) |
| 2820 | { |
| 2821 | va_end(args_copy); |
| 2822 | return; |
| 2823 | } |
| 2824 | |
| 2825 | // Add zero-terminator the first time |
| 2826 | const int write_off = (Buf.Size != 0) ? Buf.Size : 1; |
| 2827 | const int needed_sz = write_off + len; |
| 2828 | if (write_off + len >= Buf.Capacity) |
| 2829 | { |
| 2830 | int new_capacity = Buf.Capacity * 2; |
| 2831 | Buf.reserve(needed_sz > new_capacity ? needed_sz : new_capacity); |
| 2832 | } |
| 2833 | |
| 2834 | Buf.resize(needed_sz); |
| 2835 | ImFormatStringV(&Buf[write_off - 1], (size_t)len + 1, fmt, args_copy); |
| 2836 | va_end(args_copy); |
| 2837 | } |
| 2838 | |
| 2839 | void ImGuiTextIndex::append(const char* base, int old_size, int new_size) |
| 2840 | { |
no test coverage detected