- Notifications
You must be signed in to change notification settings - Fork 31.8k
/
Copy pathpystrcmp.c
30 lines (27 loc) · 777 Bytes
/
pystrcmp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* Cross platform case insensitive string compare functions
*/
#include"Python.h"
int
PyOS_mystrnicmp(constchar*s1, constchar*s2, Py_ssize_tsize)
{
constunsigned char*p1, *p2;
if (size==0)
return0;
p1= (constunsigned char*)s1;
p2= (constunsigned char*)s2;
for (; (--size>0) &&*p1&&*p2&& (Py_TOLOWER(*p1) ==Py_TOLOWER(*p2));
p1++, p2++) {
;
}
returnPy_TOLOWER(*p1) -Py_TOLOWER(*p2);
}
int
PyOS_mystricmp(constchar*s1, constchar*s2)
{
constunsigned char*p1= (constunsigned char*)s1;
constunsigned char*p2= (constunsigned char*)s2;
for (; *p1&&*p2&& (Py_TOLOWER(*p1) ==Py_TOLOWER(*p2)); p1++, p2++) {
;
}
return (Py_TOLOWER(*p1) -Py_TOLOWER(*p2));
}