/* See LICENSE file for copyright and license details. */ #include "lib-common.h" enum libcharconv_result libcharconv_clock_faces(const char *s, size_t slen, size_t *n, uint_least32_t *cp, size_t *ncp) { int num, thirty; *n = 0; for (; slen--; s++) { if ('0' <= s[0] && s[0] <= '9') { if (*n) goto no_conv; num = (int)(s[0] - '0'); if (!slen--) goto indeterminate; *n = 2u; if (s[1] == ':') goto conv; if ('0' > s[1] || s[1] > '9') goto no_conv; num *= 10; num += (int)(s[1] - '0'); if (!slen--) goto indeterminate; if (num > 24) goto no_conv; *n = 3u; if (s[2] == ':') goto conv; goto no_conv; } else { *n += 1u; } } no_conv: return LIBCHARCONV_NO_CONVERT; indeterminate: return LIBCHARCONV_INDETERMINATE; conv: if (!slen--) goto indeterminate; if (s[*n] == '3') thirty = 1; else if (s[*n] == '0') thirty = 0; else goto no_conv; if (!slen--) goto indeterminate; if (s[*n + 1u] != '0') goto no_conv; *n += 2u; if (num > (thirty ? 23 : 34)) goto no_conv; num %= 12; num = (!num ? 12 : num) - 1; num += 12 * thirty; if (*ncp) *cp = UINT32_C(0x1F550) + (uint_least32_t)num; *ncp = 1u; return LIBCHARCONV_CONVERTED; }