aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2026-01-26 20:47:06 +0100
committerMattias Andrée <m@maandree.se>2026-01-26 20:47:06 +0100
commit606483d647c3167f4db87d43ff94c797ca711b03 (patch)
tree5bc743a9d6adca5bbbded56f5c896fa260ab7d8f
parentAdd stacked (diff)
downloadcharconv-606483d647c3167f4db87d43ff94c797ca711b03.tar.gz
charconv-606483d647c3167f4db87d43ff94c797ca711b03.tar.bz2
charconv-606483d647c3167f4db87d43ff94c797ca711b03.tar.xz
Add counting rods
Signed-off-by: Mattias Andrée <m@maandree.se>
-rw-r--r--Makefile6
-rw-r--r--convert-to-counting-rods.c4
-rw-r--r--libcharconv.h5
-rw-r--r--libcharconv_counting_rods.c52
-rw-r--r--libcharconv_latin.c11
5 files changed, 76 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index daa284e..20bd984 100644
--- a/Makefile
+++ b/Makefile
@@ -85,7 +85,8 @@ BIN =\
convert-to-metrical\
convert-to-dentistry\
convert-to-cards\
- convert-to-stacked
+ convert-to-stacked\
+ convert-to-counting-rods
LIBOBJ =\
libcharconv_decode_utf8_.o\
@@ -163,7 +164,8 @@ LIBOBJ =\
libcharconv_metrical.o\
libcharconv_dentistry.o\
libcharconv_cards.o\
- libcharconv_stacked.o
+ libcharconv_stacked.o\
+ libcharconv_counting_rods.o
LOBJ = $(LIBOBJ:.o=.lo)
diff --git a/convert-to-counting-rods.c b/convert-to-counting-rods.c
new file mode 100644
index 0000000..19b9aa9
--- /dev/null
+++ b/convert-to-counting-rods.c
@@ -0,0 +1,4 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+SIMPLE(libcharconv_counting_rods)
diff --git a/libcharconv.h b/libcharconv.h
index 5d93d41..93471ac 100644
--- a/libcharconv.h
+++ b/libcharconv.h
@@ -501,6 +501,11 @@ LIBCHARCONV_FUNC_(libcharconv_cards);
*/
LIBCHARCONV_FUNC_(libcharconv_stacked);
+/**
+ * Convert DIGITs to COUNTING RODs
+ */
+LIBCHARCONV_FUNC_(libcharconv_counting_rods);
+
#undef LIBCHARCONV_FUNC_
#endif
diff --git a/libcharconv_counting_rods.c b/libcharconv_counting_rods.c
new file mode 100644
index 0000000..f50433c
--- /dev/null
+++ b/libcharconv_counting_rods.c
@@ -0,0 +1,52 @@
+/* See LICENSE file for copyright and license details. */
+#include "lib-common.h"
+
+
+enum libcharconv_result
+libcharconv_counting_rods(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++) {
+ if ('1' <= *s && *s <= '9') {
+ c = UINT32_C(0x13D60) + (unsigned)(*s - '1');
+ if (!slen)
+ goto conv_if_end;
+ if (s[1] != '0')
+ goto conv1;
+ c += 9u;
+ goto conv2;
+ } else {
+ *n += 1u;
+ }
+ }
+no_conv:
+ return LIBCHARCONV_NO_CONVERT;
+
+conv_if_end:
+ if (*n)
+ goto no_conv;
+ if (*ncp)
+ *cp = c;
+ *n += 1u;
+ *ncp = 1u;
+ return LIBCHARCONV_CONVERT_IF_END;
+
+conv1:
+ if (*n)
+ goto no_conv;
+ if (*ncp)
+ *cp = c;
+ *n += 1u;
+ *ncp = 1u;
+ return LIBCHARCONV_CONVERTED;
+
+conv2:
+ if (*n)
+ goto no_conv;
+ if (*ncp)
+ *cp = c;
+ *n += 2u;
+ *ncp = 1u;
+ return LIBCHARCONV_CONVERTED;
+}
diff --git a/libcharconv_latin.c b/libcharconv_latin.c
index f441d0c..5e050f0 100644
--- a/libcharconv_latin.c
+++ b/libcharconv_latin.c
@@ -605,6 +605,17 @@ libcharconv_latin(const char *s, size_t slen, size_t *n, uint_least32_t *cp, siz
c1 = '1';
goto conv3;
+ } else if (UINT32_C(0x13D60) <= c && c <= UINT32_C(0x13D68)) {
+ /* counting rods */
+ c -= (uint_least32_t)UINT32_C(0x13D60) - (uint_least32_t)'1';
+ goto conv;
+ } else if (UINT32_C(0x13D69) <= c && c <= UINT32_C(0x13D71)) {
+ /* counting rods */
+ c -= (uint_least32_t)UINT32_C(0x13D69) - (uint_least32_t)'1';
+ c1 = (char)c;
+ c2 = '0';
+ goto conv2;
+
} else {
use_switch:
switch (c) {