]> pd.if.org Git - pdclib/blob - functions/string/strcspn.c
Porting current working set from CVS.
[pdclib] / functions / string / strcspn.c
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* strcspn( 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 strcspn( 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                 return len;
27             }
28         }
29         ++len;
30     }
31     return len;
32 }
33
34 #endif
35
36 #ifdef TEST
37 #include <_PDCLIB_test.h>
38
39 int main( void )
40 {
41     TESTCASE( strcspn( abcde, "x" ) == 5 );
42     TESTCASE( strcspn( abcde, "xyz" ) == 5 );
43     TESTCASE( strcspn( abcde, "zyx" ) == 5 );
44     TESTCASE( strcspn( abcdx, "x" ) == 4 );
45     TESTCASE( strcspn( abcdx, "xyz" ) == 4 );
46     TESTCASE( strcspn( abcdx, "zyx" ) == 4 );
47     TESTCASE( strcspn( abcde, "a" ) == 0 );
48     TESTCASE( strcspn( abcde, "abc" ) == 0 );
49     TESTCASE( strcspn( abcde, "cba" ) == 0 );
50     return TEST_RESULTS;
51 }
52 #endif