MCPcopy Create free account
hub / github.com/Raais/ImStudio / SanitizeFormatString

Function SanitizeFormatString

src/third-party/imgui/imgui_widgets.cpp:2123–2135  ·  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

2121// - Zero terminate so extra characters after format (e.g. "%f123") don't confuse atof/atoi
2122// - stb_sprintf.h supports several new modifiers which format numbers in a way that also makes them incompatible atof/atoi.
2123static void SanitizeFormatString(const char* fmt, char* fmt_out, size_t fmt_out_size)
2124{
2125 IM_UNUSED(fmt_out_size);
2126 const char* fmt_end = ImParseFormatFindEnd(fmt);
2127 IM_ASSERT((size_t)(fmt_end - fmt + 1) < fmt_out_size); // Format is too long, let us know if this happens to you!
2128 while (fmt < fmt_end)
2129 {
2130 char c = *(fmt++);
2131 if (c != '\'' && c != '$' && c != '_') // Custom flags provided by stb_sprintf.h. POSIX 2008 also supports '.
2132 *(fmt_out++) = c;
2133 }
2134 *fmt_out = 0; // Zero-terminate
2135}
2136
2137template<typename TYPE, typename SIGNEDTYPE>
2138TYPE ImGui::RoundScalarWithFormatT(const char* format, ImGuiDataType data_type, TYPE v)

Callers 1

Calls 1

ImParseFormatFindEndFunction · 0.85

Tested by

no test coverage detected