blob: 84295e7d21feb82f9b7b2870eb9724083c146d6f [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{
9 if (size == 0)
10 return 0;
Christian Heimesfe337bf2008-03-23 21:54:12 +000011 while ((--size > 0) &&
12 (tolower((unsigned)*s1) == tolower((unsigned)*s2))) {
Christian Heimes99170a52007-12-19 02:07:34 +000013 if (!*s1++ || !*s2++)
14 break;
15 }
Christian Heimesfe337bf2008-03-23 21:54:12 +000016 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{
Christian Heimesfe337bf2008-03-23 21:54:12 +000022 while (*s1 && (tolower((unsigned)*s1++) == tolower((unsigned)*s2++))) {
Christian Heimes99170a52007-12-19 02:07:34 +000023 ;
24 }
Christian Heimesfe337bf2008-03-23 21:54:12 +000025 return (tolower((unsigned)*s1) - tolower((unsigned)*s2));
Christian Heimes99170a52007-12-19 02:07:34 +000026}