1 /* Case-insensitive string comparison function.
2 Copyright (C) 1998-1999, 2005-2008, 2010-2018 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2007.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
27 #define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
29 /* Compare the initial segment of the character string STRING consisting of
30 at most mbslen (PREFIX) characters with the character string PREFIX,
31 ignoring case. If the two match, return a pointer to the first byte
32 after this prefix in STRING. Otherwise, return NULL.
33 Note: This function may, in multibyte locales, return non-NULL if STRING
34 is of smaller length than PREFIX! */
36 mbspcasecmp (const char *string
, const char *prefix
)
38 /* This is essentially the same as
39 mbsncasecmp (string, prefix, mbslen (prefix))
40 just with small optimizations. */
42 return (char *) (string
+ strlen (string
));
44 /* Be careful not to look at the entire extent of STRING or PREFIX until
45 needed. This is useful because when two strings differ, the difference is
46 most often already in the very few first characters. */
49 mbui_iterator_t iter1
;
50 mbui_iterator_t iter2
;
52 mbui_init (iter1
, string
);
53 mbui_init (iter2
, prefix
);
55 while (mbui_avail (iter1
) && mbui_avail (iter2
))
57 int cmp
= mb_casecmp (mbui_cur (iter1
), mbui_cur (iter2
));
65 if (!mbui_avail (iter2
))
66 /* PREFIX equals STRING or is terminated before STRING. */
67 return (char *) mbui_cur_ptr (iter1
);
69 /* STRING terminated before PREFIX. */
74 const unsigned char *p1
= (const unsigned char *) string
;
75 const unsigned char *p2
= (const unsigned char *) prefix
;
83 if (c2
== '\0' || c1
!= c2
)
88 /* PREFIX equals STRING or is terminated before STRING. */
91 /* STRING terminated before PREFIX. */