1 /*
2  * Wide character string functions
3  *
4  * Copyright (C) 2010-2021, Joachim Metz <joachim.metz@gmail.com>
5  *
6  * Refer to AUTHORS for acknowledgements.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #include <common.h>
23 #include <types.h>
24 
25 #if defined( HAVE_WCTYPE_H )
26 #include <wctype.h>
27 #endif
28 
29 #include "libclocale_wide_string.h"
30 
31 #if defined( TOWLOWER ) && !defined( HAVE_WCSNCASECMP ) && !defined( HAVE_WCSCASECMP ) && !defined( WINAPI )
32 
33 /* Replacement for missing: wcsncasecmp
34  * Compares no more than a specified number of wide characters of string1 and string2,
35  * ignoring case, returning less than, equal to or greater than zero if string1 is
36  * less than, equal to or greater than string.
37  */
libclocale_wide_string_compare_no_case(const wchar_t * string1,const wchar_t * string2,size_t comparision_length)38 int libclocale_wide_string_compare_no_case(
39      const wchar_t *string1,
40      const wchar_t *string2,
41      size_t comparision_length )
42 {
43 	wint_t character1 = 0;
44 	wint_t character2 = 0;
45 
46 	if( string1 == string2 )
47 	{
48 		return( 0 );
49 	}
50 	while( comparision_length > 0 )
51 	{
52 		character1 = towlower( *string1 );
53 		character2 = towlower( *string2 );
54 
55 		if( ( character1 == 0 )
56 		 || ( character1 != character2 ) )
57 		{
58 			return( character1 - character2 );
59 		}
60 		string1++;
61 		string2++;
62 
63 		comparision_length--;
64 	}
65 	return( 0 );
66 }
67 
68 #endif /* defined( TOWLOWER ) && !defined( HAVE_WCSNCASECMP ) && !defined( HAVE_WCSCASECMP ) && !defined( WINAPI ) */
69 
70