about summary refs log tree commit diff
path: root/third_party/nix/src/nix-env/nix-env.cc
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-25T00·19+0100
committerVincent Ambo <tazjin@google.com>2020-05-25T00·19+0100
commit98299da0fda612b42ab933c47f18163cfef5fa71 (patch)
tree78fc0f1127b5f2336d3e370f342f72f38d5a5ee2 /third_party/nix/src/nix-env/nix-env.cc
parentb371821db59d33851d521d66ba1fb126d388c00f (diff)
refactor(3p/nix/libutil): Replace string2Int & trim functions r/843
Replaces these functions with corresponding functions from Abseil,
namely absl::StripAsciiWhitespace and absl::SimpleAtoi.

In the course of doing this some minor things I encountered along the
way were also refactored.

This also changes the signatures of the various custom readFile
functions to use absl::string_view types.
Diffstat (limited to 'third_party/nix/src/nix-env/nix-env.cc')
-rw-r--r--third_party/nix/src/nix-env/nix-env.cc7
1 files changed, 4 insertions, 3 deletions
diff --git a/third_party/nix/src/nix-env/nix-env.cc b/third_party/nix/src/nix-env/nix-env.cc
index e827f31e5df8..d17bde34f3cd 100644
--- a/third_party/nix/src/nix-env/nix-env.cc
+++ b/third_party/nix/src/nix-env/nix-env.cc
@@ -4,6 +4,7 @@
 #include <iostream>
 #include <sstream>
 
+#include <absl/strings/numbers.h>
 #include <glog/logging.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -1303,7 +1304,7 @@ static void opSwitchGeneration(Globals& globals, Strings opFlags,
   }
 
   int dstGen;
-  if (!string2Int(opArgs.front(), dstGen)) {
+  if (!absl::SimpleAtoi(opArgs.front(), &dstGen)) {
     throw UsageError(format("expected a generation number"));
   }
 
@@ -1369,7 +1370,7 @@ static void opDeleteGenerations(Globals& globals, Strings opFlags,
     }
     std::string str_max = std::string(opArgs.front(), 1, opArgs.front().size());
     int max;
-    if (!string2Int(str_max, max) || max == 0) {
+    if (!absl::SimpleAtoi(str_max, &max) || max == 0) {
       throw Error(format("invalid number of generations to keep ‘%1%’") %
                   opArgs.front());
     }
@@ -1378,7 +1379,7 @@ static void opDeleteGenerations(Globals& globals, Strings opFlags,
     std::set<unsigned int> gens;
     for (auto& i : opArgs) {
       unsigned int n;
-      if (!string2Int(i, n)) {
+      if (!absl::SimpleAtoi(i, &n)) {
         throw UsageError(format("invalid generation number '%1%'") % i);
       }
       gens.insert(n);