]> pd.if.org Git - pdclib/blob - functions/wchar/wcsstr.c
dos2unix
[pdclib] / functions / wchar / wcsstr.c
1 /* wcsstr( const wchar_t *, const wchar_t * )
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 <wchar.h>
8
9 #ifndef REGTEST
10
11 wchar_t * wcsstr( const wchar_t * s1, const wchar_t * s2 )
12 {
13     const wchar_t * p1 = s1;
14     const wchar_t * p2;
15     while ( *s1 )
16     {
17         p2 = s2;
18         while ( *p2 && ( *p1 == *p2 ) )
19         {
20             ++p1;
21             ++p2;
22         }
23         if ( ! *p2 )
24         {
25             return (wchar_t *) s1;
26         }
27         ++s1;
28         p1 = s1;
29     }
30     return NULL;
31 }
32
33 #endif
34
35 #ifdef TEST
36 #include "_PDCLIB_test.h"
37
38 int main( void )
39 {
40     wchar_t s[] = L"abcabcabcdabcde";
41     TESTCASE( wcsstr( s, L"x" ) == NULL );
42     TESTCASE( wcsstr( s, L"xyz" ) == NULL );
43     TESTCASE( wcsstr( s, L"a" ) == &s[0] );
44     TESTCASE( wcsstr( s, L"abc" ) == &s[0] );
45     TESTCASE( wcsstr( s, L"abcd" ) == &s[6] );
46     TESTCASE( wcsstr( s, L"abcde" ) == &s[10] );
47     return TEST_RESULTS;
48 }
49 #endif