* Andr� Malo wrote:

> Hmm, so now we can just rename apr_streq.c to apr_strcaseeq.c (dropping the
> simple eq functions), include the case tables only there (regarding to the
> other issue). The macros could stay in apr_lib.h (plus the apr_streq
> macros?), since one has to link against the apr anyway. The tables should
> probably be declared as APR_DECLARE_DATA then.
> Does this sound better?

for example this new patch? :)

nd
diff -Nur apr~/configure.in apr/configure.in
--- apr~/configure.in
+++ apr/configure.in
@@ -1852,8 +1852,8 @@
 AC_SUBST(LIBTOOL_LIBS)
 
 echo "${nl}Construct Makefiles and header files."
-MAKEFILE1="Makefile strings/Makefile passwd/Makefile tables/Makefile build/Makefile"
-SUBDIRS="strings passwd tables "
+MAKEFILE1="Makefile include/Makefile strings/Makefile passwd/Makefile tables/Makefile build/Makefile"
+SUBDIRS="include strings passwd tables "
 for dir in $apr_modules
 do
     test -d $dir || $MKDIR $dir
diff -Nur apr~/include/apr_lib.h apr/include/apr_lib.h
--- apr~/include/apr_lib.h
+++ apr/include/apr_lib.h
@@ -256,9 +256,22 @@
 #define apr_tolower(c) (tolower(((unsigned char)(c))))
 /** @see toupper */
 #define apr_toupper(c) (toupper(((unsigned char)(c))))
-
 /** @} */
 
+APR_DECLARE_DATA extern const unsigned char apr_lower_case_table_asc[256];
+APR_DECLARE_DATA extern const unsigned char apr_upper_case_table_asc[256];
+
+/**
+ * similar to apr_tolower, but locale independent, i.e. translates only A-Z
+ * @remark This works on non-ascii systems as well
+ */
+#define apr_tolower_asc(c) (apr_lower_case_table_asc[(unsigned)(c)])
+/**
+ * similar to apr_toupper, but locale independent, i.e. translates only a-z
+ * @remark This works on non-ascii systems as well
+ */
+#define apr_toupper_asc(c) (apr_upper_case_table_asc[(unsigned)(c)])
+
 #ifdef __cplusplus
 }
 #endif
diff -Nur apr~/include/apr_strings.h apr/include/apr_strings.h
--- apr~/include/apr_strings.h
+++ apr/include/apr_strings.h
@@ -87,6 +87,7 @@
 #include "apr_errno.h"
 #include "apr_pools.h"
 #define APR_WANT_IOVEC
+#define APR_WANT_STRFUNC
 #include "apr_want.h"
 
 #if APR_HAVE_STDARG_H
