about summary refs log tree commit diff
path: root/third_party/nix/src/libexpr/names.cc
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-20T21·27+0100
committerVincent Ambo <tazjin@google.com>2020-05-20T21·27+0100
commit689ef502f5b0655c9923ed77da2ae3504630f473 (patch)
tree3e331c153646f136875f047cc3b9f0aad8c86341 /third_party/nix/src/libexpr/names.cc
parentd331d3a0b5c497a46e2636f308234be66566c04c (diff)
refactor(3p/nix): Apply clang-tidy's readability-* fixes r/788
This applies the readability fixes listed here:

https://clang.llvm.org/extra/clang-tidy/checks/list.html
Diffstat (limited to 'third_party/nix/src/libexpr/names.cc')
-rw-r--r--third_party/nix/src/libexpr/names.cc25
1 files changed, 13 insertions, 12 deletions
diff --git a/third_party/nix/src/libexpr/names.cc b/third_party/nix/src/libexpr/names.cc
index ecad90c960..f559c13a61 100644
--- a/third_party/nix/src/libexpr/names.cc
+++ b/third_party/nix/src/libexpr/names.cc
@@ -17,7 +17,7 @@ DrvName::DrvName(const string& s) : hits(0) {
   name = fullName = s;
   for (unsigned int i = 0; i < s.size(); ++i) {
     /* !!! isalpha/isdigit are affected by the locale. */
-    if (s[i] == '-' && i + 1 < s.size() && !isalpha(s[i + 1])) {
+    if (s[i] == '-' && i + 1 < s.size() && (isalpha(s[i + 1]) == 0)) {
       name = string(s, 0, i);
       version = string(s, i + 1);
       break;
@@ -34,10 +34,7 @@ bool DrvName::matches(DrvName& n) {
       return false;
     }
   }
-  if (version != "" && version != n.version) {
-    return false;
-  }
-  return true;
+  return !(!version.empty() && version != n.version);
 }
 
 string nextComponent(string::const_iterator& p,
@@ -55,12 +52,12 @@ string nextComponent(string::const_iterator& p,
      of digits.  Otherwise, consume the longest sequence of
      non-digit, non-separator characters. */
   string s;
-  if (isdigit(*p)) {
-    while (p != end && isdigit(*p)) {
+  if (isdigit(*p) != 0) {
+    while (p != end && (isdigit(*p) != 0)) {
       s += *p++;
     }
   } else {
-    while (p != end && (!isdigit(*p) && *p != '.' && *p != '-')) {
+    while (p != end && ((isdigit(*p) == 0) && *p != '.' && *p != '-')) {
       s += *p++;
     }
   }
@@ -69,12 +66,15 @@ string nextComponent(string::const_iterator& p,
 }
 
 static bool componentsLT(const string& c1, const string& c2) {
-  int n1, n2;
-  bool c1Num = string2Int(c1, n1), c2Num = string2Int(c2, n2);
+  int n1;
+  int n2;
+  bool c1Num = string2Int(c1, n1);
+  bool c2Num = string2Int(c2, n2);
 
   if (c1Num && c2Num) {
     return n1 < n2;
-  } else if (c1 == "" && c2Num) {
+  }
+  if (c1.empty() && c2Num) {
     return true;
   } else if (c1 == "pre" && c2 != "pre") {
     return true;
@@ -99,7 +99,8 @@ int compareVersions(const string& v1, const string& v2) {
     string c2 = nextComponent(p2, v2.end());
     if (componentsLT(c1, c2)) {
       return -1;
-    } else if (componentsLT(c2, c1)) {
+    }
+    if (componentsLT(c2, c1)) {
       return 1;
     }
   }