MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / DebugTextEncoding

Method DebugTextEncoding

imgui_tiny_app/imgui/imgui.cpp:22022–22058  ·  view source on GitHub ↗

Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct.

Source from the content-addressed store, hash-verified

22020
22021// Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct.
22022void ImGui::DebugTextEncoding(const char* str)
22023{
22024 Text("Text: \"%s\"", str);
22025 if (!BeginTable("##DebugTextEncoding", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable))
22026 return;
22027 TableSetupColumn("Offset");
22028 TableSetupColumn("UTF-8");
22029 TableSetupColumn("Glyph");
22030 TableSetupColumn("Codepoint");
22031 TableHeadersRow();
22032 const char* str_end = str + strlen(str); // As we may receive malformed UTF-8, pass an explicit end instead of relying on ImTextCharFromUtf8() assuming enough space.
22033 for (const char* p = str; *p != 0; )
22034 {
22035 unsigned int c;
22036 const int c_utf8_len = ImTextCharFromUtf8(&c, p, str_end);
22037 TableNextColumn();
22038 Text("%d", (int)(p - str));
22039 TableNextColumn();
22040 for (int byte_index = 0; byte_index < c_utf8_len; byte_index++)
22041 {
22042 if (byte_index > 0)
22043 SameLine();
22044 Text("0x%02X", (int)(unsigned char)p[byte_index]);
22045 }
22046 TableNextColumn();
22047 TextUnformatted(p, p + c_utf8_len);
22048 if (!GetFont()->IsGlyphInFont((ImWchar)c))
22049 {
22050 SameLine();
22051 TextUnformatted("[missing]");
22052 }
22053 TableNextColumn();
22054 Text("U+%04X", (int)c);
22055 p += c_utf8_len;
22056 }
22057 EndTable();
22058}
22059
22060static void DebugFlashStyleColorStop()
22061{

Callers

nothing calls this directly

Calls 2

ImTextCharFromUtf8Function · 0.85
IsGlyphInFontMethod · 0.80

Tested by

no test coverage detected