blob: f9c2277cb56dc7096c4d8ac460879d6b0d0909c3 [file] [log] [blame]
Christian Heimesfe337bf2008-03-23 21:54:12 +00001/* Cross platform case insensitive string compare functions
Christian Heimes99170a52007-12-19 02:07:34 +00002 */
3
4#include "Python.h"
5
6int
7PyOS_mystrnicmp(const char *s1, const char *s2, Py_ssize_t size)
8{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +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 Heimes99170a52007-12-19 02:07:34 +000017}
18
19int
20PyOS_mystricmp(const char *s1, const char *s2)
21{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000022 while (*s1 && (tolower((unsigned)*s1++) == tolower((unsigned)*s2++))) {
23 ;
24 }
25 return (tolower((unsigned)*s1) - tolower((unsigned)*s2));
Christian Heimes99170a52007-12-19 02:07:34 +000026}