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

@ -1,6 +1,7 @@
#include <regex>
#include <absl/strings/ascii.h>
#include <absl/strings/str_split.h>
#include <fcntl.h>
#include <pwd.h>
@ -24,13 +25,15 @@ static void readChannels() {
}
auto channelsFile = readFile(channelsList);
for (const auto& line :
tokenizeString<std::vector<std::string>>(channelsFile, "\n")) {
absl::StripTrailingAsciiWhitespace(line);
std::vector<std::string> lines =
absl::StrSplit(channelsFile, absl::ByChar('\n'));
for (auto& line : lines) {
line = absl::StripTrailingAsciiWhitespace(line);
if (std::regex_search(line, std::regex("^\\s*\\#"))) {
continue;
}
auto split = tokenizeString<std::vector<std::string>>(line, " ");
std::vector<std::string> split = absl::StrSplit(line, absl::ByChar(' '));
auto url = std::regex_replace(split[0], std::regex("/*$"), "");
auto name = split.size() > 1 ? split[1] : baseNameOf(url);
channels[name] = url;