]> granicus.if.org Git - graphviz/commitdiff
str_and: [nfc] rewrite in more modern C99 style
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 15 Jul 2021 03:42:24 +0000 (20:42 -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 090c4b5b1ee569a8e49425393a4d8f1078781146..c366079ae158598a73b527528e37521447b626bb 100644 (file)
@@ -609,15 +609,14 @@ static char *str_ior(Expr_t *ex, const char *l, const char *r) {
  * string and
  */
 
-static char*
-str_and(Expr_t* ex, char* l, char* r)
-{
-       int     c;
+static char *str_and(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);
 }
 
 /*