gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] 01/07: mhd_str: minor code refactoring


From: gnunet
Subject: [libmicrohttpd] 01/07: mhd_str: minor code refactoring
Date: Mon, 05 Jul 2021 16:07:42 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit d51a5ce419a322c290e5d052cc01541570e7ac0f
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Wed Jun 23 10:37:28 2021 +0300

    mhd_str: minor code refactoring
    
    Repeated caseless chars comparison function moved to static
    inline function.
---
 src/microhttpd/mhd_str.c | 46 +++++++++++++++++++++++++++++++++++-----------
 1 file changed, 35 insertions(+), 11 deletions(-)

diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c
index eea2500b..41697951 100644
--- a/src/microhttpd/mhd_str.c
+++ b/src/microhttpd/mhd_str.c
@@ -143,6 +143,7 @@ isasciialnum (char c)
 #endif /* Disable unused functions. */
 
 
+#if 0 /* Disable unused functions. */
 /**
  * Convert US-ASCII character to lower case.
  * If character is upper case letter in US-ASCII than it's converted to lower
@@ -159,7 +160,6 @@ toasciilower (char c)
 }
 
 
-#if 0 /* Disable unused functions. */
 /**
  * Convert US-ASCII character to upper case.
  * If character is lower case letter in US-ASCII than it's converted to upper
@@ -219,6 +219,23 @@ toxdigitvalue (char c)
 }
 
 
+/**
+ * Caseless compare two characters.
+ *
+ * @param c1 the first char to compare
+ * @param c1 the second char to compare
+ * @return boolean 'true' if chars are caseless equal, false otherwise
+ */
+_MHD_static_inline bool
+charsequalcaseless (const char c1, const char c2)
+{
+  return ( (c1 == c2) ||
+           (isasciiupper (c1) ?
+            ((c1 - 'A' + 'a') == c2) :
+            (isasciiupper (c2) && (c1 == (c2 - 'A' + 'a')))) );
+}
+
+
 #else  /* !INLINE_FUNC */
 
 
@@ -331,6 +348,20 @@ toxdigitvalue (char c)
                             ( (((char) (c)) >= 'a' && ((char) (c)) <= 'f') ? \
                               (int) (((unsigned char) (c)) - 'a' + 10) : \
                               (int) (-1) )))
+
+/**
+ * Caseless compare two characters.
+ *
+ * @param c1 the first char to compare
+ * @param c1 the second char to compare
+ * @return boolean 'true' if chars are caseless equal, false otherwise
+ */
+#define charsequalcaseless(c1, c2) \
+  ( ((c1) == (c2)) || \
+           (isasciiupper (c1) ? \
+             (((c1) - 'A' + 'a') == (c2)) : \
+             (isasciiupper (c2) && ((c1) == ((c2) - 'A' + 'a')))) )
+
 #endif /* !INLINE_FUNC */
 
 
@@ -392,10 +423,7 @@ MHD_str_equal_caseless_n_ (const char *const str1,
     const char c2 = str2[i];
     if (0 == c2)
       return 0 == c1;
-    if ( (c1 == c2) ||
-         (isasciiupper (c1) ?
-          ((c1 - 'A' + 'a') == c2) :
-          (isasciiupper (c2) && (c1 == (c2 - 'A' + 'a')))) )
+    if (charsequalcaseless (c1, c2))
       continue;
     else
       return 0;
@@ -424,10 +452,7 @@ MHD_str_equal_caseless_bin_n_ (const char *const str1,
   {
     const char c1 = str1[i];
     const char c2 = str2[i];
-    if ( (c1 == c2) ||
-         (isasciiupper (c1) ?
-          ((c1 - 'A' + 'a') == c2) :
-          (isasciiupper (c2) && (c1 == (c2 - 'A' + 'a')))) )
+    if (charsequalcaseless (c1, c2))
       continue;
     else
       return 0;
@@ -473,8 +498,7 @@ MHD_str_has_token_caseless_ (const char *str,
 
       if (0 == sc)
         return false;
-      if ( (sc != tc) &&
-           (toasciilower (sc) != toasciilower (tc)) )
+      if (! charsequalcaseless (sc, tc))
         break;
       if (i >= token_len)
       {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]