scc

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

strspn.c (370B)


      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 = (const unsigned char *) s1;
      9 	const unsigned char *accept = (const unsigned char *) 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 }