Based on stb_to_utf8() from github.com/nothings/stb/
| 2569 | |
| 2570 | // Based on stb_to_utf8() from github.com/nothings/stb/ |
| 2571 | static 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 | |
| 2606 | int ImTextCharToUtf8(char out_buf[5], unsigned int c) |
| 2607 | { |
no outgoing calls
no test coverage detected