X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fwchar%2Fwcsstr.c;fp=functions%2Fwchar%2Fwcsstr.c;h=a2162f8f148cd0669284e2a08e5c393dd7fdb1b8;hb=14b5b78e19a79f590233caee7848e7cb19084088;hp=0000000000000000000000000000000000000000;hpb=41777e3d5dc655f59a8c3bcd071639e6878e853a;p=pdclib diff --git a/functions/wchar/wcsstr.c b/functions/wchar/wcsstr.c new file mode 100644 index 0000000..a2162f8 --- /dev/null +++ b/functions/wchar/wcsstr.c @@ -0,0 +1,49 @@ +/* wcsstr( const wchar_t *, const wchar_t * ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST + +wchar_t * wcsstr( const wchar_t * s1, const wchar_t * s2 ) +{ + const wchar_t * p1 = s1; + const wchar_t * p2; + while ( *s1 ) + { + p2 = s2; + while ( *p2 && ( *p1 == *p2 ) ) + { + ++p1; + ++p2; + } + if ( ! *p2 ) + { + return (wchar_t *) s1; + } + ++s1; + p1 = s1; + } + return NULL; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + wchar_t s[] = L"abcabcabcdabcde"; + TESTCASE( wcsstr( s, L"x" ) == NULL ); + TESTCASE( wcsstr( s, L"xyz" ) == NULL ); + TESTCASE( wcsstr( s, L"a" ) == &s[0] ); + TESTCASE( wcsstr( s, L"abc" ) == &s[0] ); + TESTCASE( wcsstr( s, L"abcd" ) == &s[6] ); + TESTCASE( wcsstr( s, L"abcde" ) == &s[10] ); + return TEST_RESULTS; +} +#endif