]> pd.if.org Git - pdclib/blob - functions/wchar/wcscspn.c
dos2unix
[pdclib] / functions / wchar / wcscspn.c
1 /* wcscspn( 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 size_t wcscspn( const wchar_t * s1, const wchar_t * s2 )
12 {
13     size_t len = 0;
14     const wchar_t * p;
15     while ( s1[len] )
16     {
17         p = s2;
18         while ( *p )
19         {
20             if ( s1[len] == *p++ )
21             {
22                 return len;
23             }
24         }
25         ++len;
26     }
27     return len;
28 }
29
30 #endif
31
32 #ifdef TEST
33 #include "_PDCLIB_test.h"
34
35 int main( void )
36 {
37     TESTCASE( wcscspn( wabcde, L"x" ) == 5 );
38     TESTCASE( wcscspn( wabcde, L"xyz" ) == 5 );
39     TESTCASE( wcscspn( wabcde, L"zyx" ) == 5 );
40     TESTCASE( wcscspn( wabcdx, L"x" ) == 4 );
41     TESTCASE( wcscspn( wabcdx, L"xyz" ) == 4 );
42     TESTCASE( wcscspn( wabcdx, L"zyx" ) == 4 );
43     TESTCASE( wcscspn( wabcde, L"a" ) == 0 );
44     TESTCASE( wcscspn( wabcde, L"abc" ) == 0 );
45     TESTCASE( wcscspn( wabcde, L"cba" ) == 0 );
46     return TEST_RESULTS;
47 }
48 #endif