]> pd.if.org Git - pdclib/blob - functions/string/strpbrk.c
41211dbd55970a8b09a898490065ac3e9b6a114c
[pdclib] / functions / string / strpbrk.c
1 /* $Id$ */
2
3 /* strpbrk( 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 char * strpbrk( const char * s1, const char * s2 )
14 {
15     const char * p1 = s1;
16     const char * p2;
17     while ( *p1 )
18     {
19         p2 = s2;
20         while ( *p2 )
21         {
22             if ( *p1 == *p2++ )
23             {
24                 return (char *) p1;
25             }
26         }
27         ++p1;
28     }
29     return NULL;
30 }
31
32 #endif
33
34 #ifdef TEST
35 #include <_PDCLIB_test.h>
36
37 int main( void )
38 {
39     TESTCASE( strpbrk( abcde, "x" ) == NULL );
40     TESTCASE( strpbrk( abcde, "xyz" ) == NULL );
41     TESTCASE( strpbrk( abcdx, "x" ) == &abcdx[4] );
42     TESTCASE( strpbrk( abcdx, "xyz" ) == &abcdx[4] );
43     TESTCASE( strpbrk( abcdx, "zyx" ) == &abcdx[4] );
44     TESTCASE( strpbrk( abcde, "a" ) == &abcde[0] );
45     TESTCASE( strpbrk( abcde, "abc" ) == &abcde[0] );
46     TESTCASE( strpbrk( abcde, "cba" ) == &abcde[0] );
47     return TEST_RESULTS;
48 }
49 #endif