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

Function ImParseFormatTrimDecorations

KBotExt/imgui/imgui_widgets.cpp:3278–3288  ·  view source on GitHub ↗

Extract the format out of a format string with leading or trailing decorations fmt = "blah blah" -> return "" fmt = "%.3f" -> return fmt fmt = "hello %.3f" -> return fmt + 6 fmt = "%.3f hello" -> return buf written with "%.3f"

Source from the content-addressed store, hash-verified

3276// fmt = "hello %.3f" -> return fmt + 6
3277// fmt = "%.3f hello" -> return buf written with "%.3f"
3278const char* ImParseFormatTrimDecorations(const char* fmt, char* buf, size_t buf_size)
3279{
3280 const char* fmt_start = ImParseFormatFindStart(fmt);
3281 if (fmt_start[0] != '%')
3282 return "";
3283 const char* fmt_end = ImParseFormatFindEnd(fmt_start);
3284 if (fmt_end[0] == 0) // If we only have leading decoration, we don't need to copy the data.
3285 return fmt_start;
3286 ImStrncpy(buf, fmt_start, ImMin((size_t)(fmt_end - fmt_start) + 1, buf_size));
3287 return buf;
3288}
3289
3290// Sanitize format
3291// - Zero terminate so extra characters after format (e.g. "%f123") don't confuse atof/atoi

Callers 1

TempInputScalarMethod · 0.85

Calls 4

ImParseFormatFindStartFunction · 0.85
ImParseFormatFindEndFunction · 0.85
ImStrncpyFunction · 0.85
ImMinFunction · 0.85

Tested by

no test coverage detected