Staging
v0.8.1
Revision a9ba8ba9a71f3cb8d274c354ff67b6206abeb8ac authored by Ethan Furman on 17 September 2020, 00:37:51 UTC, committed by GitHub on 17 September 2020, 00:37:51 UTC
fix default `_missing_` to return `None` instead of raising a `ValueError`
Co-authored-by: Andrey Darascheka <andrei.daraschenka@leverx.com>
(cherry picked from commit c95ad7a91fbd7636f33a098d3b39964ab083bf49)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
1 parent 4465df6
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)
{
    const unsigned char *p1, *p2;
    if (size == 0)
        return 0;
    p1 = (const unsigned char *)s1;
    p2 = (const unsigned char *)s2;
    for (; (--size > 0) && *p1 && *p2 && (tolower(*p1) == tolower(*p2));
         p1++, p2++) {
        ;
    }
    return tolower(*p1) - tolower(*p2);
}

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