]> granicus.if.org Git - apache/commitdiff
cleanup compare_lexicography function.
authorAndré Malo <nd@apache.org>
Sun, 3 Aug 2003 20:15:50 +0000 (20:15 +0000)
committerAndré Malo <nd@apache.org>
Sun, 3 Aug 2003 20:15:50 +0000 (20:15 +0000)
- improve readability
- make sure that unsigned chars are compared
- use apr_size_t for string lengths

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@100895 13f79535-47bb-0310-9956-ffa450edef68

modules/mappers/mod_rewrite.c

index a194e9310743242ee42f28d5798c816d4ee81c86..7ef7e78eb3e16fe0ce778f03207a7aac34f8f7c8 100644 (file)
@@ -3216,28 +3216,24 @@ static const char *cmd_rewriterule(cmd_parms *cmd, void *in_dconf,
  */
 
 /* Lexicographic Compare */
-static APR_INLINE int compare_lexicography(char *cpNum1, char *cpNum2)
+static APR_INLINE int compare_lexicography(char *a, char *b)
 {
-    int i;
-    int n1, n2;
+    apr_size_t i, lena, lenb;
 
-    n1 = strlen(cpNum1);
-    n2 = strlen(cpNum2);
-    if (n1 > n2) {
-        return 1;
-    }
-    if (n1 < n2) {
-        return -1;
-    }
-    for (i = 0; i < n1; i++) {
-        if (cpNum1[i] > cpNum2[i]) {
-            return 1;
-        }
-        if (cpNum1[i] < cpNum2[i]) {
-            return -1;
+    lena = strlen(a);
+    lenb = strlen(b);
+
+    if (lena == lenb) {
+        for (i = 0; i < lena; ++i) {
+            if (a[i] != b[i]) {
+                return ((unsigned char)a[i] > (unsigned char)b[i]) ? 1 : -1;
+            }
         }
+
+        return 0;
     }
-    return 0;
+
+    return ((lena > lenb) ? 1 : -1);
 }
 
 /*