1 /* Copyright (c) 2009 Corinna Vinschen <corinna@vinschen.de> */
2 /*
3 FUNCTION
4 <<wcsncasecmp>>---case-insensitive wide character string compare
5
6 INDEX
7 wcsncasecmp
8
9 SYNOPSIS
10 #include <wchar.h>
11 int wcsncasecmp(const wchar_t *<[a]>, const wchar_t * <[b]>, size_t <[length]>);
12
13 DESCRIPTION
14 <<wcsncasecmp>> compares up to <[length]> wide characters
15 from the string at <[a]> to the string at <[b]> in a
16 case-insensitive manner.
17
18 RETURNS
19
20 If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
21 both are converted to uppercase), <<wcsncasecmp>> returns a
22 number greater than zero. If the two strings are equivalent,
23 <<wcsncasecmp>> returns zero. If <<*<[a]>>> sorts
24 lexicographically before <<*<[b]>>>, <<wcsncasecmp>> returns a
25 number less than zero.
26
27 PORTABILITY
28 POSIX-1.2008
29
30 <<wcsncasecmp>> requires no supporting OS subroutines. It uses
31 tolower() from elsewhere in this library.
32
33 QUICKREF
34 wcsncasecmp
35 */
36
37 #include <wchar.h>
38 #include <wctype.h>
39
40 int
wcsncasecmp(const wchar_t * s1,const wchar_t * s2,size_t n)41 wcsncasecmp (const wchar_t *s1,
42 const wchar_t *s2,
43 size_t n)
44 {
45 int d = 0;
46 for ( ; n != 0; n--)
47 {
48 const int c1 = towlower (*s1++);
49 const int c2 = towlower (*s2++);
50 if (((d = c1 - c2) != 0) || (c2 == '\0'))
51 break;
52 }
53 return d;
54 }
55