1 | /*␊ |
2 | * strpbrk␊ |
3 | */␊ |
4 | ␊ |
5 | #include <limits.h>␊ |
6 | #include "strxspn.h"␊ |
7 | ␊ |
8 | size_t __strxspn(const char *s, const char *map, int parity)␊ |
9 | {␊ |
10 | ␉char matchmap[UCHAR_MAX + 1];␊ |
11 | ␉size_t n = 0;␊ |
12 | ␊ |
13 | ␉/* Create bitmap */␊ |
14 | ␉memset(matchmap, 0, sizeof matchmap);␊ |
15 | ␉while (*map)␊ |
16 | ␉␉matchmap[(unsigned char)*map++] = 1;␊ |
17 | ␊ |
18 | ␉/* Make sure the null character never matches */␊ |
19 | ␉matchmap[0] = parity;␊ |
20 | ␊ |
21 | ␉/* Calculate span length */␊ |
22 | ␉while (matchmap[(unsigned char)*s++] ^ parity)␊ |
23 | ␉␉n++;␊ |
24 | ␊ |
25 | ␉return n;␊ |
26 | }␊ |
27 | |