Helper: Text buffer for logging/accumulating text
| 2159 | |
| 2160 | // Helper: Text buffer for logging/accumulating text |
| 2161 | void ImGuiTextBuffer::appendfv(const char* fmt, va_list args) |
| 2162 | { |
| 2163 | va_list args_copy; |
| 2164 | va_copy(args_copy, args); |
| 2165 | |
| 2166 | int len = ImFormatStringV(NULL, 0, fmt, args); // FIXME-OPT: could do a first pass write attempt, likely successful on first pass. |
| 2167 | if (len <= 0) |
| 2168 | { |
| 2169 | va_end(args_copy); |
| 2170 | return; |
| 2171 | } |
| 2172 | |
| 2173 | // Add zero-terminator the first time |
| 2174 | const int write_off = (Buf.Size != 0) ? Buf.Size : 1; |
| 2175 | const int needed_sz = write_off + len; |
| 2176 | if (write_off + len >= Buf.Capacity) |
| 2177 | { |
| 2178 | int new_capacity = Buf.Capacity * 2; |
| 2179 | Buf.reserve(needed_sz > new_capacity ? needed_sz : new_capacity); |
| 2180 | } |
| 2181 | |
| 2182 | Buf.resize(needed_sz); |
| 2183 | ImFormatStringV(&Buf[write_off - 1], (size_t)len + 1, fmt, args_copy); |
| 2184 | va_end(args_copy); |
| 2185 | } |
| 2186 | |
| 2187 | //----------------------------------------------------------------------------- |
| 2188 | // [SECTION] ImGuiListClipper |
no test coverage detected