refactor(3p/nix): Replace tokenizeStrings with absl::StrSplit

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.
This commit is contained in:
Vincent Ambo 2020-05-25 15:54:14 +01:00
parent b99b368d17
commit bf452cbc2a
29 changed files with 146 additions and 145 deletions

View file

@ -3,6 +3,7 @@
#include <absl/strings/ascii.h>
#include <absl/strings/match.h>
#include <absl/strings/str_split.h>
#include <glog/logging.h>
#include <sys/time.h>
@ -48,11 +49,11 @@ HgInfo exportMercurial(ref<Store> store, const std::string& uri,
hgInfo.branch = absl::StripTrailingAsciiWhitespace(
runProgram("hg", true, {"branch", "-R", uri}));
auto files = tokenizeString<std::set<std::string>>(
std::set<std::string> files = absl::StrSplit(
runProgram("hg", true,
{"status", "-R", uri, "--clean", "--modified", "--added",
"--no-status", "--print0"}),
"\0"s);
absl::ByChar('\0'));
PathFilter filter = [&](const Path& p) -> bool {
assert(absl::StartsWith(p, uri));
@ -124,10 +125,11 @@ HgInfo exportMercurial(ref<Store> store, const std::string& uri,
writeFile(stampFile, "");
}
auto tokens = tokenizeString<std::vector<std::string>>(
runProgram("hg", true,
{"log", "-R", cacheDir, "-r", rev, "--template",
"{node} {rev} {branch}"}));
std::vector<std::string> tokens =
absl::StrSplit(runProgram("hg", true,
{"log", "-R", cacheDir, "-r", rev, "--template",
"{node} {rev} {branch}"}),
absl::ByAnyChar(" \t\n\r"));
assert(tokens.size() == 3);
HgInfo hgInfo;