1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
23 /* These functions are borrowed from libcurl's lib/rawstr.c with minor
24 * modifications to style and naming. Curl_raw_equal and Curl_raw_nequal are
25 * further modified to be true cmp style functions, returning negative, zero,
32 /* Portable, consistent toupper (remember EBCDIC). Do not use toupper() because
33 its behavior is altered by the current locale. */
34 static char raw_toupper(char in
)
94 * _alpm_raw_cmp() is for doing "raw" case insensitive strings. This is meant
95 * to be locale independent and only compare strings we know are safe for
96 * this. See http://daniel.haxx.se/blog/2008/10/15/strcasecmp-in-turkish/ for
97 * some further explanation to why this function is necessary.
99 * The function is capable of comparing a-z case insensitively even for
103 int _alpm_raw_cmp(const char *first
, const char *second
)
105 while(*first
&& *second
) {
106 if(raw_toupper(*first
) != raw_toupper(*second
)) {
107 /* get out of the loop as soon as they don't match */
113 /* we do the comparison here (possibly again), just to make sure that if the
114 loop above is skipped because one of the strings reached zero, we must not
115 return this as a successful match */
116 return (raw_toupper(*first
) - raw_toupper(*second
));
119 int _alpm_raw_ncmp(const char *first
, const char *second
, size_t max
)
121 while(*first
&& *second
&& max
) {
122 if(raw_toupper(*first
) != raw_toupper(*second
)) {
130 /* they are equal this far */
134 return (raw_toupper(*first
) - raw_toupper(*second
));
137 /* vim: set ts=2 sw=2 noet: */