11 #define LONG_BIT (CHAR_BIT*sizeof(long))
15 set_bit(unsigned long *bitmap, unsigned int bit)
17 bitmap[bit/LONG_BIT] |= 1UL << (bit%LONG_BIT);
21 test_bit(unsigned long *bitmap, unsigned int bit)
23 return (int)(bitmap[bit/LONG_BIT] >> (bit%LONG_BIT)) & 1;
27 strxspn(const char *s, const char *map, int parity)
29 unsigned long matchmap[((1 << CHAR_BIT)+LONG_BIT-1)/LONG_BIT];
33 memset(matchmap, 0, sizeof matchmap);
35 set_bit(matchmap, (unsigned char) *map++);
37 /* Make sure the null character never matches */
41 /* Calculate span length */
42 while ( test_bit(matchmap, (unsigned char) *s++)^parity )
49 strspn(const char *s, const char *accept)
51 return strxspn(s, accept, 0);
55 strcspn(const char *s, const char *reject)
57 return strxspn(s, reject, 1);
61 strpbrk(const char *s, const char *accept)
63 const char *ss = s+strxspn(s, accept, 1);
65 return *ss ? (char *)ss : NULL;