Neal Norwitz | ade57d0 | 2008-03-23 06:19:57 +0000 | [diff] [blame] | 1 | /* Cross platform case insensitive string compare functions |
Christian Heimes | 0a8143f | 2007-12-18 23:22:54 +0000 | [diff] [blame] | 2 | */ |
| 3 | |
| 4 | #include "Python.h" |
| 5 | |
| 6 | int |
| 7 | PyOS_mystrnicmp(const char *s1, const char *s2, Py_ssize_t size) |
| 8 | { |
| 9 | if (size == 0) |
| 10 | return 0; |
Neal Norwitz | ade57d0 | 2008-03-23 06:19:57 +0000 | [diff] [blame] | 11 | while ((--size > 0) && |
| 12 | (tolower((unsigned)*s1) == tolower((unsigned)*s2))) { |
Christian Heimes | 0a8143f | 2007-12-18 23:22:54 +0000 | [diff] [blame] | 13 | if (!*s1++ || !*s2++) |
| 14 | break; |
| 15 | } |
Neal Norwitz | ade57d0 | 2008-03-23 06:19:57 +0000 | [diff] [blame] | 16 | return tolower((unsigned)*s1) - tolower((unsigned)*s2); |
Christian Heimes | 0a8143f | 2007-12-18 23:22:54 +0000 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | int |
| 20 | PyOS_mystricmp(const char *s1, const char *s2) |
| 21 | { |
Neal Norwitz | ade57d0 | 2008-03-23 06:19:57 +0000 | [diff] [blame] | 22 | while (*s1 && (tolower((unsigned)*s1++) == tolower((unsigned)*s2++))) { |
Christian Heimes | 0a8143f | 2007-12-18 23:22:54 +0000 | [diff] [blame] | 23 | ; |
| 24 | } |
Neal Norwitz | ade57d0 | 2008-03-23 06:19:57 +0000 | [diff] [blame] | 25 | return (tolower((unsigned)*s1) - tolower((unsigned)*s2)); |
Christian Heimes | 0a8143f | 2007-12-18 23:22:54 +0000 | [diff] [blame] | 26 | } |