pystrcmp.c 562 Bytes
Newer Older
1
/* Cross platform case insensitive string compare functions
2 3 4 5 6 7 8 9 10
 */

#include "Python.h"

int
PyOS_mystrnicmp(const char *s1, const char *s2, Py_ssize_t size)
{
	if (size == 0)
		return 0;
11 12
	while ((--size > 0) &&
	       (tolower((unsigned)*s1) == tolower((unsigned)*s2))) {
13 14 15
		if (!*s1++ || !*s2++)
			break;
	}
16
	return tolower((unsigned)*s1) - tolower((unsigned)*s2);
17 18 19 20 21
}

int
PyOS_mystricmp(const char *s1, const char *s2)
{
22
	while (*s1 && (tolower((unsigned)*s1++) == tolower((unsigned)*s2++))) {
23 24
		;
	}
25
	return (tolower((unsigned)*s1) - tolower((unsigned)*s2));
26
}