From 98299da0fda612b42ab933c47f18163cfef5fa71 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 25 May 2020 01:19:02 +0100 Subject: refactor(3p/nix/libutil): Replace string2Int & trim functions 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. --- third_party/nix/src/libutil/util.hh | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'third_party/nix/src/libutil/util.hh') diff --git a/third_party/nix/src/libutil/util.hh b/third_party/nix/src/libutil/util.hh index 7d10df50bf5b..0f3752dfde5a 100644 --- a/third_party/nix/src/libutil/util.hh +++ b/third_party/nix/src/libutil/util.hh @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -97,8 +98,8 @@ unsigned char getFileType(const Path& path); /* Read the contents of a file into a string. */ std::string readFile(int fd); -std::string readFile(const Path& path, bool drain = false); -void readFile(const Path& path, Sink& sink); +std::string readFile(absl::string_view path, bool drain = false); +void readFile(absl::string_view path, Sink& sink); /* Write a string to a file. */ void writeFile(const Path& path, const std::string& s, mode_t mode = 0666); @@ -325,10 +326,6 @@ C tokenizeString(const std::string& s, std::string concatStringsSep(const std::string& sep, const Strings& ss); std::string concatStringsSep(const std::string& sep, const StringSet& ss); -/* Remove whitespace from the start and end of a string. */ -std::string trim(const std::string& s, - const std::string& whitespace = " \n\r\t"); - /* Replace all occurrences of a string inside another string. */ std::string replaceStrings(const std::string& s, const std::string& from, const std::string& to); @@ -339,16 +336,6 @@ std::string statusToString(int status); bool statusOk(int status); -/* Parse a string into an integer. */ -template -bool string2Int(const std::string& s, N& n) { - if (std::string(s, 0, 1) == "-" && !std::numeric_limits::is_signed) - return false; - std::istringstream str(s); - str >> n; - return str && str.get() == EOF; -} - /* Parse a string into a float. */ template bool string2Float(const std::string& s, N& n) { -- cgit 1.4.1