]> pd.if.org Git - pdclib/blob - functions/string/strcspn.c
Added test drivers.
[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 size_t strcspn( 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                 return len;
25             }
26         }
27         ++len;
28     }
29     return len;
30 }
31
32 #ifdef TEST
33 #include <_PDCLIB_test.h>
34
35 int main()
36 {
37     BEGIN_TESTS;
38     TESTCASE( strcspn( abcde, "x" ) == 5 );
39     TESTCASE( strcspn( abcde, "xyz" ) == 5 );
40     TESTCASE( strcspn( abcde, "zyx" ) == 5 );
41     TESTCASE( strcspn( abcdx, "x" ) == 4 );
42     TESTCASE( strcspn( abcdx, "xyz" ) == 4 );
43     TESTCASE( strcspn( abcdx, "zyx" ) == 4 );
44     TESTCASE( strcspn( abcde, "a" ) == 0 );
45     TESTCASE( strcspn( abcde, "abc" ) == 0 );
46     TESTCASE( strcspn( abcde, "cba" ) == 0 );
47     return TEST_RESULTS;
48 }
49 #endif