diff options
| author | Mattias Andrée <m@maandree.se> | 2026-01-26 17:57:59 +0100 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-01-26 17:57:59 +0100 |
| commit | b48e74772cc4e6879a6d37a5c00ad6df2db1edc3 (patch) | |
| tree | 4d1497bc28ff8ef8f2c4102195326dfe76b2622d /libcharconv_enclosed_negative.c | |
| parent | Add flipping and turning for yijing n-grams, and add invisible (diff) | |
| download | charconv-b48e74772cc4e6879a6d37a5c00ad6df2db1edc3.tar.gz charconv-b48e74772cc4e6879a6d37a5c00ad6df2db1edc3.tar.bz2 charconv-b48e74772cc4e6879a6d37a5c00ad6df2db1edc3.tar.xz | |
Add enclosed
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to '')
| -rw-r--r-- | libcharconv_enclosed_negative.c | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/libcharconv_enclosed_negative.c b/libcharconv_enclosed_negative.c new file mode 100644 index 0000000..d7be6a7 --- /dev/null +++ b/libcharconv_enclosed_negative.c @@ -0,0 +1,150 @@ +/* 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; +} |
