/* See LICENSE file for copyright and license details. */ #include "lib-common.h" static struct { uint_least32_t a; uint_least32_t b; } pairs[] = { {UINT32_C(0x0020), UINT32_C(0x2588)}, {UINT32_C(0x1FBA3), UINT32_C(0x1FBBE)}, {UINT32_C(0x1FBAE), UINT32_C(0x1FBBF)}, {UINT32_C(0x1FBBD), UINT32_C(0x2573)}, {UINT32_C(0x1F030), UINT32_C(0x1F031)}, {UINT32_C(0x1F062), UINT32_C(0x1F063)}, {UINT32_C(0x2686), UINT32_C(0x2688)}, {UINT32_C(0x2687), UINT32_C(0x2689)}, {UINT32_C(0x2616), UINT32_C(0x26C9)}, {UINT32_C(0x2617), UINT32_C(0x26CA)}, {UINT32_C(0x26C0), UINT32_C(0x26C2)}, {UINT32_C(0x26C1), UINT32_C(0x26C3)}, {UINT32_C(0x1FA06), UINT32_C(0x1FA07)}, {UINT32_C(0x1FA1B), UINT32_C(0x1FA1C)}, {UINT32_C(0x1FA30), UINT32_C(0x1FA31)}, {UINT32_C(0x1FA45), UINT32_C(0x1FA46)}, {UINT32_C(0x1FA48), UINT32_C(0x1FA49)}, {UINT32_C(0x1FA4B), UINT32_C(0x1FA4C)}, {UINT32_C(0x24EA), UINT32_C(0x24FF)}, {UINT32_C(0x1F10B), UINT32_C(0x1F10C)}, {UINT32_C(0x2690), UINT32_C(0x2691)}, {UINT32_C(0x1F3F3), UINT32_C(0x1F3F4)}, {UINT32_C(0x1F3F1), UINT32_C(0x1F3F2)} }; static struct { struct {uint_least32_t low, high;} low, high; } range_pairs[] = { {{UINT32_C(0x2654), UINT32_C(0x2659)}, {UINT32_C(0x265A), UINT32_C(0x265F)}}, {{UINT32_C(0x1FA60), UINT32_C(0x1FA66)}, {UINT32_C(0x1FA67), UINT32_C(0x1FA6D)}}, {{UINT32_C(0x1FA09), UINT32_C(0x1FA0E)}, {UINT32_C(0x1FA0F), UINT32_C(0x1FA14)}}, {{UINT32_C(0x1FA1E), UINT32_C(0x1FA23)}, {UINT32_C(0x1FA24), UINT32_C(0x1FA29)}}, {{UINT32_C(0x1FA33), UINT32_C(0x1FA38)}, {UINT32_C(0x1FA39), UINT32_C(0x1FA3E)}}, {{UINT32_C(0x1FA4E), UINT32_C(0x1FA50)}, {UINT32_C(0x1FA51), UINT32_C(0x1FA53)}}, {{UINT32_C(0x2460), UINT32_C(0x2469)}, {UINT32_C(0x2776), UINT32_C(0x277F)}}, {{UINT32_C(0x246A), UINT32_C(0x2473)}, {UINT32_C(0x24EB), UINT32_C(0x24F4)}}, {{UINT32_C(0x24B6), UINT32_C(0x24CF)}, {UINT32_C(0x1F150), UINT32_C(0x1F169)}}, {{UINT32_C(0x1F130), UINT32_C(0x1F149)}, {UINT32_C(0x1F170), UINT32_C(0x1F189)}}, {{UINT32_C(0x2780), UINT32_C(0x2789)}, {UINT32_C(0x278A), UINT32_C(0x2793)}}, {{UINT32_C(0x2660), UINT32_C(0x2663)}, {UINT32_C(0x2664), UINT32_C(0x2667)}} }; enum libcharconv_result libcharconv_negative(const char *s, size_t slen, size_t *n, uint_least32_t *cp, size_t *ncp) { uint_least32_t c; size_t i, clen; *n = 0; while (slen) { clen = libcharconv_decode_utf8_(s, slen, &c); if (clen > slen) { if (*n) goto no_conv; return LIBCHARCONV_INDETERMINATE; } if (!clen) { *n += 1u; slen -= 1u; s = &s[1]; continue; } for (i = 0u; i < sizeof(range_pairs) / sizeof(*range_pairs); i++) { if (range_pairs[i].low.low <= c && c <= range_pairs[i].low.high) { c += range_pairs[i].high.low - range_pairs[i].low.low; goto conv; } if (range_pairs[i].high.low <= c && c <= range_pairs[i].high.high) { c -= range_pairs[i].high.low - range_pairs[i].low.low; goto conv; } } for (i = 0u; i < sizeof(pairs) / sizeof(*pairs); i++) { if (c == pairs[i].a) { c = pairs[i].b; goto conv; } if (c == pairs[i].b) { c = pairs[i].a; goto conv; } } *n += clen; s = &s[clen]; slen -= clen; } no_conv: return LIBCHARCONV_NO_CONVERT; conv: if (*n) goto no_conv; if (*ncp) *cp = c; *n += clen; *ncp = 1u; return LIBCHARCONV_CONVERTED; }