@@ -104,6 +105,47 @@
  */
 
 /**
+ * Check whether two strings are equal.
+ * @param a The first string to compare
+ * @param b The second string to compare
+ * @return Either 0 (not equal) or 1 (equal)
+ */
+#define apr_streq(a, b)     (!strcmp(a, b))
+/**
+ * Check whether the first n chars of two strings are equal.
+ * @param a The first string to compare
+ * @param b The second string to compare
+ * @param n The maximum of characters to compare
+ * @return Either 0 (not equal) or 1 (equal)
+ */
+#define apr_strneq(a, b, n) (!strncmp(a, b, n))
+
+/**
+ * Check whether two strings are equal, compared case insensitively.
+ * @param a The first string to compare
+ * @param b The second string to compare
+ * @return Either 0 (not equal) or 1 (equal)
+ * @remark The case will be checked independent from the locale, i.e.
+ *         only A-Z will be translated. Mostly useful for checking
+ *         HTTP-Headers and the like.
+ */
+APR_DECLARE(APR_INLINE int) apr_strcaseeq(const char *a, const char *b);
+
+/**
+ * Check whether the first n chars of two strings are equal, compared case
+ * insensitively.
+ * @param a The first string to compare
+ * @param b The second string to compare
+ * @param n The maximum of characters to compare
+ * @return Either 0 (not equal) or 1 (equal)
+ * @remark The case will be checked independent from the locale, i.e.
+ *         only A-Z will be translated. Mostly useful for checking
+ *         HTTP-Headers and the like.
+ */
+APR_DECLARE(APR_INLINE int) apr_strncaseeq(const char *a, const char *b,
+                                           apr_size_t n);
+
+/**
  * Do a natural order comparison of two strings.
  * @param a The first string to compare
  * @param b The second string to compare
diff -Nur apr~/include/gen_case_tables.c apr/include/gen_case_tables.c
--- apr~/include/gen_case_tables.c
+++ apr/include/gen_case_tables.c
@@ -0,0 +1,113 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written
+ *    permission, please contact [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+#include "apr.h"
+
+#define APR_WANT_STRFUNC
+#define APR_WANT_STDIO
+#include "apr_want.h"
+
+int main(int argc, char *argv[])
+{
+    unsigned c, uc;
+    const char *upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+    const char *lower = "abcdefghijklmnopqrstuvwxyz";
+    const char *p;
+
+    printf("/* this file is automatically generated by gen_case_tables, "
+           "do not edit */\n\n"
+           "#ifndef APR_CASE_TABLES_ASC_H\n"
+           "#define APR_CASE_TABLES_ASC_H\n\n"
+           "/* lower case */\n"
+           "APR_DECLARE_DATA const unsigned char "
+           "apr_lower_case_table_asc[256] = {\n"
+           "      0, ");
+
+    for (c = 1; c < 256; ++c) {
+        if (c % 16 == 0) {
+            printf("\n    ");
+        }
+
+        uc = c;
+        if ((p = strchr(upper, c)) != NULL) {
+            uc = lower[p-upper];
+        }
+
+        printf("%3u%s", (unsigned)uc, (c < 255) ? ", " : "");
+    }
+
+    printf("\n};\n\n");
+
+    printf("/* upper case */\n"
+           "APR_DECLARE_DATA const unsigned char "
+           "apr_upper_case_table_asc[256] = {\n"
+           "      0, ");
+
+    for (c = 1; c < 256; ++c) {
+        if (c % 16 == 0) {
+            printf("\n    ");
+        }
+
+        uc = c;
+        if ((p = strchr(lower, c)) != NULL) {
+            uc = upper[p-lower];
+        }
+
+        printf("%3u%s", (unsigned)uc, (c < 255) ? ", " : "");
+    }
+
+    printf("\n};\n\n#endif /* APR_CASE_TABLES_ASC_H */\n");
+
+    return 0;
+}
diff -Nur apr~/include/Makefile.in apr/include/Makefile.in
--- apr~/include/Makefile.in
+++ apr/include/Makefile.in
@@ -0,0 +1,20 @@
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+TARGETS = apr_case_tables_asc.h
+
+# bring in rules.mk for standard functionality
[EMAIL PROTECTED]@
+
+DEFOSDIR=$(INCDIR)/arch/@DEFAULT_OSDIR@
+INCDIR=../include
+INCLUDES=-I$(INCDIR) -I$(DEFOSDIR)
+
+gen_case_tables_OBJECTS = gen_case_tables.lo
+gen_case_tables: $(gen_case_tables_OBJECTS)
+	$(LINK) $(EXTRA_LDFLAGS) $(gen_case_tables_OBJECTS) $(EXTRA_LIBS)
+
+apr_case_tables_asc.h: gen_case_tables
+	./gen_case_tables > $@
+
+# DO NOT REMOVE
diff -Nur apr~/Makefile.in apr/Makefile.in
--- apr~/Makefile.in
+++ apr/Makefile.in
@@ -34,7 +34,8 @@
 CLEAN_TARGETS = 
 DISTCLEAN_TARGETS = config.cache config.log config.status \
 	include/apr.h include/arch/unix/apr_private.h \
-	libtool apr.exp apr-config exports.c export_vars.h
+	libtool apr.exp apr-config exports.c export_vars.h \
+	include/gen_case_tables include/apr_case_tables_asc.h
 EXTRACLEAN_TARGETS = configure aclocal.m4 include/arch/unix/apr_private.h.in
 
 [EMAIL PROTECTED]@
diff -Nur apr~/strings/apr_strcaseeq.c apr/strings/apr_strcaseeq.c
--- apr~/strings/apr_strcaseeq.c
+++ apr/strings/apr_strcaseeq.c
@@ -0,0 +1,80 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written
+ *    permission, please contact [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+#include "apr.h"
+#include "apr_lib.h"
+#include "apr_case_tables_asc.h"
+
+APR_DECLARE(APR_INLINE int) apr_strcaseeq(const char *a, const char *b)
+{
+    while (*a && apr_tolower_asc(*a) == apr_tolower_asc(*b)) {
+        ++a;
+        ++b;
+    }
+
+    return (apr_tolower_asc(*a) == apr_tolower_asc(*b));
+}
+
+APR_DECLARE(APR_INLINE int) apr_strncaseeq(const char *a, const char *b,
+                                           apr_size_t n)
+{
+    const char *ep = a + n - 1;
+
+    while (a < ep && apr_tolower_asc(*a) == apr_tolower_asc(*b) && *a) {
+        ++a;
+        ++b;
+    }
+
+    return (apr_tolower_asc(*a) == apr_tolower_asc(*b));
+}
diff -Nur apr~/strings/Makefile.in apr/strings/Makefile.in
--- apr~/strings/Makefile.in
+++ apr/strings/Makefile.in
@@ -7,7 +7,8 @@
 	apr_strnatcmp.lo \
 	apr_strings.lo \
 	apr_fnmatch.lo \
-	apr_strtok.lo
+	apr_strtok.lo \
+	apr_strcaseeq.lo
 
 # bring in rules.mk for standard functionality
 @INCLUDE_RULES@

Reply via email to