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