diff options
| author | Julian Andres Klode <jak@debian.org> | 2025-07-28 12:06:00 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2025-10-25 18:42:14 +0000 |
| commit | 50d8703c785898d06463513896e37cbe7cedd471 (patch) | |
| tree | e43b858bb0a0efe70ef1428325eaa2b414ec3e39 | |
| parent | a92a5ecc465055027d9fbb899f359ec7eab110bd (diff) | |
Move split() to APT::String::Split()
This splits based upon contiguous whitespace as separators
| -rw-r--r-- | apt-pkg/contrib/strutl.cc | 11 | ||||
| -rw-r--r-- | apt-pkg/contrib/strutl.h | 1 | ||||
| -rw-r--r-- | apt-pkg/init.cc | 17 |
3 files changed, 14 insertions, 15 deletions
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 651c985bd..b5200831a 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -138,6 +138,17 @@ size_t DisplayLength(string_view str) return len; } +// Splits by whitespace. There may be continuous spans of whitespace - they +// will be considered as one. +std::vector<std::string> Split(std::string const &s) +{ + std::vector<std::string> vec; + std::istringstream iss(s); + iss.imbue(std::locale::classic()); + for (std::string current_s; iss >> current_s;) + vec.push_back(current_s); + return vec; +} } } /*}}}*/ diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index 79b7c8bfa..c22b2dda2 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -48,6 +48,7 @@ namespace APT { APT_PUBLIC std::string Join(std::vector<std::string> list, const std::string_view &sep); // Returns string display length honoring multi-byte characters APT_PUBLIC size_t DisplayLength(std::string_view str); + APT_HIDDEN std::vector<std::string> Split(std::string const &str); } } diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc index 61d45e37e..531cd258d 100644 --- a/apt-pkg/init.cc +++ b/apt-pkg/init.cc @@ -38,19 +38,6 @@ namespace APT { APT_HIDDEN extern std::unordered_map<std::string, std::vector<std::string>> ArchToTupleMap; } -// Splits by whitespace. There may be continuous spans of whitespace - they -// will be considered as one. -static std::vector<std::string> split(std::string const & s) -{ - std::vector<std::string> vec; - std::istringstream iss(s); - iss.imbue(std::locale::classic()); - for(std::string current_s; iss >> current_s; ) - vec.push_back(current_s); - return vec; -} - - // pkgInitArchTupleMap - Initialize the architecture tuple map /*{{{*/ // --------------------------------------------------------------------- /* This initializes */ @@ -67,7 +54,7 @@ static bool pkgInitArchTupleMap() { if (cpuline[0] == '#' || cpuline[0] == '\0') continue; - auto cpurow = split(cpuline); + auto cpurow = APT::String::Split(cpuline); auto cpu = APT::String::Strip(cpurow.at(0)); cpus.emplace_back(cpu); @@ -90,7 +77,7 @@ static bool pkgInitArchTupleMap() if (tupleline[0] == '#' || tupleline[0] == '\0') continue; - std::vector<std::string> tuplerow = split(tupleline); + std::vector<std::string> tuplerow = APT::String::Split(tupleline); auto tuple = APT::String::Strip(tuplerow.at(0)); auto arch = APT::String::Strip(tuplerow.at(1)); |
