MCPcopy Create free account
hub / github.com/Overload-Technologies/Overload / ImTextCharToUtf8_inline

Function ImTextCharToUtf8_inline

Dependencies/ImGui/src/imgui.cpp:2530–2563  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

2528
2529// Based on stb_to_utf8() from github.com/nothings/stb/
2530static inline int ImTextCharToUtf8_inline(char* buf, int buf_size, unsigned int c)
2531{
2532 if (c < 0x80)
2533 {
2534 buf[0] = (char)c;
2535 return 1;
2536 }
2537 if (c < 0x800)
2538 {
2539 if (buf_size < 2) return 0;
2540 buf[0] = (char)(0xc0 + (c >> 6));
2541 buf[1] = (char)(0x80 + (c & 0x3f));
2542 return 2;
2543 }
2544 if (c < 0x10000)
2545 {
2546 if (buf_size < 3) return 0;
2547 buf[0] = (char)(0xe0 + (c >> 12));
2548 buf[1] = (char)(0x80 + ((c >> 6) & 0x3f));
2549 buf[2] = (char)(0x80 + ((c ) & 0x3f));
2550 return 3;
2551 }
2552 if (c <= 0x10FFFF)
2553 {
2554 if (buf_size < 4) return 0;
2555 buf[0] = (char)(0xf0 + (c >> 18));
2556 buf[1] = (char)(0x80 + ((c >> 12) & 0x3f));
2557 buf[2] = (char)(0x80 + ((c >> 6) & 0x3f));
2558 buf[3] = (char)(0x80 + ((c ) & 0x3f));
2559 return 4;
2560 }
2561 // Invalid code point, the max unicode is 0x10FFFF
2562 return 0;
2563}
2564
2565const char* ImTextCharToUtf8(char out_buf[5], unsigned int c)
2566{

Callers 2

ImTextCharToUtf8Function · 0.85
ImTextStrToUtf8Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected