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