aboutsummaryrefslogtreecommitdiffstats
path: root/libcharconv_dentistry.c
diff options
context:
space:
mode:
Diffstat (limited to 'libcharconv_dentistry.c')
-rw-r--r--libcharconv_dentistry.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/libcharconv_dentistry.c b/libcharconv_dentistry.c
new file mode 100644
index 0000000..e3f463e
--- /dev/null
+++ b/libcharconv_dentistry.c
@@ -0,0 +1,61 @@
+/* See LICENSE file for copyright and license details. */
+#include "lib-common.h"
+
+
+enum libcharconv_result
+libcharconv_dentistry(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 'o':
+ case 'O': c = UINT32_C(0x23C0); goto conv;
+ case 'a':
+ case 'A': c = UINT32_C(0x23C3); goto conv;
+ case '~': c = UINT32_C(0x23C6); goto conv;
+ case 'l': c = UINT32_C(0x23BF); goto conv;
+ case 'j': c = UINT32_C(0x23CC); goto conv;
+ case 't': c = UINT32_C(0x23CA); goto conv;
+ case 'L': c = UINT32_C(0x23BE); goto conv;
+ case 'J': c = UINT32_C(0x23CB); goto conv;
+ case 'T': c = UINT32_C(0x23C9); goto conv;
+ case '-':
+ case '_':
+ if (!slen)
+ return LIBCHARCONV_INDETERMINATE;
+ if (s[1] != 'A' && s[1] != 'O' && s[1] != '~')
+ if (s[1] != 'a' && s[1] != 'o')
+ goto no_match;
+ c = (s[1] == 'A' || s[1] == 'a') ? UINT32_C(0x23C1) :
+ (s[1] == 'O' || s[1] == 'o') ? UINT32_C(0x23C4) : UINT32_C(0x23C7);
+ if (s[0] == '_')
+ c += 1u;
+ goto conv2;
+ default:
+ no_match:
+ *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;
+
+conv2:
+ if (*n)
+ goto no_conv;
+ if (*ncp)
+ *cp = c;
+ *n += 2u;
+ *ncp = 1u;
+ return LIBCHARCONV_CONVERTED;
+}