1 /* strcspn( const char *, const char * )
2
3 This file is part of the Public Domain C Library (PDCLib).
4 Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #include <string.h>
8
9 #ifndef REGTEST
10
strcspn(const char * s1,const char * s2)11 size_t strcspn( const char * s1, const char * s2 )
12 {
13 size_t len = 0;
14 const char * p;
15
16 while ( s1[len] )
17 {
18 p = s2;
19
20 while ( *p )
21 {
22 if ( s1[len] == *p++ )
23 {
24 return len;
25 }
26 }
27
28 ++len;
29 }
30
31 return len;
32 }
33
34 #endif
35
36 #ifdef TEST
37
38 #include "_PDCLIB_test.h"
39
main(void)40 int main( void )
41 {
42 TESTCASE( strcspn( abcde, "x" ) == 5 );
43 TESTCASE( strcspn( abcde, "xyz" ) == 5 );
44 TESTCASE( strcspn( abcde, "zyx" ) == 5 );
45 TESTCASE( strcspn( abcdx, "x" ) == 4 );
46 TESTCASE( strcspn( abcdx, "xyz" ) == 4 );
47 TESTCASE( strcspn( abcdx, "zyx" ) == 4 );
48 TESTCASE( strcspn( abcde, "a" ) == 0 );
49 TESTCASE( strcspn( abcde, "abc" ) == 0 );
50 TESTCASE( strcspn( abcde, "cba" ) == 0 );
51 return TEST_RESULTS;
52 }
53
54 #endif
55