]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ctype: add ISUNRESERVED()
authorDaniel Stenberg <daniel@haxx.se>
Tue, 12 Sep 2023 13:38:02 +0000 (15:38 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 13 Sep 2023 12:29:44 +0000 (14:29 +0200)
... and make Curl_isunreserved() use that macro instead of providing a
separate funtion for the purpose.

Closes #11840

lib/curl_ctype.h
lib/escape.c
lib/escape.h

index 1d1d60c28d15183ac781b8cd2996a92111782d0c..c7b370c592139326e26ebbb8acf7bf9972e33a0e 100644 (file)
@@ -43,5 +43,9 @@
 #define ISDIGIT(x)  (((x) >= '0') && ((x) <= '9'))
 #define ISBLANK(x)  (((x) == ' ') || ((x) == '\t'))
 #define ISSPACE(x)  (ISBLANK(x) || (((x) >= 0xa) && ((x) <= 0x0d)))
+#define isurlpuntcs(x) (((x) == '-') || ((x) == '.') || ((x) == '_') || \
+                        ((x) == '~'))
+#define ISUNRESERVED(x) (ISALNUM(x) || isurlpuntcs(x))
+
 
 #endif /* HEADER_CURL_CTYPE_H */
index 56aa2b39888866b17e8335fe78d0b1c2de1ebc60..2fc1d1ee56ea288fce9f3575bf1fec4ff79e3232 100644 (file)
 #include "curl_memory.h"
 #include "memdebug.h"
 
-/* Portable character check (remember EBCDIC). Do not use isalnum() because
-   its behavior is altered by the current locale.
-   See https://datatracker.ietf.org/doc/html/rfc3986#section-2.3
-*/
-bool Curl_isunreserved(unsigned char in)
-{
-  switch(in) {
-    case '0': case '1': case '2': case '3': case '4':
-    case '5': case '6': case '7': case '8': case '9':
-    case 'a': case 'b': case 'c': case 'd': case 'e':
-    case 'f': case 'g': case 'h': case 'i': case 'j':
-    case 'k': case 'l': case 'm': case 'n': case 'o':
-    case 'p': case 'q': case 'r': case 's': case 't':
-    case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
-    case 'A': case 'B': case 'C': case 'D': case 'E':
-    case 'F': case 'G': case 'H': case 'I': case 'J':
-    case 'K': case 'L': case 'M': case 'N': case 'O':
-    case 'P': case 'Q': case 'R': case 'S': case 'T':
-    case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
-    case '-': case '.': case '_': case '~':
-      return TRUE;
-    default:
-      break;
-  }
-  return FALSE;
-}
-
 /* for ABI-compatibility with previous versions */
 char *curl_escape(const char *string, int inlength)
 {
index cdbb712acc1792d744ee2f97504505686cb7fcc9..b9fd272f6b9772ae2692346f74257267824129be 100644 (file)
@@ -26,7 +26,9 @@
 /* Escape and unescape URL encoding in strings. The functions return a new
  * allocated string or NULL if an error occurred.  */
 
-bool Curl_isunreserved(unsigned char in);
+#include "curl_ctype.h"
+
+#define Curl_isunreserved(x) ISUNRESERVED(x)
 
 enum urlreject {
   REJECT_NADA = 2,