1 /**
2 * @file
3 * For systems lacking wcscasecmp()
4 *
5 * @authors
6 * Copyright (C) 2009 Rocco Rutte <pdmef@gmx.net>
7 *
8 * @copyright
9 * This program is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 2 of the License, or (at your option) any later
12 * version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 /**
24 * @page neo_wcscasecmp For systems lacking wcscasecmp()
25 *
26 * For systems lacking wcscasecmp()
27 */
28
29 #include "config.h"
30 #include <wchar.h>
31 #include <wctype.h>
32
33 /**
34 * wcscasecmp - Compare two wide-character strings, ignoring case
35 * @param a First string
36 * @param b Second string
37 * @retval -1 a precedes b
38 * @retval 0 a and b are identical
39 * @retval 1 b precedes a
40 */
wcscasecmp(const wchar_t * a,const wchar_t * b)41 int wcscasecmp(const wchar_t *a, const wchar_t *b)
42 {
43 if (!a && !b)
44 return 0;
45 if (!a && b)
46 return -1;
47 if (a && !b)
48 return 1;
49
50 for (; *a || *b; a++, b++)
51 {
52 int i = towlower(*a);
53 if ((i - towlower(*b)) != 0)
54 return i;
55 }
56 return 0;
57 }
58