diff options
author | Vincent Ambo <tazjin@google.com> | 2020-05-25T14·54+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2020-05-25T14·54+0100 |
commit | bf452cbc2ae2b209ec262ce858deca470d086f24 (patch) | |
tree | 198e98902be569301ecb9a821b0c9512b128f930 /third_party/nix/src/libutil/util.cc | |
parent | b99b368d17f2e806a61f7abb83c6d3a9e4bbdc38 (diff) |
refactor(3p/nix): Replace tokenizeStrings with absl::StrSplit r/846
This function was a custom (and inefficient in the case of single-character delimiters) string splitter which was used all over the codebase. Abseil provides an appropriate replacement function.
Diffstat (limited to 'third_party/nix/src/libutil/util.cc')
-rw-r--r-- | third_party/nix/src/libutil/util.cc | 29 |
1 files changed, 4 insertions, 25 deletions
diff --git a/third_party/nix/src/libutil/util.cc b/third_party/nix/src/libutil/util.cc index fb9c6bfd5270..3f541134b88f 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) { |