diff options
| author | Mattias Andrée <m@maandree.se> | 2026-01-25 12:04:20 +0100 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-01-25 12:04:20 +0100 |
| commit | a7c404e03a4b814160ec4c97797a56ee4581a0f7 (patch) | |
| tree | ac3c598e792f041826438e8fe81e31ce5ca92d6b /libcharconv_yijing_hexagrams.c | |
| parent | Add lisu (diff) | |
| download | charconv-a7c404e03a4b814160ec4c97797a56ee4581a0f7.tar.gz charconv-a7c404e03a4b814160ec4c97797a56ee4581a0f7.tar.bz2 charconv-a7c404e03a4b814160ec4c97797a56ee4581a0f7.tar.xz | |
Add yijing n-grams
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'libcharconv_yijing_hexagrams.c')
| -rw-r--r-- | libcharconv_yijing_hexagrams.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/libcharconv_yijing_hexagrams.c b/libcharconv_yijing_hexagrams.c new file mode 100644 index 0000000..b271e1f --- /dev/null +++ b/libcharconv_yijing_hexagrams.c @@ -0,0 +1,69 @@ +/* See LICENSE file for copyright and license details. */ +#include "lib-common.h" + + +static unsigned char yijing_hexagrams[] = { + 0xC0, 0xEB, 0xCC, 0xE0, 0xC9, 0xC5, 0xD8, 0xCB, + 0xC8, 0xF8, 0xE4, 0xF4, 0xFC, 0xFA, 0xE9, 0xD3, + 0xCD, 0xF1, 0xDD, 0xF7, 0xE5, 0xFF, 0xD4, 0xE2, + 0xD9, 0xD1, 0xD5, 0xF3, 0xE8, 0xC3, 0xDA, 0xD6, + 0xEA, 0xDB, 0xF0, 0xDE, 0xF9, 0xEE, 0xD0, 0xEC, + 0xC4, 0xEF, 0xFE, 0xE6, 0xFB, 0xDC, 0xC2, 0xC7, + 0xE1, 0xDF, 0xF6, 0xFD, 0xF5, 0xE7, 0xF2, 0xCF, + 0xCA, 0xED, 0xE3, 0xCE, 0xD2, 0xC6, 0xD7, 0xC1 +}; + + +enum libcharconv_result +libcharconv_yijing_hexagrams(const char *s, size_t slen, size_t *n, uint_least32_t *cp, size_t *ncp) +{ + uint_least32_t c; + size_t i; + *n = 0; + for (; slen--; s++) { + if ('1' <= s[0] && s[0] <= '2') { + if (slen == 0u) + return LIBCHARCONV_INDETERMINATE; + if ('1' > s[1] || s[1] > '2') + goto no_match; + if (slen == 1u) + return LIBCHARCONV_INDETERMINATE; + if ('1' > s[2] || s[2] > '2') + goto no_match; + if (slen == 2u) + return LIBCHARCONV_INDETERMINATE; + if ('1' > s[3] || s[3] > '2') + goto no_match; + if (slen == 3u) + return LIBCHARCONV_INDETERMINATE; + if ('1' > s[4] || s[4] > '2') + goto no_match; + if (slen == 4u) + return LIBCHARCONV_INDETERMINATE; + if ('1' > s[5] || s[5] > '2') + goto no_match; + i = s[5] == '2' ? 1u : 0u; + i |= s[4] == '2' ? 2u : 0u; + i |= s[3] == '2' ? 4u : 0u; + i |= s[2] == '2' ? 8u : 0u; + i |= s[1] == '2' ? 16u : 0u; + i |= s[0] == '2' ? 32u : 0u; + c = UINT32_C(0x4D00) | yijing_hexagrams[i]; + goto conv; + } else { + no_match: + *n += 1u; + } + } +no_conv: + return LIBCHARCONV_NO_CONVERT; + +conv: + if (*n) + goto no_conv; + if (*ncp) + *cp = c; + *n += 6u; + *ncp = 1u; + return LIBCHARCONV_CONVERTED; +} |
