/* See LICENSE file for copyright and license details. */ #include "lib-common.h" enum libcharconv_result libcharconv_buhid(const char *s, size_t slen, size_t *n, uint_least32_t *cp, size_t *ncp) { uint_least32_t c; *n = 0; for (; slen--; s++) { PLAIN_CASE_SINGLE('k', 0x1743); PLAIN_CASE_SINGLE('g', 0x1744); PLAIN_CASE_SELECT("tdnpbmyrlwsh", 0x1746); switch (s[0]) { case 'A': case 'a': c = UINT32_C(0x1740); goto conv1; case 'I': case 'i': c = UINT32_C(0x1741); goto conv1; case 'U': case 'u': c = UINT32_C(0x1742); goto conv1; case '^': if (!slen) return LIBCHARCONV_INDETERMINATE; switch (s[1]) { case 'I': case 'i': c = UINT32_C(0x1752); goto conv2; case 'U': case 'u': c = UINT32_C(0x1753); goto conv2; default: goto no_match; } goto no_match; default: no_match: *n += 1u; break; } } no_conv: return LIBCHARCONV_NO_CONVERT; conv: if (*n) goto no_conv; conv_again: if (!slen) return LIBCHARCONV_INDETERMINATE; switch (s[1]) { case 'A': case 'a': if (*ncp >= 1u) cp[0] = c; *n += 2u; *ncp = 1u; return LIBCHARCONV_CONVERTED; case 'I': case 'i': if (*ncp >= 1u) cp[0] = c; if (*ncp >= 2u) cp[1] = UINT32_C(0x1752); *n += 2u; *ncp = 2u; return LIBCHARCONV_CONVERTED; case 'U': case 'u': if (*ncp >= 1u) cp[0] = c; if (*ncp >= 2u) cp[1] = UINT32_C(0x1753); *n += 2u; *ncp = 2u; return LIBCHARCONV_CONVERTED; case 'G': case 'g': if (c == UINT32_C(0x1745)) goto no_match; if (s[0] != 'N' && s[0] != 'n') goto no_match; c = UINT32_C(0x1745); *n += 1u; slen--; s++; goto conv_again; default: goto no_match; } conv1: if (*n) goto no_conv; if (*ncp) *cp = c; *n += 1u; *ncp = 1u; return LIBCHARCONV_CONVERTED; conv2: if (*n) goto no_conv; if (*ncp) *cp = c; *n += 2u; *ncp = 1u; return LIBCHARCONV_CONVERTED; }