MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / ImParseFormatSanitizeForPrinting

Function ImParseFormatSanitizeForPrinting

KBotExt/imgui/imgui_widgets.cpp:3293–3305  ·  view source on GitHub ↗

Sanitize format - Zero terminate so extra characters after format (e.g. "%f123") don't confuse atof/atoi - stb_sprintf.h supports several new modifiers which format numbers in a way that also makes them incompatible atof/atoi.

Source from the content-addressed store, hash-verified

3291// - Zero terminate so extra characters after format (e.g. "%f123") don't confuse atof/atoi
3292// - stb_sprintf.h supports several new modifiers which format numbers in a way that also makes them incompatible atof/atoi.
3293void ImParseFormatSanitizeForPrinting(const char* fmt_in, char* fmt_out, size_t fmt_out_size)
3294{
3295 const char* fmt_end = ImParseFormatFindEnd(fmt_in);
3296 IM_UNUSED(fmt_out_size);
3297 IM_ASSERT((size_t)(fmt_end - fmt_in + 1) < fmt_out_size); // Format is too long, let us know if this happens to you!
3298 while (fmt_in < fmt_end)
3299 {
3300 char c = *fmt_in++;
3301 if (c != '\'' && c != '$' && c != '_') // Custom flags provided by stb_sprintf.h. POSIX 2008 also supports '.
3302 *(fmt_out++) = c;
3303 }
3304 *fmt_out = 0; // Zero-terminate
3305}
3306
3307// - For scanning we need to remove all width and precision fields and flags "%+3.7f" -> "%f". BUT don't strip types like "%I64d" which includes digits. ! "%07I64d" -> "%I64d"
3308const char* ImParseFormatSanitizeForScanning(const char* fmt_in, char* fmt_out, size_t fmt_out_size)

Callers 1

Calls 1

ImParseFormatFindEndFunction · 0.85

Tested by

no test coverage detected