aboutsummaryrefslogtreecommitdiffstats
path: root/libcharconv_gothic.c
diff options
context:
space:
mode:
Diffstat (limited to 'libcharconv_gothic.c')
-rw-r--r--libcharconv_gothic.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/libcharconv_gothic.c b/libcharconv_gothic.c
new file mode 100644
index 0000000..61ec9a9
--- /dev/null
+++ b/libcharconv_gothic.c
@@ -0,0 +1,91 @@
+/* See LICENSE file for copyright and license details. */
+#include "lib-common.h"
+
+
+static struct {
+ unsigned char cp_low;
+ char latin;
+} gothic[] = {
+ {0x30, 'a'},
+ {0x31, 'b'},
+ {0x32, 'g'},
+ {0x32, 'G'},
+ {0x33, 'd'},
+ {0x33, 'D'},
+ {0x34, 'e'},
+ {0x35, 'q'},
+ {0x36, 'z'},
+ {0x37, 'h'},
+ {0x38, 'T'},
+ {0x39, 'i'},
+ {0x3A, 'k'},
+ {0x3B, 'l'},
+ {0x3C, 'm'},
+ {0x3D, 'n'},
+ {0x3E, 'j'},
+ {0x3F, 'u'},
+ {0x40, 'p'},
+ {0x42, 'r'},
+ {0x43, 's'},
+ {0x44, 't'},
+ {0x45, 'w'},
+ {0x45, 'y'},
+ {0x46, 'f'},
+ {0x47, 'x'},
+ {0x48, 'v'},
+ {0x48, 'W'},
+ {0x49, 'o'}
+};
+
+
+enum libcharconv_result
+libcharconv_gothic(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 && *s <= '9') {
+ if (*n)
+ goto no_conv;
+ c = UINT32_C(0x10330) + (uint_least32_t)(*s - '1');
+ *n = 1u;
+ if (slen == 0u)
+ goto convn_if_end;
+ if (s[1] != '0')
+ goto convn;
+ c += 9u;
+ *n += 1u;
+ if (slen == 1u)
+ goto convn_if_end;
+ if (s[2] == '0') {
+ c += 9u;
+ *n += 1u;
+ }
+ goto convn;
+ } else {
+ for (i = 0u; i < sizeof(gothic) / sizeof(*gothic); i++)
+ if (*s == gothic[i].latin)
+ goto conv;
+ *n += 1u;
+ }
+ }
+no_conv:
+ return LIBCHARCONV_NO_CONVERT;
+
+conv:
+ if (*n)
+ goto no_conv;
+ *n += 1u;
+ c = (uint_least32_t)(UINT32_C(0x10300) | gothic[i].cp_low);
+convn:
+ if (*ncp)
+ *cp = c;
+ *ncp = 1u;
+ return LIBCHARCONV_CONVERTED;
+convn_if_end:
+ if (*ncp)
+ *cp = c;
+ *ncp = 1u;
+ return LIBCHARCONV_CONVERT_IF_END;
+}