+#include "collate.h"
+
+static int
+CHIN1(cs, ch, loc)
+cset *cs;
+wint_t ch;
+locale_t loc;
+{
+ int i;
+
+ assert(ch >= 0);
+ for (i = 0; i < cs->nequiv_classes; i++)
+ /* sadly, we can only deal with single characters from an
+ * equivalence class */
+ if (__collate_equiv_match(cs->equiv_classes[i], NULL, 0, ch, NULL, 0, NULL, NULL, loc) > 0)
+ return (!cs->invert);
+ if (ch < NC)
+ return (((cs->bmp[ch >> 3] & (1 << (ch & 7))) != 0) ^
+ cs->invert);
+ for (i = 0; i < cs->nwides; i++)
+ if (ch == cs->wides[i])
+ return (!cs->invert);
+ for (i = 0; i < cs->nranges; i++)
+ if (cs->ranges[i].min <= ch && ch <= cs->ranges[i].max)
+ return (!cs->invert);
+ for (i = 0; i < cs->ntypes; i++)
+ if (iswctype_l(ch, cs->types[i], loc))
+ return (!cs->invert);
+ return (cs->invert);
+}
+
+static __inline int
+CHIN(cs, ch, loc)
+cset *cs;
+wint_t ch;
+locale_t loc;
+{
+
+ assert(ch >= 0);
+ if (ch < NC && cs->nequiv_classes == 0)
+ return (((cs->bmp[ch >> 3] & (1 << (ch & 7))) != 0) ^
+ cs->invert);
+ else if (cs->icase)
+ return (CHIN1(cs, ch, loc) || CHIN1(cs, towlower_l(ch, loc), loc) ||
+ CHIN1(cs, towupper_l(ch, loc), loc));
+ else
+ return (CHIN1(cs, ch, loc));
+}