blob: 84295e7d21feb82f9b7b2870eb9724083c146d6f [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{
9 if (size == 0)
10 return 0;
Neal Norwitzade57d02008-03-23 06:19:57 +000011 while ((--size > 0) &&
12 (tolower((unsigned)*s1) == tolower((unsigned)*s2))) {
Christian Heimes0a8143f2007-12-18 23:22:54 +000013 if (!*s1++ || !*s2++)
14 break;
15 }
Neal Norwitzade57d02008-03-23 06:19:57 +000016 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{
Neal Norwitzade57d02008-03-23 06:19:57 +000022 while (*s1 && (tolower((unsigned)*s1++) == tolower((unsigned)*s2++))) {
Christian Heimes0a8143f2007-12-18 23:22:54 +000023 ;
24 }
Neal Norwitzade57d02008-03-23 06:19:57 +000025 return (tolower((unsigned)*s1) - tolower((unsigned)*s2));
Christian Heimes0a8143f2007-12-18 23:22:54 +000026}