X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fwchar%2Fwcsstr.c;h=1427a8a573de7690bf7a3bb5e5ea62d358513638;hp=84f7c492b388e3edd1ec4530596901001b5b5c8a;hb=abc15df6b9fae3374d24c7cf5c3ab94c605b2a6d;hpb=8894c921674bb116d0a7b8f23a55311e7a768019 diff --git a/functions/wchar/wcsstr.c b/functions/wchar/wcsstr.c index 84f7c49..1427a8a 100644 --- a/functions/wchar/wcsstr.c +++ b/functions/wchar/wcsstr.c @@ -1,49 +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 +/* 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