]> pd.if.org Git - pdclib/blob - functions/string/strcspn.c
Removed the $Name$ tags (not supported by SVN). Added $Id$ to Makefile / text files.
[pdclib] / functions / string / strcspn.c
1 /* $Id$ */
2
3 /* strcspn( 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 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 #endif
33
34 #ifdef TEST
35 #include <_PDCLIB_test.h>
36
37 int main( void )
38 {
39     TESTCASE( strcspn( abcde, "x" ) == 5 );
40     TESTCASE( strcspn( abcde, "xyz" ) == 5 );
41     TESTCASE( strcspn( abcde, "zyx" ) == 5 );
42     TESTCASE( strcspn( abcdx, "x" ) == 4 );
43     TESTCASE( strcspn( abcdx, "xyz" ) == 4 );
44     TESTCASE( strcspn( abcdx, "zyx" ) == 4 );
45     TESTCASE( strcspn( abcde, "a" ) == 0 );
46     TESTCASE( strcspn( abcde, "abc" ) == 0 );
47     TESTCASE( strcspn( abcde, "cba" ) == 0 );
48     return TEST_RESULTS;
49 }
50 #endif