blob: f9c2277cb56dc7096c4d8ac460879d6b0d0909c3 [file] [log] [blame]
Neal Norwitzade57d02008-03-23 06:19:57 +00001/* Cross platform case insensitive string compare functions
Christian Heimes0a8143f2007-12-18 23:22:54 +00002 */
3
4#include "Python.h"
5
6int
7PyOS_mystrnicmp(const char *s1, const char *s2, Py_ssize_t size)
8{
Antoine Pitrouc83ea132010-05-09 14:46:46 +00009 if (size == 0)
10 return 0;
11 while ((--size > 0) &&
12 (tolower((unsigned)*s1) == tolower((unsigned)*s2))) {
13 if (!*s1++ || !*s2++)
14 break;
15 }
16 return tolower((unsigned)*s1) - tolower((unsigned)*s2);
Christian Heimes0a8143f2007-12-18 23:22:54 +000017}
18
19int
20PyOS_mystricmp(const char *s1, const char *s2)
21{
Antoine Pitrouc83ea132010-05-09 14:46:46 +000022 while (*s1 && (tolower((unsigned)*s1++) == tolower((unsigned)*s2++))) {
23 ;
24 }
25 return (tolower((unsigned)*s1) - tolower((unsigned)*s2));
Christian Heimes0a8143f2007-12-18 23:22:54 +000026}