MCPcopy Create free account
hub / github.com/cinder/Cinder / ImTextCharToUtf8_inline

Function ImTextCharToUtf8_inline

src/imgui/imgui.cpp:2571–2604  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

2569
2570// Based on stb_to_utf8() from github.com/nothings/stb/
2571static inline int ImTextCharToUtf8_inline(char* buf, int buf_size, unsigned int c)
2572{
2573 if (c < 0x80)
2574 {
2575 buf[0] = (char)c;
2576 return 1;
2577 }
2578 if (c < 0x800)
2579 {
2580 if (buf_size < 2) return 0;
2581 buf[0] = (char)(0xc0 + (c >> 6));
2582 buf[1] = (char)(0x80 + (c & 0x3f));
2583 return 2;
2584 }
2585 if (c < 0x10000)
2586 {
2587 if (buf_size < 3) return 0;
2588 buf[0] = (char)(0xe0 + (c >> 12));
2589 buf[1] = (char)(0x80 + ((c >> 6) & 0x3f));
2590 buf[2] = (char)(0x80 + ((c ) & 0x3f));
2591 return 3;
2592 }
2593 if (c <= 0x10FFFF)
2594 {
2595 if (buf_size < 4) return 0;
2596 buf[0] = (char)(0xf0 + (c >> 18));
2597 buf[1] = (char)(0x80 + ((c >> 12) & 0x3f));
2598 buf[2] = (char)(0x80 + ((c >> 6) & 0x3f));
2599 buf[3] = (char)(0x80 + ((c ) & 0x3f));
2600 return 4;
2601 }
2602 // Invalid code point, the max unicode is 0x10FFFF
2603 return 0;
2604}
2605
2606int ImTextCharToUtf8(char out_buf[5], unsigned int c)
2607{

Callers 2

ImTextCharToUtf8Function · 0.85
ImTextStrToUtf8Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected