1 /* utf8.c - collect routines for conversion to/from utf8 */
5 * Convert utf8 to long.
6 * On success: update *inptr to be the first nonread character,
7 * set *err to 0, and return the obtained value.
8 * On failure: leave *inptr unchanged, set *err to some nonzero error value:
9 * UTF8_BAD: bad utf8, UTF8_SHORT: input too short
12 * cnt is either 0 or gives the number of available bytes
15 from_utf8(char **inptr, int cnt, int *err) {
18 int need, bit, bad = 0;
20 in = (unsigned char *)(* inptr);
29 if (cnt && cnt < need) {
35 else if (need) while(--need) {
37 if ((uc2 & 0xc0) != 0x80) {
41 uc = ((uc << 6) | (uc2 & 0x3f));