X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;ds=sidebyside;f=functions%2Fwchar%2Fwcscspn.c;fp=functions%2Fwchar%2Fwcscspn.c;h=1f311c61e7b0772f73321e2f95a599bb3d218aac;hb=14b5b78e19a79f590233caee7848e7cb19084088;hp=0000000000000000000000000000000000000000;hpb=41777e3d5dc655f59a8c3bcd071639e6878e853a;p=pdclib diff --git a/functions/wchar/wcscspn.c b/functions/wchar/wcscspn.c new file mode 100644 index 0000000..1f311c6 --- /dev/null +++ b/functions/wchar/wcscspn.c @@ -0,0 +1,48 @@ +/* wcscspn( 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 + +size_t wcscspn( const wchar_t * s1, const wchar_t * s2 ) +{ + size_t len = 0; + const wchar_t * p; + while ( s1[len] ) + { + p = s2; + while ( *p ) + { + if ( s1[len] == *p++ ) + { + return len; + } + } + ++len; + } + return len; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + TESTCASE( wcscspn( wabcde, L"x" ) == 5 ); + TESTCASE( wcscspn( wabcde, L"xyz" ) == 5 ); + TESTCASE( wcscspn( wabcde, L"zyx" ) == 5 ); + TESTCASE( wcscspn( wabcdx, L"x" ) == 4 ); + TESTCASE( wcscspn( wabcdx, L"xyz" ) == 4 ); + TESTCASE( wcscspn( wabcdx, L"zyx" ) == 4 ); + TESTCASE( wcscspn( wabcde, L"a" ) == 0 ); + TESTCASE( wcscspn( wabcde, L"abc" ) == 0 ); + TESTCASE( wcscspn( wabcde, L"cba" ) == 0 ); + return TEST_RESULTS; +} +#endif