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