MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / ImTextCharToUtf8_inline

Function ImTextCharToUtf8_inline

extern/imgui/imgui.cpp:2111–2144  ·  view source on GitHub ↗

Based on stb_to_utf8() from github.com/nothings/stb/

Source from the content-addressed store, hash-verified

2109
2110// Based on stb_to_utf8() from github.com/nothings/stb/
2111static inline int ImTextCharToUtf8_inline(char* buf, int buf_size, unsigned int c)
2112{
2113 if (c < 0x80)
2114 {
2115 buf[0] = (char)c;
2116 return 1;
2117 }
2118 if (c < 0x800)
2119 {
2120 if (buf_size < 2) return 0;
2121 buf[0] = (char)(0xc0 + (c >> 6));
2122 buf[1] = (char)(0x80 + (c & 0x3f));
2123 return 2;
2124 }
2125 if (c < 0x10000)
2126 {
2127 if (buf_size < 3) return 0;
2128 buf[0] = (char)(0xe0 + (c >> 12));
2129 buf[1] = (char)(0x80 + ((c >> 6) & 0x3f));
2130 buf[2] = (char)(0x80 + ((c ) & 0x3f));
2131 return 3;
2132 }
2133 if (c <= 0x10FFFF)
2134 {
2135 if (buf_size < 4) return 0;
2136 buf[0] = (char)(0xf0 + (c >> 18));
2137 buf[1] = (char)(0x80 + ((c >> 12) & 0x3f));
2138 buf[2] = (char)(0x80 + ((c >> 6) & 0x3f));
2139 buf[3] = (char)(0x80 + ((c ) & 0x3f));
2140 return 4;
2141 }
2142 // Invalid code point, the max unicode is 0x10FFFF
2143 return 0;
2144}
2145
2146const char* ImTextCharToUtf8(char out_buf[5], unsigned int c)
2147{

Callers 2

ImTextCharToUtf8Function · 0.85
ImTextStrToUtf8Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected