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_positive.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 'libcharconv_enclosed_positive.c')
| -rw-r--r-- | libcharconv_enclosed_positive.c | 209 |
1 files changed, 209 insertions, 0 deletions
diff --git a/libcharconv_enclosed_positive.c b/libcharconv_enclosed_positive.c new file mode 100644 index 0000000..15dd51e --- /dev/null +++ b/libcharconv_enclosed_positive.c @@ -0,0 +1,209 @@ +/* See LICENSE file for copyright and license details. */ +#include "lib-common.h" + + +enum libcharconv_result +libcharconv_enclosed_positive(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(0x1F10B); + else + c += UINT32_C(0x2780) - 1u; + goto conv6; + } else if (s[1] == '(') { + if (!slen--) + goto indeterminate; + if (s[2] == '1') { + if (!slen--) + goto indeterminate; + if (s[3] == ')') { + if (!slen--) + goto indeterminate; + if (s[4] != ')') + goto no_match; + c = UINT32_C(0x24F5); + goto conv5; + } else if (s[3] == '0') { + if (!slen--) + goto indeterminate; + if (s[4] != ')') + goto no_match; + if (!slen--) + goto indeterminate; + if (s[5] != ')') + goto no_match; + c = UINT32_C(0x24FE); + goto conv6; + } else { + goto no_match; + } + } else if ('2' <= s[2] && s[2] <= '9') { + c = UINT32_C(0x24F6) + (unsigned)(s[2] - '2'); + if (!slen--) + goto indeterminate; + if (s[3] != ')') + goto no_match; + if (!slen--) + goto indeterminate; + if (s[4] != ')') + goto no_match; + goto conv5; + } + } else if (s[1] == '1') { + if (!slen--) + goto indeterminate; + if (s[2] == ')') { + c = UINT32_C(0x2460); + goto conv3; + } else if ('0' <= s[2] && s[2] <= '9') { + if (!slen--) + goto indeterminate; + if (s[3] != ')') + goto no_match; + c = UINT32_C(0x2469) + (unsigned)(s[2] - '0'); + goto conv4; + } else { + goto no_match; + } + } else if (s[1] == '2') { + if (!slen--) + goto indeterminate; + if (s[2] == ')') { + c = UINT32_C(0x2461); + goto conv3; + } else if (s[2] == '0') { + if (!slen--) + goto indeterminate; + if (s[3] != ')') + goto no_match; + c = UINT32_C(0x2473); + goto conv4; + } else { + goto no_match; + } + } else if (s[1] == '0') { + if (!slen--) + goto indeterminate; + if (s[2] != ')') + goto no_match; + c = UINT32_C(0x24EA); + goto conv3; + } else if ('3' <= s[1] && s[1] <= '9') { + if (!slen--) + goto indeterminate; + if (s[2] != ')') + goto no_match; + c = UINT32_C(0x2460) + (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(0x24D0) + (unsigned)(s[1] - 'a'); + goto conv3; + } else if ('A' <= s[1] && s[1] <= 'Z') { + if (!slen--) + goto indeterminate; + if (s[2] != ')') + goto no_match; + c = UINT32_C(0x24B6) + (unsigned)(s[1] - 'A'); + goto conv3; + } else { + goto no_match; + } + } else if (s[0] == '[') { + if (!slen--) + goto indeterminate; + if (s[1] == 'd') { + if (!slen--) + goto indeterminate; + if (s[2] != ']') + goto no_match; + c = UINT32_C(0x1F1A5); + goto conv3; + } else if ('A' <= s[1] && s[1] <= 'Z') { + if (!slen--) + goto indeterminate; + if (s[2] != ']') + goto no_match; + c = UINT32_C(0x1F130) + (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; + +conv5: + if (*n) + goto no_conv; + if (*ncp) + *cp = c; + *n += 5u; + *ncp = 1u; + return LIBCHARCONV_CONVERTED; + +conv6: + if (*n) + goto no_conv; + if (*ncp) + *cp = c; + *n += 6u; + *ncp = 1u; + return LIBCHARCONV_CONVERTED; +} |
