MCPcopy Create free account
hub / github.com/GPUOpen-LibrariesAndSDKs/Cauldron / ImTextCharToUtf8

Function ImTextCharToUtf8

libs/imgui/imgui.cpp:1165–1200  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1163
1164// Based on stb_to_utf8() from github.com/nothings/stb/
1165static inline int ImTextCharToUtf8(char* buf, int buf_size, unsigned int c)
1166{
1167 if (c < 0x80)
1168 {
1169 buf[0] = (char)c;
1170 return 1;
1171 }
1172 if (c < 0x800)
1173 {
1174 if (buf_size < 2) return 0;
1175 buf[0] = (char)(0xc0 + (c >> 6));
1176 buf[1] = (char)(0x80 + (c & 0x3f));
1177 return 2;
1178 }
1179 if (c >= 0xdc00 && c < 0xe000)
1180 {
1181 return 0;
1182 }
1183 if (c >= 0xd800 && c < 0xdc00)
1184 {
1185 if (buf_size < 4) return 0;
1186 buf[0] = (char)(0xf0 + (c >> 18));
1187 buf[1] = (char)(0x80 + ((c >> 12) & 0x3f));
1188 buf[2] = (char)(0x80 + ((c >> 6) & 0x3f));
1189 buf[3] = (char)(0x80 + ((c ) & 0x3f));
1190 return 4;
1191 }
1192 //else if (c < 0x10000)
1193 {
1194 if (buf_size < 3) return 0;
1195 buf[0] = (char)(0xe0 + (c >> 12));
1196 buf[1] = (char)(0x80 + ((c>> 6) & 0x3f));
1197 buf[2] = (char)(0x80 + ((c ) & 0x3f));
1198 return 3;
1199 }
1200}
1201
1202static inline int ImTextCountUtf8BytesFromChar(unsigned int c)
1203{

Callers 1

ImTextStrToUtf8Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected