Thanks to Alejandro Colomar for the suggestion and the code for the
define's that were added to lib.h.  This helps the readability a lot.
---
 crypt.c         |  2 +-
 imap/command.c  |  2 +-
 lib.c           |  2 +-
 lib.h           | 14 ++++++++++++++
 mutt_sasl_gnu.c |  2 +-
 muttlib.c       |  2 +-
 rfc2047.c       |  2 +-
 url.c           |  2 +-
 8 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/crypt.c b/crypt.c
index e4c8051d..80a6d6d1 100644
--- a/crypt.c
+++ b/crypt.c
@@ -1295,7 +1295,7 @@ short crypt_is_numerical_keyid(const char *s)
   if (strlen(s) % 8)
     return 0;
   while (*s)
-    if (strchr("0123456789ABCDEFabcdef", *s++) == NULL)
+    if (strchr(CTYPE_XDIGIT_C, *s++) == NULL)
       return 0;
 
   return 1;
diff --git a/imap/command.c b/imap/command.c
index 63dedf6c..77bb7b8f 100644
--- a/imap/command.c
+++ b/imap/command.c
@@ -701,7 +701,7 @@ static void cmd_parse_vanished(IMAP_DATA *idata, char *s)
   end_of_seqset = s;
   while (*end_of_seqset)
   {
-    if (!strchr("0123456789:,", *end_of_seqset))
+    if (!strchr(CTYPE_UIDS_RFC7162_C, *end_of_seqset))
       *end_of_seqset = '\0';
     else
       end_of_seqset++;
diff --git a/lib.c b/lib.c
index 9776fcdb..fdecda25 100644
--- a/lib.c
+++ b/lib.c
@@ -573,7 +573,7 @@ success:
 }
 
 
-static const char safe_chars[] = 
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+@{}._-:%";
+static const char safe_chars[] = CTYPE_PFCHAR_C "+@{}:%";
 
 void mutt_sanitize_filename(char *f, int flags)
 {
diff --git a/lib.h b/lib.h
index 25875656..08f1ac27 100644
--- a/lib.h
+++ b/lib.h
@@ -147,6 +147,20 @@ static inline char *skip_email_wsp(const char *s)
    on some systems */
 #define SKIP_LOCALE_WS(c) while (*(c) && IS_LOCALE_WS(*(c))) c++;
 
+/*
+ * Various useful sets of characters
+ */
+#define CTYPE_LOWER_C         "abcdefghijklmnopqrstuvwxyz"
+#define CTYPE_UPPER_C         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+#define CTYPE_DIGIT_C         "0123456789"
+#define CTYPE_ALPHA_C         CTYPE_LOWER_C CTYPE_UPPER_C
+#define CTYPE_ALNUM_C         CTYPE_ALPHA_C CTYPE_DIGIT_C
+#define CTYPE_PFCHAR_C        CTYPE_ALNUM_C "._-"      // portable filename 
character set
+#define CTYPE_UXDIGIT_C       CTYPE_DIGIT_C "ABCDEF"   // uppercase hex
+#define CTYPE_XDIGIT_C        CTYPE_UXDIGIT_C "abcdef" // hex
+
+#define CTYPE_UIDS_RFC7162_C  CTYPE_DIGIT_C ":,"  // known-uids
+
 /*
  * These functions aren't defined in lib.c, but
  * they are used there.
diff --git a/mutt_sasl_gnu.c b/mutt_sasl_gnu.c
index 9a7a4b87..2bd5afbf 100644
--- a/mutt_sasl_gnu.c
+++ b/mutt_sasl_gnu.c
@@ -66,7 +66,7 @@ void mutt_gsasl_done(void)
 }
 
 static const char *VALID_MECHANISM_CHARACTERS =
-  "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
+  CTYPE_UPPER_C CTYPE_DIGIT_C "-_";
 
 /* This logic is derived from the libgsasl suggest code */
 static int mechlist_contains(const char *uc_mech, const char *uc_mechlist)
diff --git a/muttlib.c b/muttlib.c
index d24a37f0..ee29cc17 100644
--- a/muttlib.c
+++ b/muttlib.c
@@ -1178,7 +1178,7 @@ void _mutt_buffer_quote_filename(BUFFER *d, const char 
*f, int add_outer)
     mutt_buffer_addch(d, '\'');
 }
 
-static const char safe_chars[] = 
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+@{}._-:%";
+static const char safe_chars[] = CTYPE_PFCHAR_C "+@{}:%";
 
 void mutt_buffer_sanitize_filename(BUFFER *d, const char *f, int flags)
 {
diff --git a/rfc2047.c b/rfc2047.c
index 2bdd8553..f043c9ab 100644
--- a/rfc2047.c
+++ b/rfc2047.c
@@ -257,7 +257,7 @@ static size_t b_encoder(char *s, ICONV_CONST char *d, 
size_t dlen,
 static size_t q_encoder(char *s, ICONV_CONST char *d, size_t dlen,
                         const char *tocode)
 {
-  static const char hex[] = "0123456789ABCDEF";
+  static const char hex[] = CTYPE_UXDIGIT_C;
   char *s0 = s;
 
   memcpy(s, "=?", 2), s += 2;
diff --git a/url.c b/url.c
index 02dbf34c..37d091cf 100644
--- a/url.c
+++ b/url.c
@@ -193,7 +193,7 @@ int url_parse_ciss(ciss_url_t *ciss, char *src)
 
 static void url_pct_encode(char *dst, size_t l, const char *src)
 {
-  static const char *alph = "0123456789ABCDEF";
+  static const char *alph = CTYPE_UXDIGIT_C;
 
   *dst = 0;
   l--;
-- 
2.55.0

Reply via email to