Staging
v0.5.1
Revision 516a6a254814d2bc6a90290dfc44d77fdfb4050b authored by Victor Stinner on 18 June 2019, 00:13:58 UTC, committed by Ned Deily on 18 June 2019, 00:13:57 UTC
(cherry picked from commit c1f5667be1e3ec5871560c677402c1252c6018a6)
1 parent ecafe8e
Raw File
pystrcmp.c
/* Cross platform case insensitive string compare functions
 */

#include "Python.h"

int
PyOS_mystrnicmp(const char *s1, const char *s2, Py_ssize_t size)
{
    if (size == 0)
        return 0;
    while ((--size > 0) &&
           (tolower((unsigned)*s1) == tolower((unsigned)*s2))) {
        if (!*s1++ || !*s2++)
            break;
    }
    return tolower((unsigned)*s1) - tolower((unsigned)*s2);
}

int
PyOS_mystricmp(const char *s1, const char *s2)
{
    while (*s1 && (tolower((unsigned)*s1++) == tolower((unsigned)*s2++))) {
        ;
    }
    return (tolower((unsigned)*s1) - tolower((unsigned)*s2));
}
back to top