| 14 | **/ |
| 15 | |
| 16 | int uni2utf8(unsigned int c, char *buf, size_t size) |
| 17 | { |
| 18 | unsigned int len = 0; |
| 19 | int first; |
| 20 | int i; |
| 21 | |
| 22 | if (c < 0x80) { |
| 23 | first = 0; |
| 24 | len = 1; |
| 25 | } else if (c < 0x800) { |
| 26 | first = 0xc0; |
| 27 | len = 2; |
| 28 | } else if (c < 0x10000) { |
| 29 | first = 0xe0; |
| 30 | len = 3; |
| 31 | } else if (c < 0x200000) { |
| 32 | first = 0xf0; |
| 33 | len = 4; |
| 34 | } else if (c < 0x4000000) { |
| 35 | first = 0xf8; |
| 36 | len = 5; |
| 37 | } else { |
| 38 | first = 0xfc; |
| 39 | len = 6; |
| 40 | } |
| 41 | |
| 42 | if (buf && size > 0) { |
| 43 | if (len > size) |
| 44 | len = (unsigned int) size; |
| 45 | for (i = len - 1; i > 0; --i) { |
| 46 | buf[i] = (c & 0x3f) | 0x80; |
| 47 | c >>= 6; |
| 48 | } |
| 49 | buf[0] = c | first; |
| 50 | } |
| 51 | |
| 52 | return len; |
| 53 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…