/* See LICENSE file for copyright and license details. */ #include "lib-common.h" static struct { uint_least32_t a; uint_least32_t b; } pairs[] = { {0x2032, 0x2035}, {0x2033, 0x2036}, {0x2034, 0x2037}, {0x204F, 0x003B}, {0x2E2E, 0x003F}, {0x2143, 0x004C}, {UINT32_C(0xA4ED), (uint_least32_t)'B'}, {UINT32_C(0xA4DB), (uint_least32_t)'C'}, {UINT32_C(0xA4F7), (uint_least32_t)'D'}, {UINT32_C(0xA4F1), (uint_least32_t)'E'}, {UINT32_C(0xA4D8), (uint_least32_t)'K'}, {UINT32_C(0x1F12F), UINT32_C(0x00A9)} }; enum libcharconv_result libcharconv_mirrored(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; } if (UINT32_C(0x1F031) <= c && c <= UINT32_C(0x1F061)) { c -= UINT32_C(0x1F031); c = c % 7u * 7u + c / 7u; c += UINT32_C(0x1F031); goto conv; } else { 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; }