Based on stb_to_utf8() from github.com/nothings/stb/
| 2047 | |
| 2048 | // Based on stb_to_utf8() from github.com/nothings/stb/ |
| 2049 | static inline int ImTextCharToUtf8_inline(char* buf, int buf_size, unsigned int c) |
| 2050 | { |
| 2051 | if (c < 0x80) |
| 2052 | { |
| 2053 | buf[0] = (char)c; |
| 2054 | return 1; |
| 2055 | } |
| 2056 | if (c < 0x800) |
| 2057 | { |
| 2058 | if (buf_size < 2) return 0; |
| 2059 | buf[0] = (char)(0xc0 + (c >> 6)); |
| 2060 | buf[1] = (char)(0x80 + (c & 0x3f)); |
| 2061 | return 2; |
| 2062 | } |
| 2063 | if (c < 0x10000) |
| 2064 | { |
| 2065 | if (buf_size < 3) return 0; |
| 2066 | buf[0] = (char)(0xe0 + (c >> 12)); |
| 2067 | buf[1] = (char)(0x80 + ((c >> 6) & 0x3f)); |
| 2068 | buf[2] = (char)(0x80 + ((c ) & 0x3f)); |
| 2069 | return 3; |
| 2070 | } |
| 2071 | if (c <= 0x10FFFF) |
| 2072 | { |
| 2073 | if (buf_size < 4) return 0; |
| 2074 | buf[0] = (char)(0xf0 + (c >> 18)); |
| 2075 | buf[1] = (char)(0x80 + ((c >> 12) & 0x3f)); |
| 2076 | buf[2] = (char)(0x80 + ((c >> 6) & 0x3f)); |
| 2077 | buf[3] = (char)(0x80 + ((c ) & 0x3f)); |
| 2078 | return 4; |
| 2079 | } |
| 2080 | // Invalid code point, the max unicode is 0x10FFFF |
| 2081 | return 0; |
| 2082 | } |
| 2083 | |
| 2084 | const char* ImTextCharToUtf8(char out_buf[5], unsigned int c) |
| 2085 | { |
no outgoing calls
no test coverage detected