commit - 987d9c885908e59047d2577404e6d7d058f349a2
commit + a1e5a814946390aac545d5ad478b1adb6ff5f112
blob - 942ac1f138c65beb8ee09571efd94ddfbf4fc6af
blob + 3093c1cd2bfec6e5fb6649ee13c6e1f34a8c2241
--- utf8.c
+++ utf8.c
1,3,1,1,1,1,1,3,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // s7..s8
};
-uint32_t
-utf8_decode(uint32_t* restrict state, uint32_t* restrict codep, uint8_t byte) {
+static inline uint32_t
+decode(uint32_t* restrict state, uint32_t* restrict codep, uint8_t byte)
+{
uint32_t type = utf8d[byte];
*codep = (*state != UTF8_ACCEPT) ?
/* end of the converter, utility functions ahead */
+/* public version of decode */
+uint32_t
+utf8_decode(uint32_t* restrict state, uint32_t* restrict codep, uint8_t byte)
+{
+ return decode(state, codep, byte);
+}
+
/* encode cp in s. s must be at least 4 bytes wide */
size_t
utf8_encode(uint32_t cp, char *s)
uint32_t cp = 0, state = 0;
for (i = 0; *s && i < n; ++s)
- if (!utf8_decode(&state, &cp, *s))
+ if (!decode(&state, &cp, *s))
++i;
if (state != UTF8_ACCEPT)
len = 0;
for (; *s; ++s)
- if (!utf8_decode(&state, &cp, *s))
+ if (!decode(&state, &cp, *s))
len++;
return len;
}
tot = 0;
for (i = 0; *s && i < n; ++s)
- if (!utf8_decode(&state, &cp, *s)) {
+ if (!decode(&state, &cp, *s)) {
i++;
tot += utf8_chwidth(cp);
}
tot = 0;
for (; *s; ++s)
- if (!utf8_decode(&state, &cp, *s))
+ if (!decode(&state, &cp, *s))
tot += utf8_chwidth(cp);
return tot;
tot = 0;
for (; *str && str < end; ++str)
- if (!utf8_decode(&state, &cp, *str))
+ if (!decode(&state, &cp, *str))
tot += utf8_chwidth(cp);
return tot;
}
uint32_t cp = 0, state = 0;
for (; *s; ++s)
- if (!utf8_decode(&state, &cp, *s))
+ if (!decode(&state, &cp, *s))
break;
return (char*)s+1;
}