aboutsummaryrefslogtreecommitdiffstats
path: root/lib-common.h
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2026-01-28 22:03:48 +0100
committerMattias Andrée <m@maandree.se>2026-01-28 22:03:48 +0100
commit40bf70fb8f23e5ff7212b568c69e0725372e5b57 (patch)
tree0d4be706d0182ddeafd4eaafd073e12c2fa2a9e8 /lib-common.h
parentMisc stuff (diff)
downloadcharconv-40bf70fb8f23e5ff7212b568c69e0725372e5b57.tar.gz
charconv-40bf70fb8f23e5ff7212b568c69e0725372e5b57.tar.bz2
charconv-40bf70fb8f23e5ff7212b568c69e0725372e5b57.tar.xz
Clean up
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'lib-common.h')
-rw-r--r--lib-common.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/lib-common.h b/lib-common.h
index eb8cab9..2ab89a0 100644
--- a/lib-common.h
+++ b/lib-common.h
@@ -1,7 +1,97 @@
/* See LICENSE file for copyright and license details. */
#include "libcharconv.h"
+#include <ctype.h>
#include <string.h>
#include <strings.h>
size_t libcharconv_decode_utf8_(const char *s, size_t slen, uint_least32_t *cp);
+
+extern const unsigned char libcharconv_yijing_hexagrams_[];
+
+
+#define CYCLE_2(A, B)\
+ {UINT32_C(A), UINT32_C(B)},\
+ {UINT32_C(B), UINT32_C(A)}
+
+#define CYCLE_4(A, B, C, D)\
+ {UINT32_C(A), UINT32_C(B)},\
+ {UINT32_C(B), UINT32_C(C)},\
+ {UINT32_C(C), UINT32_C(D)},\
+ {UINT32_C(D), UINT32_C(A)}
+
+#define CYCLE_8(A, B, C, D, E, F, G, H)\
+ {UINT32_C(A), UINT32_C(B)},\
+ {UINT32_C(B), UINT32_C(C)},\
+ {UINT32_C(C), UINT32_C(D)},\
+ {UINT32_C(D), UINT32_C(E)},\
+ {UINT32_C(E), UINT32_C(F)},\
+ {UINT32_C(F), UINT32_C(G)},\
+ {UINT32_C(G), UINT32_C(H)},\
+ {UINT32_C(H), UINT32_C(A)}
+
+
+#define PLAIN_RANGE(FIRST, LAST, FIRST_CP)\
+ do {\
+ if ((FIRST) <= *s && *s <= (LAST)) { \
+ c = (uint_least32_t)(UINT32_C(FIRST_CP) + (unsigned)(*s - (FIRST)));\
+ goto conv;\
+ }\
+ } while (0)
+
+#define PLAIN_CASE_RANGE(FIRST, LAST, FIRST_CP)\
+ do {\
+ if (tolower(FIRST) <= tolower(*s) && tolower(*s) <= tolower(LAST)) { \
+ c = (uint_least32_t)(UINT32_C(FIRST_CP) + (unsigned)(tolower(*s) - tolower(FIRST)));\
+ goto conv;\
+ }\
+ } while (0)
+
+#define PLAIN_SINGLE(C, CP)\
+ do {\
+ if (*s == (C)) {\
+ c = (uint_least32_t)UINT32_C(CP);\
+ goto conv;\
+ }\
+ } while (0)
+
+#define PLAIN_CASE_SINGLE(C, CP)\
+ do {\
+ if (*s == tolower(C) || *s == toupper(C)) {\
+ c = (uint_least32_t)UINT32_C(CP);\
+ goto conv;\
+ }\
+ } while (0)
+
+#define PLAIN_SELECT(CS, FIRST_CP)\
+ do {\
+ size_t i__;\
+ for (i__ = 0u; (CS)[i__]; i__++) {\
+ if (*s == (CS)[i__]) {\
+ c = (uint_least32_t)(UINT32_C(FIRST_CP) + i__);\
+ goto conv;\
+ }\
+ }\
+ } while (0)
+
+#define PLAIN_CASE_SELECT(CS, FIRST_CP)\
+ do {\
+ size_t i__;\
+ for (i__ = 0u; (CS)[i__]; i__++) {\
+ if (*s == tolower((CS)[i__]) || *s == toupper((CS)[i__])) {\
+ c = (uint_least32_t)(UINT32_C(FIRST_CP) + i__); \
+ goto conv;\
+ }\
+ }\
+ } while (0)
+
+#define PLAIN_RANGE_SWAP(LOW_FIRST, LOW_LAST, HIGH_FIRST, HIGH_LAST)\
+ do {\
+ if (UINT32_C(LOW_FIRST) <= c && c <= UINT32_C(LOW_LAST)) {\
+ c += UINT32_C(HIGH_FIRST) - UINT32_C(LOW_FIRST);\
+ goto conv;\
+ } else if (UINT32_C(HIGH_FIRST) <= c && c <= UINT32_C(HIGH_LAST)) {\
+ c -= UINT32_C(HIGH_FIRST) - UINT32_C(LOW_FIRST);\
+ goto conv;\
+ }\
+ } while (0)