/* See LICENSE file for copyright and license details. */ #include "libcharconv.h" #include #include #include size_t libcharconv_decode_utf8_(const char *s, size_t slen, uint_least32_t *cp); extern const unsigned char libcharconv_yijing_hexagrams_[]; #define CYCLE_2(A, B)\ {UINT32_C(A), UINT32_C(B)},\ {UINT32_C(B), UINT32_C(A)} #define CYCLE_4(A, B, C, D)\ {UINT32_C(A), UINT32_C(B)},\ {UINT32_C(B), UINT32_C(C)},\ {UINT32_C(C), UINT32_C(D)},\ {UINT32_C(D), UINT32_C(A)} #define CYCLE_8(A, B, C, D, E, F, G, H)\ {UINT32_C(A), UINT32_C(B)},\ {UINT32_C(B), UINT32_C(C)},\ {UINT32_C(C), UINT32_C(D)},\ {UINT32_C(D), UINT32_C(E)},\ {UINT32_C(E), UINT32_C(F)},\ {UINT32_C(F), UINT32_C(G)},\ {UINT32_C(G), UINT32_C(H)},\ {UINT32_C(H), UINT32_C(A)} #define PLAIN_RANGE(FIRST, LAST, FIRST_CP)\ do {\ if ((FIRST) <= *s && *s <= (LAST)) { \ c = (uint_least32_t)(UINT32_C(FIRST_CP) + (unsigned)(*s - (FIRST)));\ goto conv;\ }\ } while (0) #define PLAIN_CASE_RANGE(FIRST, LAST, FIRST_CP)\ do {\ if (tolower(FIRST) <= tolower(*s) && tolower(*s) <= tolower(LAST)) { \ c = (uint_least32_t)(UINT32_C(FIRST_CP) + (unsigned)(tolower(*s) - tolower(FIRST)));\ goto conv;\ }\ } while (0) #define PLAIN_SINGLE(C, CP)\ do {\ if (*s == (C)) {\ c = (uint_least32_t)UINT32_C(CP);\ goto conv;\ }\ } while (0) #define PLAIN_CASE_SINGLE(C, CP)\ do {\ if (*s == tolower(C) || *s == toupper(C)) {\ c = (uint_least32_t)UINT32_C(CP);\ goto conv;\ }\ } while (0) #define PLAIN_SELECT(CS, FIRST_CP)\ do {\ size_t i__;\ for (i__ = 0u; (CS)[i__]; i__++) {\ if (*s == (CS)[i__]) {\ c = (uint_least32_t)(UINT32_C(FIRST_CP) + i__);\ goto conv;\ }\ }\ } while (0) #define PLAIN_CASE_SELECT(CS, FIRST_CP)\ do {\ size_t i__;\ for (i__ = 0u; (CS)[i__]; i__++) {\ if (*s == tolower((CS)[i__]) || *s == toupper((CS)[i__])) {\ c = (uint_least32_t)(UINT32_C(FIRST_CP) + i__); \ goto conv;\ }\ }\ } while (0) #define PLAIN_RANGE_SWAP(LOW_FIRST, LOW_LAST, HIGH_FIRST, HIGH_LAST)\ do {\ if (UINT32_C(LOW_FIRST) <= c && c <= UINT32_C(LOW_LAST)) {\ c += UINT32_C(HIGH_FIRST) - UINT32_C(LOW_FIRST);\ goto conv;\ } else if (UINT32_C(HIGH_FIRST) <= c && c <= UINT32_C(HIGH_LAST)) {\ c -= UINT32_C(HIGH_FIRST) - UINT32_C(LOW_FIRST);\ goto conv;\ }\ } while (0)