| 43 | //========================================================================== |
| 44 | |
| 45 | int utf8_encode(int32_t codepoint, uint8_t *buffer, int *size) |
| 46 | { |
| 47 | if (codepoint < 0) |
| 48 | return -1; |
| 49 | else if (codepoint < 0x80) |
| 50 | { |
| 51 | buffer[0] = (char)codepoint; |
| 52 | *size = 1; |
| 53 | } |
| 54 | else if (codepoint < 0x800) |
| 55 | { |
| 56 | buffer[0] = 0xC0 + ((codepoint & 0x7C0) >> 6); |
| 57 | buffer[1] = 0x80 + ((codepoint & 0x03F)); |
| 58 | *size = 2; |
| 59 | } |
| 60 | else if (codepoint < 0x10000) |
| 61 | { |
| 62 | buffer[0] = 0xE0 + ((codepoint & 0xF000) >> 12); |
| 63 | buffer[1] = 0x80 + ((codepoint & 0x0FC0) >> 6); |
| 64 | buffer[2] = 0x80 + ((codepoint & 0x003F)); |
| 65 | *size = 3; |
| 66 | } |
| 67 | else if (codepoint <= 0x10FFFF) |
| 68 | { |
| 69 | buffer[0] = 0xF0 + ((codepoint & 0x1C0000) >> 18); |
| 70 | buffer[1] = 0x80 + ((codepoint & 0x03F000) >> 12); |
| 71 | buffer[2] = 0x80 + ((codepoint & 0x000FC0) >> 6); |
| 72 | buffer[3] = 0x80 + ((codepoint & 0x00003F)); |
| 73 | *size = 4; |
| 74 | } |
| 75 | else |
| 76 | return -1; |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | //========================================================================== |
| 82 | // |
no outgoing calls
no test coverage detected