/* See LICENSE file for copyright and license details. */ #include "lib-common.h" enum libcharconv_result libcharconv_enclosed_negative(const char *s, size_t slen, size_t *n, uint_least32_t *cp, size_t *ncp) { uint_least32_t c; size_t old_slen; *n = 0; for (; slen--; s++) { old_slen = slen; if (s[0] == '(') { if (!slen--) goto indeterminate; if ((unsigned char)s[1] == 0xF0u) { if (!slen--) goto indeterminate; if ((unsigned char)s[2] != 0x9Du) goto no_match; if (!slen--) goto indeterminate; if ((unsigned char)s[3] != 0x9Fu) goto no_match; if (!slen--) goto indeterminate; if (0xA2u > (unsigned char)s[4] || (unsigned char)s[4] > 0xABu) goto no_match; if (!slen--) goto indeterminate; if (s[5] != ')') goto no_match; c = (unsigned char)s[4] - 0xA2u; if (c == 0) c = UINT32_C(0x1F10C); else c += UINT32_C(0x278A) - 1u; goto conv6; } else if (s[1] == '1') { if (!slen--) goto indeterminate; if (s[2] == ')') { c = UINT32_C(0x2776); goto conv3; } else if ('0' <= s[2] && s[2] <= '9') { if (!slen--) goto indeterminate; if (s[3] != ')') goto no_match; if (s[2] == '0') c = UINT32_C(0x277F); else c = UINT32_C(0x24EB) + (unsigned)(s[2] - '1'); goto conv4; } else { goto no_match; } } else if (s[1] == '2') { if (!slen--) goto indeterminate; if (s[2] == ')') { c = UINT32_C(0x2777); goto conv3; } else if (s[2] == '0') { if (!slen--) goto indeterminate; if (s[3] != ')') goto no_match; c = UINT32_C(0x24F4); goto conv4; } else { goto no_match; } } else if (s[1] == '0') { if (!slen--) goto indeterminate; if (s[2] != ')') goto no_match; c = UINT32_C(0x24FF); goto conv3; } else if ('3' <= s[1] && s[1] <= '9') { if (!slen--) goto indeterminate; if (s[2] != ')') goto no_match; c = UINT32_C(0x2776) + (unsigned)(s[1] - '1'); goto conv3; } else if ('A' <= s[1] && s[1] <= 'Z') { if (!slen--) goto indeterminate; if (s[2] != ')') goto no_match; c = UINT32_C(0x1F150) + (unsigned)(s[1] - 'A'); goto conv3; } else { goto no_match; } } else if (s[0] == '[') { if (!slen--) goto indeterminate; if ('A' <= s[1] && s[1] <= 'Z') { if (!slen--) goto indeterminate; if (s[2] != ']') goto no_match; c = UINT32_C(0x1F170) + (unsigned)(s[1] - 'A'); goto conv3; } } else { no_match: slen = old_slen; *n += 1u; break; } } no_conv: return LIBCHARCONV_NO_CONVERT; indeterminate: if (*n) goto no_conv; return LIBCHARCONV_INDETERMINATE; conv3: if (*n) goto no_conv; if (*ncp) *cp = c; *n += 3u; *ncp = 1u; return LIBCHARCONV_CONVERTED; conv4: if (*n) goto no_conv; if (*ncp) *cp = c; *n += 4u; *ncp = 1u; return LIBCHARCONV_CONVERTED; conv6: if (*n) goto no_conv; if (*ncp) *cp = c; *n += 6u; *ncp = 1u; return LIBCHARCONV_CONVERTED; }