aboutsummaryrefslogtreecommitdiffstats
path: root/libcharconv_domino_tiles_horizontal.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libcharconv_domino_tiles_horizontal.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/libcharconv_domino_tiles_horizontal.c b/libcharconv_domino_tiles_horizontal.c
new file mode 100644
index 0000000..5edf493
--- /dev/null
+++ b/libcharconv_domino_tiles_horizontal.c
@@ -0,0 +1,85 @@
+/* See LICENSE file for copyright and license details. */
+#include "lib-common.h"
+
+
+enum libcharconv_result
+libcharconv_domino_tiles_horizontal(const char *s, size_t slen, size_t *n, uint_least32_t *cp, size_t *ncp)
+{
+ uint_least32_t c;
+ int vertical;
+ *n = 0;
+ for (; slen--; s++) {
+ if ('0' <= s[0] && s[0] <= '6') {
+ if (!slen--)
+ return LIBCHARCONV_INDETERMINATE;
+ vertical = 0;
+ if (s[1] == '|')
+ vertical = 0;
+ else if (s[1] == '-')
+ vertical = 1;
+ else if ('0' <= s[1] && s[1] <= '6')
+ goto conv2;
+ else
+ goto no_match;
+ if (!slen--)
+ return LIBCHARCONV_INDETERMINATE;
+ if ('0' <= s[2] && s[2] <= '6')
+ goto conv3;
+ goto no_match;
+ } else if (s[0] == '#') {
+ if (!slen--)
+ return LIBCHARCONV_INDETERMINATE;
+ vertical = 0;
+ if (s[1] == '|')
+ vertical = 0;
+ else if (s[1] == '-')
+ vertical = 1;
+ else if (s[1] == '#')
+ goto conv2;
+ else
+ goto no_match;
+ if (!slen--)
+ return LIBCHARCONV_INDETERMINATE;
+ if (s[2] == '#')
+ goto conv3;
+ goto no_match;
+ } else {
+ no_match:
+ *n += 1u;
+ }
+ }
+no_conv:
+ return LIBCHARCONV_NO_CONVERT;
+
+conv2:
+ if (*n)
+ goto no_conv;
+ if (*ncp) {
+ if (s[0] == '#')
+ c = UINT32_C(0x1F030);
+ else
+ c = UINT32_C(0x1F031) + (unsigned)(s[0] - '0') * 7u + (unsigned)(s[1] - '0');
+ if (vertical)
+ c += UINT32_C(0x1F062) - UINT32_C(0x1F030);
+ *cp = c;
+ }
+ *n += 2u;
+ *ncp = 1u;
+ return LIBCHARCONV_CONVERTED;
+
+conv3:
+ if (*n)
+ goto no_conv;
+ if (*ncp) {
+ if (s[0] == '#')
+ c = UINT32_C(0x1F030);
+ else
+ c = UINT32_C(0x1F031) + (unsigned)(s[0] - '0') * 7u + (unsigned)(s[2] - '0');
+ if (vertical)
+ c += UINT32_C(0x1F062) - UINT32_C(0x1F030);
+ *cp = c;
+ }
+ *n += 3u;
+ *ncp = 1u;
+ return LIBCHARCONV_CONVERTED;
+}