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