/* See LICENSE file for copyright and license details. */ #include "lib-common.h" enum libcharconv_result libcharconv_mahjong_tiles(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++, ++*n) { PLAIN_CASE_SELECT("pobc", 0x1F022); PLAIN_CASE_SELECT("j#", 0x1F02A); if (tolower(s[0]) == 'e') { if (!slen) goto indeterminate; if (tolower(s[1]) == 'w') { c = UINT32_C(0x1F000); goto conv2; } goto no_conv; } if (tolower(s[0]) == 's') { if (!slen) goto indeterminate; if (tolower(s[1]) == 'w') { c = UINT32_C(0x1F001); goto conv2; } else if (tolower(s[1]) == 'p') { c = UINT32_C(0x1F026); goto conv2; } else if (tolower(s[1]) == 'u') { c = UINT32_C(0x1F027); goto conv2; } goto no_conv; } if (tolower(s[0]) == 'w') { if (!slen) goto indeterminate; if (tolower(s[1]) == 'w') { c = UINT32_C(0x1F002); goto conv2; } else if (tolower(s[1]) == 'd') { c = UINT32_C(0x1F006); goto conv2; } else if (tolower(s[1]) == 'i') { c = UINT32_C(0x1F029); goto conv2; } goto no_conv; } if (tolower(s[0]) == 'n') { if (!slen) goto indeterminate; if (tolower(s[1]) == 'w') { c = UINT32_C(0x1F003); goto conv2; } goto no_conv; } if (tolower(s[0]) == 'r') { if (!slen) goto indeterminate; if (tolower(s[1]) == 'd') { c = UINT32_C(0x1F004); goto conv2; } goto no_conv; } if (tolower(s[0]) == 'g') { if (!slen) goto indeterminate; if (tolower(s[1]) == 'd') { c = UINT32_C(0x1F005); goto conv2; } goto no_conv; } if (tolower(s[0]) == 'a') { if (!slen) goto indeterminate; if (tolower(s[1]) == 'u') { c = UINT32_C(0x1F028); goto conv2; } goto no_conv; } if ('1' <= s[0] && s[0] <= '9') { if (!slen) goto indeterminate; if (tolower(s[1]) == 'c') c = UINT32_C(0x1F007); else if (tolower(s[1]) == 'b') c = UINT32_C(0x1F010); else if (tolower(s[1]) == 'o') c = UINT32_C(0x1F019); else goto no_conv; c += (uint_least32_t)(s[0] - '1'); goto conv2; } } return LIBCHARCONV_NO_CONVERT; no_conv: *n += 1u; return LIBCHARCONV_NO_CONVERT; indeterminate: if (*n) goto no_conv; return LIBCHARCONV_INDETERMINATE; 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; }