1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <stdint.h> #include <stddef.h> #include "unicode.h" size_t utf8_chsize(uint32_t ch) { if (ch < 0x80) { return 1; } else if (ch < 0x800) { return 2; } else if (ch < 0x10000) { return 3; } return 4; }