diff options
| author | Mattias Andrée <m@maandree.se> | 2026-01-25 17:23:41 +0100 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-01-25 17:23:41 +0100 |
| commit | 2707fbda25ae9554280111ea2f5999e2feac4b20 (patch) | |
| tree | fa85500503c700e78d6d27c1cfa5d6f8312a409d /libcharconv_tally_marks.c | |
| parent | Add sora sompeng (diff) | |
| download | charconv-2707fbda25ae9554280111ea2f5999e2feac4b20.tar.gz charconv-2707fbda25ae9554280111ea2f5999e2feac4b20.tar.bz2 charconv-2707fbda25ae9554280111ea2f5999e2feac4b20.tar.xz | |
Add tally marks and ideographic tally marks
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'libcharconv_tally_marks.c')
| -rw-r--r-- | libcharconv_tally_marks.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libcharconv_tally_marks.c b/libcharconv_tally_marks.c new file mode 100644 index 0000000..e94f48d --- /dev/null +++ b/libcharconv_tally_marks.c @@ -0,0 +1,30 @@ +/* See LICENSE file for copyright and license details. */ +#include "lib-common.h" + + +enum libcharconv_result +libcharconv_tally_marks(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++) { + switch (*s) { + case '1': c = UINT32_C(0x13D77); goto conv; + case '5': c = UINT32_C(0x13D78); goto conv; + default: + *n += 1u; + break; + } + } +no_conv: + return LIBCHARCONV_NO_CONVERT; + +conv: + if (*n) + goto no_conv; + if (*ncp) + *cp = c; + *n += 1u; + *ncp = 1u; + return LIBCHARCONV_CONVERTED; +} |
