]> pd.if.org Git - pdclib/blob - functions/string/strspn.c
0cf90df051ecbbcce66c8345fcd38119635d5afd
[pdclib] / functions / string / strspn.c
1 /* strspn( 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
11 size_t strspn( const char * s1, const char * s2 )
12 {
13     size_t len = 0;
14     const char * p;
15     while ( s1[ len ] )
16     {
17         p = s2;
18         while ( *p )
19         {
20             if ( s1[len] == *p )
21             {
22                 break;
23             }
24             ++p;
25         }
26         if ( ! *p )
27         {
28             return len;
29         }
30         ++len;
31     }
32     return len;
33 }
34
35 #endif
36
37 #ifdef TEST
38 #include <_PDCLIB_test.h>
39
40 int main( void )
41 {
42     TESTCASE( strspn( abcde, "abc" ) == 3 );
43     TESTCASE( strspn( abcde, "b" ) == 0 );
44     TESTCASE( strspn( abcde, abcde ) == 5 );
45     return TEST_RESULTS;
46 }
47 #endif