Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
strspn.c
Go to the documentation of this file.
1 #include <stdint.h>
2 #include <string.h>
3 
4 #define BITOP(a, b, op) \
5  ((a)[(size_t)(b) / (8 * sizeof *(a))] op(size_t) 1 << ((size_t)(b) % (8 * sizeof *(a))))
6 
7 size_t strspn(const char* s, const char* c)
8 {
9  const char* a = s;
10  size_t byteset[32 / sizeof(size_t)] = {0};
11 
12  if(!c[0])
13  {
14  return 0;
15  }
16 
17  if(!c[1])
18  {
19  for(; *s == *c; s++)
20  {
21  {
22  ;
23  }
24  }
25  return (uintptr_t)s - (uintptr_t)a;
26  }
27 
28  for(; *c && BITOP(byteset, *(const unsigned char*)c, |=); c++)
29  {
30  {
31  ;
32  }
33  }
34  for(; *s && BITOP(byteset, *(const unsigned char*)s, &); s++)
35  {
36  {
37  ;
38  }
39  }
40 
41  return (uintptr_t)s - (uintptr_t)a;
42 }
#define BITOP(a, b, op)
Definition: strspn.c:4
size_t strspn(const char *s, const char *c)
Definition: strspn.c:7