about summary refs log tree commit diff
path: root/third_party/nix/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/nix/src/libutil')
-rw-r--r--third_party/nix/src/libutil/config.cc14
-rw-r--r--third_party/nix/src/libutil/util.cc29
-rw-r--r--third_party/nix/src/libutil/util.hh7
3 files changed, 14 insertions, 36 deletions
diff --git a/third_party/nix/src/libutil/config.cc b/third_party/nix/src/libutil/config.cc
index bc81ce77ce..9e3f6f85c5 100644
--- a/third_party/nix/src/libutil/config.cc
+++ b/third_party/nix/src/libutil/config.cc
@@ -1,14 +1,16 @@
-#define GOOGLE_STRIP_LOG 0
 #include "config.hh"
 
+#include <string>
 #include <utility>
+#include <vector>
 
 #include <absl/strings/numbers.h>
+#include <absl/strings/str_split.h>
+#include <absl/strings/string_view.h>
 #include <glog/logging.h>
 
 #include "args.hh"
 #include "json.hh"
-// #include <glog/log_severity.h>
 
 namespace nix {
 
@@ -99,7 +101,9 @@ void AbstractConfig::applyConfigFile(const Path& path) {
         line = std::string(line, 0, hash);
       }
 
-      auto tokens = tokenizeString<std::vector<std::string> >(line);
+      // TODO(tazjin): absl::string_view after path functions are fixed.
+      std::vector<std::string> tokens =
+          absl::StrSplit(line, absl::ByAnyChar(" \t\n\r"));
       if (tokens.empty()) {
         continue;
       }
@@ -258,7 +262,7 @@ void BaseSetting<bool>::convertToArg(Args& args, const std::string& category) {
 
 template <>
 void BaseSetting<Strings>::set(const std::string& str) {
-  value = tokenizeString<Strings>(str);
+  value = absl::StrSplit(str, absl::ByAnyChar(" \t\n\r"));
 }
 
 template <>
@@ -276,7 +280,7 @@ void BaseSetting<Strings>::toJSON(JSONPlaceholder& out) {
 
 template <>
 void BaseSetting<StringSet>::set(const std::string& str) {
-  value = tokenizeString<StringSet>(str);
+  value = absl::StrSplit(str, absl::ByAnyChar(" \t\n\r"));
 }
 
 template <>
diff --git a/third_party/nix/src/libutil/util.cc b/third_party/nix/src/libutil/util.cc
index fb9c6bfd52..3f541134b8 100644
--- a/third_party/nix/src/libutil/util.cc
+++ b/third_party/nix/src/libutil/util.cc
@@ -12,6 +12,7 @@
 #include <thread>
 #include <utility>
 
+#include <absl/strings/str_split.h>
 #include <absl/strings/string_view.h>
 #include <fcntl.h>
 #include <grp.h>
@@ -165,7 +166,7 @@ Path canonPath(const Path& path, bool resolveSymlinks) {
   return s.empty() ? "/" : s;
 }
 
-Path dirOf(const Path& path) {
+Path dirOf(absl::string_view path) {
   Path::size_type pos = path.rfind('/');
   if (pos == std::string::npos) {
     return ".";
@@ -542,7 +543,8 @@ Path getConfigDir() {
 std::vector<Path> getConfigDirs() {
   Path configHome = getConfigDir();
   std::string configDirs = getEnv("XDG_CONFIG_DIRS");
-  auto result = tokenizeString<std::vector<std::string>>(configDirs, ":");
+  std::vector<std::string> result =
+      absl::StrSplit(configDirs, absl::ByChar(':'));
   result.insert(result.begin(), configHome);
   return result;
 }
@@ -1170,29 +1172,6 @@ void _interrupted() {
 
 //////////////////////////////////////////////////////////////////////
 
-template <class C>
-C tokenizeString(const std::string& s, const std::string& separators) {
-  C result;
-  std::string::size_type pos = s.find_first_not_of(separators, 0);
-  while (pos != std::string::npos) {
-    std::string::size_type end = s.find_first_of(separators, pos + 1);
-    if (end == std::string::npos) {
-      end = s.size();
-    }
-    std::string token(s, pos, end - pos);
-    result.insert(result.end(), token);
-    pos = s.find_first_not_of(separators, end);
-  }
-  return result;
-}
-
-template Strings tokenizeString(const std::string& s,
-                                const std::string& separators);
-template StringSet tokenizeString(const std::string& s,
-                                  const std::string& separators);
-template std::vector<std::string> tokenizeString(const std::string& s,
-                                                 const std::string& separators);
-
 std::string concatStringsSep(const std::string& sep, const Strings& ss) {
   std::string s;
   for (auto& i : ss) {
diff --git a/third_party/nix/src/libutil/util.hh b/third_party/nix/src/libutil/util.hh
index 51d9979e16..27e6b47fb2 100644
--- a/third_party/nix/src/libutil/util.hh
+++ b/third_party/nix/src/libutil/util.hh
@@ -56,7 +56,7 @@ Path canonPath(const Path& path, bool resolveSymlinks = false);
    everything before the final `/'.  If the path is the root or an
    immediate child thereof (e.g., `/foo'), this means an empty string
    is returned. */
-Path dirOf(const Path& path);
+Path dirOf(absl::string_view path);
 
 /* Return the base name of the given canonical path, i.e., everything
    following the final `/'. */
@@ -316,11 +316,6 @@ MakeError(Interrupted, BaseError);
 
 MakeError(FormatError, Error);
 
-/* String tokenizer. */
-template <class C>
-C tokenizeString(const std::string& s,
-                 const std::string& separators = " \t\n\r");
-
 /* Concatenate the given strings with a separator between the
    elements. */
 std::string concatStringsSep(const std::string& sep, const Strings& ss);