scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

strspn.c (322B)


      1 #include <string.h>
      2 
      3 #undef strspn
      4 
      5 size_t
      6 strspn(const char *s1, const char *s2)
      7 {
      8 	const unsigned char *s = s1;
      9 	const unsigned char *accept = s2;
     10 	size_t n;
     11 	unsigned ch;
     12 	char map[__NUMCHARS] = {0};
     13 
     14 	while ((ch = *accept++) != '\0')
     15 		map[ch] = 1;
     16 
     17 	for (n = 0; (ch = *s++) != '\0' && map[ch]; ++n)
     18 		;
     19 
     20 	return n;
     21 }