diff options
| author | Mattias Andrée <m@maandree.se> | 2026-01-26 20:35:11 +0100 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-01-26 20:35:11 +0100 |
| commit | e4e8b674cc75b545bb30045f73484c6011efe1de (patch) | |
| tree | 5e731946b1d44fc2a7e9c48bb21b5319e11cfc6c | |
| parent | Add cards (diff) | |
| download | charconv-e4e8b674cc75b545bb30045f73484c6011efe1de.tar.gz charconv-e4e8b674cc75b545bb30045f73484c6011efe1de.tar.bz2 charconv-e4e8b674cc75b545bb30045f73484c6011efe1de.tar.xz | |
Add stacked
Signed-off-by: Mattias Andrée <m@maandree.se>
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | convert-to-stacked.c | 4 | ||||
| -rw-r--r-- | libcharconv.h | 5 | ||||
| -rw-r--r-- | libcharconv_latin.c | 4 | ||||
| -rw-r--r-- | libcharconv_stacked.c | 66 |
5 files changed, 83 insertions, 2 deletions
@@ -84,7 +84,8 @@ BIN =\ convert-to-enclosed\ convert-to-metrical\ convert-to-dentistry\ - convert-to-cards + convert-to-cards\ + convert-to-stacked LIBOBJ =\ libcharconv_decode_utf8_.o\ @@ -161,7 +162,8 @@ LIBOBJ =\ libcharconv_enclosed_negative.o\ libcharconv_metrical.o\ libcharconv_dentistry.o\ - libcharconv_cards.o + libcharconv_cards.o\ + libcharconv_stacked.o LOBJ = $(LIBOBJ:.o=.lo) diff --git a/convert-to-stacked.c b/convert-to-stacked.c new file mode 100644 index 0000000..119655f --- /dev/null +++ b/convert-to-stacked.c @@ -0,0 +1,4 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +SIMPLE(libcharconv_stacked) diff --git a/libcharconv.h b/libcharconv.h index 8e5e1a6..5d93d41 100644 --- a/libcharconv.h +++ b/libcharconv.h @@ -496,6 +496,11 @@ LIBCHARCONV_FUNC_(libcharconv_dentistry); */ LIBCHARCONV_FUNC_(libcharconv_cards); +/** + * Stack characters vertically + */ +LIBCHARCONV_FUNC_(libcharconv_stacked); + #undef LIBCHARCONV_FUNC_ #endif diff --git a/libcharconv_latin.c b/libcharconv_latin.c index 473896a..f441d0c 100644 --- a/libcharconv_latin.c +++ b/libcharconv_latin.c @@ -1070,6 +1070,10 @@ libcharconv_latin(const char *s, size_t slen, size_t *n, uint_least32_t *cp, siz case UINT32_C(0x2666): c1 = 'D'; goto conv1; case UINT32_C(0x2667): c1 = 'c'; goto conv1; + /* stacked */ + case UINT32_C(0x2051): c1 = '*'; c2 = '*'; goto conv2; + case UINT32_C(0x2E49): c1 = ','; c2 = ','; goto conv2; + default: no_match: *n += clen; diff --git a/libcharconv_stacked.c b/libcharconv_stacked.c new file mode 100644 index 0000000..6f89834 --- /dev/null +++ b/libcharconv_stacked.c @@ -0,0 +1,66 @@ +/* See LICENSE file for copyright and license details. */ +#include "lib-common.h" + + +static struct { + uint_least32_t a; + uint_least32_t b; + uint_least32_t to; +} pairs[] = { + {(uint_least32_t)'*', (uint_least32_t)'*', UINT32_C(0x2051)}, + {(uint_least32_t)',', (uint_least32_t)',', UINT32_C(0x2E49)} +}; + + +enum libcharconv_result +libcharconv_stacked(const char *s, size_t slen, size_t *n, uint_least32_t *cp, size_t *ncp) +{ + uint_least32_t a, b; + size_t i, alen, blen; + *n = 0; + while (slen) { + alen = libcharconv_decode_utf8_(s, slen, &a); + if (alen > slen) { + if (*n) + goto no_conv; + return LIBCHARCONV_INDETERMINATE; + } + if (!alen) { + *n += 1u; + slen -= 1u; + s = &s[1]; + continue; + } + + for (i = 0u; i < sizeof(pairs) / sizeof(*pairs); i++) { + if (a != pairs[i].a) + continue; + if (*n) + goto no_conv; + if (slen == alen) + return LIBCHARCONV_INDETERMINATE; + blen = libcharconv_decode_utf8_(&s[alen], slen - alen, &b); + if (blen > slen) + return LIBCHARCONV_INDETERMINATE; + if (!blen) + goto no_conv; + if (b == pairs[i].b) + goto conv; + } + + *n += alen; + s = &s[alen]; + slen -= alen; + } +no_conv: + return LIBCHARCONV_NO_CONVERT; + +conv: + if (*n) + goto no_conv; + if (*ncp) + *cp = pairs[i].to; + *n += alen + blen; + *ncp = 1u; + return LIBCHARCONV_CONVERTED; +} |
