]> granicus.if.org Git - graphviz/commitdiff
str_mod: [nfc] rewrite in more modern C99 style
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 15 Jul 2021 04:12:16 +0000 (21:12 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 21 Jul 2021 14:45:42 +0000 (07:45 -0700)
Upcoming changes will improve the efficiency of this function and decrease its
coupling with other operations. Rather than introduce these new changes in a
differing style, this preparatory commit rewrites the existing functionality in
this style first, without affecting its behavior. Related to #1873, #1998.

lib/expr/exeval.c

index f3118b29af671befd1548c915b343596815ba461..3c272e1bfc5727e8bc2c455cef28ff213eb1a66d 100644 (file)
@@ -691,15 +691,14 @@ static char *str_xor(Expr_t *ex, const char *l, const char *r) {
  * string mod
  */
 
-static char*
-str_mod(Expr_t* ex, char* l, char* r)
-{
-       int     c;
+static char *str_mod(Expr_t *ex, const char *l, const char *r) {
 
-       while ((c = *l++))
-               if (!strchr(r, c) && !strchr(l, c))
-                       sfputc(ex->tmp, c);
-       return exstash(ex->tmp, ex->ve);
+  for (const char *p = l; *p != '\0'; ++p) {
+    if (strchr(r, *p) == NULL && strchr(p + 1, *p) == NULL) {
+      sfputc(ex->tmp, *p);
+    }
+  }
+  return exstash(ex->tmp, ex->ve);
 }
 
 /*