]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
parseRichDep: merge duplicated code into a skipnonwhite() inline function
authorMichael Schroeder <mls@suse.de>
Tue, 16 Jul 2019 11:20:12 +0000 (13:20 +0200)
committerMichael Schroeder <mls@suse.de>
Tue, 16 Jul 2019 11:20:12 +0000 (13:20 +0200)
ext/pool_parserpmrichdep.c

index 93d77f8e8094d4dd77b81873df3cfe7726d5bbf6..bf6cbef517a9608c434b9ea06fb1e1dd21cf1fca 100644 (file)
@@ -27,13 +27,23 @@ static struct RichOpComp {
   { NULL, 0, 0},
 };
 
+static inline const char *
+skipnonwhite(const char *p)
+{
+  int bl = 0;
+  while (*p && !(*p == ' ' || *p == ',' || (*p == ')' && bl-- <= 0)))
+    if (*p++ == '(')
+      bl++;
+  return p;
+}
+
 static Id
 parseRichDep(Pool *pool, const char **depp, Id chainfl)
 {
   const char *p = *depp;
   const char *n;
   Id id, evr;
-  int fl, bl;
+  int fl;
   struct RichOpComp *op;
 
   if (!chainfl && *p++ != '(')
@@ -51,10 +61,7 @@ parseRichDep(Pool *pool, const char **depp, Id chainfl)
   else
     {
       n = p;
-      bl = 0;
-      while (*p && !(*p == ' ' || *p == ',' || (*p == ')' && bl-- <= 0)))
-       if (*p++ == '(')
-         bl++;
+      p = skipnonwhite(p);
       if (n == p)
        return 0;
       id = pool_strn2id(pool, n, p - n, 1);
@@ -79,10 +86,7 @@ parseRichDep(Pool *pool, const char **depp, Id chainfl)
              while (*p == ' ')
                p++;
              n = p;
-             bl = 0;
-             while (*p && !(*p == ' ' || *p == ',' || (*p == ')' && bl-- <= 0)))
-               if (*p++ == '(')
-                 bl++;
+             p = skipnonwhite(p);
              if (p - n > 2 && n[0] == '0' && n[1] == ':')
                n += 2;         /* strip zero epoch */
              if (n == p)