MCPcopy Create free account
hub / github.com/RenderKit/embree / ImParseFormatTrimDecorations

Function ImParseFormatTrimDecorations

tutorials/common/imgui/imgui_widgets.cpp:3206–3216  ·  view source on GitHub ↗

Extract the format out of a format string with leading or trailing decorations fmt = "blah blah" -> return fmt 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

3204// fmt = "hello %.3f" -> return fmt + 6
3205// fmt = "%.3f hello" -> return buf written with "%.3f"
3206const char* ImParseFormatTrimDecorations(const char* fmt, char* buf, size_t buf_size)
3207{
3208 const char* fmt_start = ImParseFormatFindStart(fmt);
3209 if (fmt_start[0] != '%')
3210 return fmt;
3211 const char* fmt_end = ImParseFormatFindEnd(fmt_start);
3212 if (fmt_end[0] == 0) // If we only have leading decoration, we don't need to copy the data.
3213 return fmt_start;
3214 ImStrncpy(buf, fmt_start, ImMin((size_t)(fmt_end - fmt_start) + 1, buf_size));
3215 return buf;
3216}
3217
3218// Sanitize format
3219// - 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