MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / ImTextCharToUtf8_inline

Function ImTextCharToUtf8_inline

plugins/Cardinal/src/DearImGui/imgui.cpp:1747–1780  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1745
1746// Based on stb_to_utf8() from github.com/nothings/stb/
1747static inline int ImTextCharToUtf8_inline(char* buf, int buf_size, unsigned int c)
1748{
1749 if (c < 0x80)
1750 {
1751 buf[0] = (char)c;
1752 return 1;
1753 }
1754 if (c < 0x800)
1755 {
1756 if (buf_size < 2) return 0;
1757 buf[0] = (char)(0xc0 + (c >> 6));
1758 buf[1] = (char)(0x80 + (c & 0x3f));
1759 return 2;
1760 }
1761 if (c < 0x10000)
1762 {
1763 if (buf_size < 3) return 0;
1764 buf[0] = (char)(0xe0 + (c >> 12));
1765 buf[1] = (char)(0x80 + ((c >> 6) & 0x3f));
1766 buf[2] = (char)(0x80 + ((c ) & 0x3f));
1767 return 3;
1768 }
1769 if (c <= 0x10FFFF)
1770 {
1771 if (buf_size < 4) return 0;
1772 buf[0] = (char)(0xf0 + (c >> 18));
1773 buf[1] = (char)(0x80 + ((c >> 12) & 0x3f));
1774 buf[2] = (char)(0x80 + ((c >> 6) & 0x3f));
1775 buf[3] = (char)(0x80 + ((c ) & 0x3f));
1776 return 4;
1777 }
1778 // Invalid code point, the max unicode is 0x10FFFF
1779 return 0;
1780}
1781
1782const char* ImTextCharToUtf8(char out_buf[5], unsigned int c)
1783{

Callers 2

ImTextCharToUtf8Function · 0.85
ImTextStrToUtf8Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected