]> granicus.if.org Git - neomutt/commitdiff
mutt_str_startswith - init.c
authorPietro Cerutti <gahr@gahr.ch>
Fri, 9 Nov 2018 15:11:41 +0000 (15:11 +0000)
committerRichard Russon <rich@flatcap.org>
Wed, 14 Nov 2018 15:10:31 +0000 (15:10 +0000)
init.c

diff --git a/init.c b/init.c
index d33187e159bc04707fbc26eb2cb8d498760ad75f..9f669b75ae4363ab78de20ef3cd257550857702b 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1032,14 +1032,14 @@ static int parse_attachments(struct Buffer *buf, struct Buffer *s,
     op = '+';
     category--;
   }
-  if (mutt_str_strncasecmp(category, "attachment", strlen(category)) == 0)
+  if (mutt_str_startswith("attachment", category, CASE_IGNORE))
   {
     if (op == '+')
       head = &AttachAllow;
     else
       head = &AttachExclude;
   }
-  else if (mutt_str_strncasecmp(category, "inline", strlen(category)) == 0)
+  else if (mutt_str_startswith("inline", category, CASE_IGNORE))
   {
     if (op == '+')
       head = &InlineAllow;
@@ -1434,13 +1434,13 @@ static int parse_set(struct Buffer *buf, struct Buffer *s, unsigned long data,
       query = true;
       s->dptr++;
     }
-    else if (mutt_str_strncmp("no", s->dptr, 2) == 0)
+    else if (mutt_str_startswith(s->dptr, "no", CASE_MATCH))
     {
       prefix = true;
       unset = !unset;
       s->dptr += 2;
     }
-    else if (mutt_str_strncmp("inv", s->dptr, 3) == 0)
+    else if (mutt_str_startswith(s->dptr, "inv", CASE_MATCH))
     {
       prefix = true;
       inv = !inv;
@@ -1467,7 +1467,7 @@ static int parse_set(struct Buffer *buf, struct Buffer *s, unsigned long data,
     bool equals = false;
 
     struct HashElem *he = NULL;
-    bool my = (mutt_str_strncmp("my_", buf->data, 3) == 0);
+    bool my = mutt_str_startswith(buf->data, "my_", CASE_MATCH);
     if (!my)
     {
       he = cs_get_elem(Config, buf->data);
@@ -1764,7 +1764,6 @@ static int parse_setenv(struct Buffer *buf, struct Buffer *s,
 
   /* get variable name */
   mutt_extract_token(buf, s, MUTT_TOKEN_EQUAL);
-  int len = strlen(buf->data);
 
   if (query)
   {
@@ -1772,7 +1771,7 @@ static int parse_setenv(struct Buffer *buf, struct Buffer *s,
     while (envp && *envp)
     {
       /* This will display all matches for "^QUERY" */
-      if (mutt_str_strncmp(buf->data, *envp, len) == 0)
+      if (mutt_str_startswith(*envp, buf->data, CASE_MATCH))
       {
         if (!found)
         {
@@ -2219,14 +2218,14 @@ static int parse_unattachments(struct Buffer *buf, struct Buffer *s,
     op = '+';
     p--;
   }
-  if (mutt_str_strncasecmp(p, "attachment", strlen(p)) == 0)
+  if (mutt_str_startswith("attachment", p, CASE_IGNORE))
   {
     if (op == '+')
       head = &AttachAllow;
     else
       head = &AttachExclude;
   }
-  else if (mutt_str_strncasecmp(p, "inline", strlen(p)) == 0)
+  else if (mutt_str_startswith("inline", p, CASE_IGNORE))
   {
     if (op == '+')
       head = &InlineAllow;
@@ -3295,20 +3294,20 @@ int mutt_command_complete(char *buf, size_t buflen, int pos, int numtabs)
     /* return the completed command */
     strncpy(buf, Completed, buflen - spaces);
   }
-  else if ((mutt_str_strncmp(buf, "set", 3) == 0) ||
-           (mutt_str_strncmp(buf, "unset", 5) == 0) ||
-           (mutt_str_strncmp(buf, "reset", 5) == 0) ||
-           (mutt_str_strncmp(buf, "toggle", 6) == 0))
+  else if (mutt_str_startswith(buf, "set", CASE_MATCH) ||
+           mutt_str_startswith(buf, "unset", CASE_MATCH) ||
+           mutt_str_startswith(buf, "reset", CASE_MATCH) ||
+           mutt_str_startswith(buf, "toggle", CASE_MATCH))
   { /* complete variables */
     static const char *const prefixes[] = { "no", "inv", "?", "&", 0 };
 
     pt++;
     /* loop through all the possible prefixes (no, inv, ...) */
-    if (mutt_str_strncmp(buf, "set", 3) == 0)
+    if (mutt_str_startswith(buf, "set", CASE_MATCH))
     {
       for (num = 0; prefixes[num]; num++)
       {
-        if (mutt_str_strncmp(pt, prefixes[num], mutt_str_strlen(prefixes[num])) == 0)
+        if (mutt_str_startswith(pt, prefixes[num], CASE_MATCH))
         {
           pt += mutt_str_strlen(prefixes[num]);
           break;
@@ -3353,7 +3352,7 @@ int mutt_command_complete(char *buf, size_t buflen, int pos, int numtabs)
 
     strncpy(pt, Completed, buf + buflen - pt - spaces);
   }
-  else if (mutt_str_strncmp(buf, "exec", 4) == 0)
+  else if (mutt_str_startswith(buf, "exec", CASE_MATCH))
   {
     const struct Binding *menu = km_get_table(CurrentMenu);
 
@@ -3608,7 +3607,7 @@ int mutt_var_value_complete(char *buf, size_t buflen, int pos)
   if (*pt == '=') /* abort if no var before the '=' */
     return 0;
 
-  if (mutt_str_strncmp(buf, "set", 3) == 0)
+  if (mutt_str_startswith(buf, "set", CASE_MATCH))
   {
     const char *myvarval = NULL;
     char var[STRING];