Retro68/gcc/newlib/libc/string/strcspn.c

49 lines
788 B
C
Raw Normal View History

2017-04-11 21:13:36 +00:00
/*
FUNCTION
<<strcspn>>---count characters not in string
INDEX
strcspn
2018-12-28 15:30:48 +00:00
SYNOPSIS
2017-04-11 21:13:36 +00:00
size_t strcspn(const char *<[s1]>, const char *<[s2]>);
DESCRIPTION
This function computes the length of the initial part of
the string pointed to by <[s1]> which consists entirely of
characters <[NOT]> from the string pointed to by <[s2]>
(excluding the terminating null character).
RETURNS
<<strcspn>> returns the length of the substring found.
PORTABILITY
<<strcspn>> is ANSI C.
<<strcspn>> requires no supporting OS subroutines.
*/
#include <string.h>
size_t
2018-12-28 15:30:48 +00:00
strcspn (const char *s1,
const char *s2)
2017-04-11 21:13:36 +00:00
{
2018-12-28 15:30:48 +00:00
const char *s = s1;
const char *c;
2017-04-11 21:13:36 +00:00
while (*s1)
{
for (c = s2; *c; c++)
{
if (*s1 == *c)
break;
}
if (*c)
break;
s1++;
}
return s1 - s;
}