MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / SanitizeFormatString

Function SanitizeFormatString

plugins/Cardinal/src/DearImGui/imgui_widgets.cpp:2177–2189  ·  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

2175// - Zero terminate so extra characters after format (e.g. "%f123") don't confuse atof/atoi
2176// - stb_sprintf.h supports several new modifiers which format numbers in a way that also makes them incompatible atof/atoi.
2177static void SanitizeFormatString(const char* fmt, char* fmt_out, size_t fmt_out_size)
2178{
2179 IM_UNUSED(fmt_out_size);
2180 const char* fmt_end = ImParseFormatFindEnd(fmt);
2181 IM_ASSERT((size_t)(fmt_end - fmt + 1) < fmt_out_size); // Format is too long, let us know if this happens to you!
2182 while (fmt < fmt_end)
2183 {
2184 char c = *(fmt++);
2185 if (c != '\'' && c != '$' && c != '_') // Custom flags provided by stb_sprintf.h. POSIX 2008 also supports '.
2186 *(fmt_out++) = c;
2187 }
2188 *fmt_out = 0; // Zero-terminate
2189}
2190
2191template<typename TYPE, typename SIGNEDTYPE>
2192TYPE ImGui::RoundScalarWithFormatT(const char* format, ImGuiDataType data_type, TYPE v)

Callers 1

Calls 1

ImParseFormatFindEndFunction · 0.85

Tested by

no test coverage detected