diff options
author | corvid <corvid@lavabit.com> | 2011-11-11 04:26:41 +0000 |
---|---|---|
committer | corvid <corvid@lavabit.com> | 2011-11-11 04:26:41 +0000 |
commit | 980fe05f47b9d6dd8626b5ea021e2c16807ff5ca (patch) | |
tree | 2e5670d74d8fcfb8e7f6b84ffaf5f77b74855746 /dlib/dlib.c | |
parent | 119aa95ed6bc612dd4ef7a3121d9bf220148aaa4 (diff) |
locale-independent ASCII character case handling
Basically, I and i are different letters in Turkic languages, and this
causes problems for str(n)casecmp and toupper/tolower in these locales
when dillo is dealing with ASCII.
Diffstat (limited to 'dlib/dlib.c')
-rw-r--r-- | dlib/dlib.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/dlib/dlib.c b/dlib/dlib.c index a3c59060..002adcdf 100644 --- a/dlib/dlib.c +++ b/dlib/dlib.c @@ -173,16 +173,21 @@ char *dStrsep(char **orig, const char *delim) } /* + * ASCII functions to avoid the case difficulties introduced by I/i in + * Turkic locales. + */ + +/* * Case insensitive strstr */ -char *dStristr(const char *haystack, const char *needle) +char *dStriAsciiStr(const char *haystack, const char *needle) { int i, j; char *ret = NULL; if (haystack && needle) { for (i = 0, j = 0; haystack[i] && needle[j]; ++i) - if (tolower(haystack[i]) == tolower(needle[j])) { + if (D_ASCII_TOLOWER(haystack[i]) == D_ASCII_TOLOWER(needle[j])) { ++j; } else if (j) { i -= j; @@ -194,6 +199,29 @@ char *dStristr(const char *haystack, const char *needle) return ret; } +int dStrAsciiCasecmp(const char *s1, const char *s2) +{ + int ret = 0; + + while ((*s1 || *s2) && + !(ret = D_ASCII_TOLOWER(*s1) - D_ASCII_TOLOWER(*s2))) { + s1++; + s2++; + } + return ret; +} + +int dStrnAsciiCasecmp(const char *s1, const char *s2, size_t n) +{ + int ret = 0; + + while (n-- && (*s1 || *s2) && + !(ret = D_ASCII_TOLOWER(*s1) - D_ASCII_TOLOWER(*s2))) { + s1++; + s2++; + } + return ret; +} /* *- dStr ---------------------------------------------------------------------- |