diff dlib/dlib.h @ 2332:29c53b9ebe92

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.
author corvid <corvid@lavabit.com>
date Fri, 11 Nov 2011 04:26:41 +0000
parents 2af950507af5
children 8a508291ac35
line wrap: on
line diff
--- a/dlib/dlib.h	Fri Nov 11 03:48:55 2011 +0000
+++ b/dlib/dlib.h	Fri Nov 11 04:26:41 2011 +0000
@@ -5,7 +5,6 @@
 #include <stddef.h>    /* for size_t */
 #include <stdarg.h>    /* for va_list */
 #include <string.h>    /* for strerror */
-#include <strings.h>   /* for strcasecmp, strncasecmp (POSIX 2001) */
 
 #include "d_size.h"
 
@@ -34,6 +33,8 @@
 #define dIsspace(c) isspace((uchar_t)(c))
 #define dIsalnum(c) isalnum((uchar_t)(c))
 
+#define D_ASCII_TOUPPER(c) (((c) >= 'a' && (c) <= 'z') ? (c) - 0x20 : (c))
+#define D_ASCII_TOLOWER(c) (((c) >= 'A' && (c) <= 'Z') ? (c) + 0x20 : (c))
 /*
  *-- Casts -------------------------------------------------------------------
  */
@@ -86,12 +87,11 @@
 char *dStrstrip(char *s);
 char *dStrnfill(size_t len, char c);
 char *dStrsep(char **orig, const char *delim);
-char *dStristr(const char *haystack, const char *needle);
 void dStrshred(char *s);
+char *dStriAsciiStr(const char *haystack, const char *needle);
+int dStrAsciiCasecmp(const char *s1, const char *s2);
+int dStrnAsciiCasecmp(const char *s1, const char *s2, size_t n);
 
-/* these are in POSIX 2001. Could be implemented if a port requires it */
-#define dStrcasecmp strcasecmp
-#define dStrncasecmp strncasecmp
 #define dStrerror strerror
 
 /*