MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / ImTextCharToUtf8_inline

Function ImTextCharToUtf8_inline

KBotExt/imgui/imgui.cpp:2172–2205  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

2170
2171// Based on stb_to_utf8() from github.com/nothings/stb/
2172static inline int ImTextCharToUtf8_inline(char* buf, int buf_size, unsigned int c)
2173{
2174 if (c < 0x80)
2175 {
2176 buf[0] = (char)c;
2177 return 1;
2178 }
2179 if (c < 0x800)
2180 {
2181 if (buf_size < 2) return 0;
2182 buf[0] = (char)(0xc0 + (c >> 6));
2183 buf[1] = (char)(0x80 + (c & 0x3f));
2184 return 2;
2185 }
2186 if (c < 0x10000)
2187 {
2188 if (buf_size < 3) return 0;
2189 buf[0] = (char)(0xe0 + (c >> 12));
2190 buf[1] = (char)(0x80 + ((c >> 6) & 0x3f));
2191 buf[2] = (char)(0x80 + ((c) & 0x3f));
2192 return 3;
2193 }
2194 if (c <= 0x10FFFF)
2195 {
2196 if (buf_size < 4) return 0;
2197 buf[0] = (char)(0xf0 + (c >> 18));
2198 buf[1] = (char)(0x80 + ((c >> 12) & 0x3f));
2199 buf[2] = (char)(0x80 + ((c >> 6) & 0x3f));
2200 buf[3] = (char)(0x80 + ((c) & 0x3f));
2201 return 4;
2202 }
2203 // Invalid code point, the max unicode is 0x10FFFF
2204 return 0;
2205}
2206
2207const char* ImTextCharToUtf8(char out_buf[5], unsigned int c)
2208{

Callers 2

ImTextCharToUtf8Function · 0.85
ImTextStrToUtf8Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected