diff options
| -rw-r--r-- | apt-pkg/cachefilter-patterns.h | 7 | ||||
| -rw-r--r-- | apt-pkg/edsp.cc | 23 | ||||
| -rw-r--r-- | apt-pkg/pkgcache.cc | 37 | ||||
| -rw-r--r-- | apt-pkg/pkgcache.h | 4 |
4 files changed, 37 insertions, 34 deletions
diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h index 75784e040..1714bbb62 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -475,12 +475,7 @@ struct APT_HIDDEN VersionIsPriority : public VersionAnyMatcher explicit VersionIsPriority(std::string name) : name(name) {} bool operator()(pkgCache::VerIterator const &Ver) override { - std::string Mapping[] = {"", "required","important","standard", - "optional","extra"}; - if (Ver->Priority > 0 && Ver->Priority < APT_ARRAY_SIZE(Mapping)) { - return name == Mapping[Ver->Priority]; - } - return false; + return Ver->Priority > 0 && name == pkgCache::Priority_NoL10n(Ver->Priority); } }; diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc index d3ce830ea..88f572f18 100644 --- a/apt-pkg/edsp.cc +++ b/apt-pkg/edsp.cc @@ -41,17 +41,6 @@ using std::string; -// we could use pkgCache::DepType and ::Priority, but these would be localized strings⦠-constexpr char const * const PrioMap[] = { - nullptr, "important", "required", "standard", - "optional", "extra" -}; -constexpr char const * const DepMap[] = { - nullptr, "Depends", "Pre-Depends", "Suggests", - "Recommends" , "Conflicts", "Replaces", - "Obsoletes", "Breaks", "Enhances" -}; - // WriteOkay - varaidic helper to easily Write to a FileFd /*{{{*/ static bool WriteOkay_fn(FileFd &) { return true; } template<typename... Tail> static bool WriteOkay_fn(FileFd &output, std::string_view data, Tail... more_data) @@ -99,7 +88,7 @@ static bool WriteScenarioVersion(FileFd &output, pkgCache::PkgIterator const &Pk // WriteScenarioDependency /*{{{*/ static bool WriteScenarioDependency(FileFd &output, pkgCache::VerIterator const &Ver, bool const OnlyCritical) { - std::array<std::string, APT_ARRAY_SIZE(DepMap)> dependencies; + std::array<std::string, 10> dependencies; bool orGroup = false; for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep) { @@ -123,7 +112,7 @@ static bool WriteScenarioDependency(FileFd &output, pkgCache::VerIterator const bool Okay = output.Failed() == false; for (size_t i = 1; i < dependencies.size(); ++i) if (dependencies[i].empty() == false) - WriteOkay(Okay, output, "\n", DepMap[i], ": ", dependencies[i]); + WriteOkay(Okay, output, "\n", pkgCache::DepType_NoL10n(i), ": ", dependencies[i]); std::vector<std::string> provides; for (auto Prv = Ver.ProvidesList(); not Prv.end(); ++Prv) { @@ -152,7 +141,7 @@ static bool WriteScenarioLimitedDependency(FileFd &output, std::vector<bool> const &pkgset, bool const OnlyCritical) { - std::array<std::string, APT_ARRAY_SIZE(DepMap)> dependencies; + std::array<std::string, 10> dependencies; bool orGroup = false; for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep) { @@ -189,7 +178,7 @@ static bool WriteScenarioLimitedDependency(FileFd &output, bool Okay = output.Failed() == false; for (size_t i = 1; i < dependencies.size(); ++i) if (dependencies[i].empty() == false) - WriteOkay(Okay, output, "\n", DepMap[i], ": ", dependencies[i]); + WriteOkay(Okay, output, "\n", pkgCache::DepType_NoL10n(i), ": ", dependencies[i]); string provides; for (pkgCache::PrvIterator Prv = Ver.ProvidesList(); Prv.end() == false; ++Prv) { @@ -250,8 +239,8 @@ static bool WriteScenarioEDSPVersion(pkgDepCache &Cache, FileFd &output, pkgCach { bool Okay = WriteOkay(output, "\nSource: ", Ver.SourcePkgName(), "\nSource-Version: ", Ver.SourceVerStr()); - if (PrioMap[Ver->Priority] != nullptr) - WriteOkay(Okay, output, "\nPriority: ", PrioMap[Ver->Priority]); + if (auto const Prio = pkgCache::Priority_NoL10n(Ver->Priority); not Prio.empty()) + WriteOkay(Okay, output, "\nPriority: ", Prio); if (Ver->Section != 0) WriteOkay(Okay, output, "\nSection: ", Ver.Section()); if (Pkg.CurrentVer() == Ver) diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index ffe30fa92..57c6d2b22 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -32,6 +32,7 @@ #include <apt-pkg/version.h> #include <algorithm> +#include <array> #include <cstddef> #include <cstring> #include <sstream> @@ -340,24 +341,40 @@ const char *pkgCache::CompType(unsigned char Comp) /* */ const char *pkgCache::DepType(unsigned char Type) { - const char *Types[] = {"",_("Depends"),_("PreDepends"),_("Suggests"), - _("Recommends"),_("Conflicts"),_("Replaces"), - _("Obsoletes"),_("Breaks"), _("Enhances")}; - if (Type < sizeof(Types)/sizeof(*Types)) + std::array<char const *, 12> Types{nullptr, _("Depends"), _("PreDepends"), _("Suggests"), + _("Recommends"), _("Conflicts"), _("Replaces"), + _("Obsoletes"), _("Breaks"), _("Enhances")}; + if (Type < Types.size()) return Types[Type]; return ""; } +std::string_view pkgCache::DepType_NoL10n(unsigned char Type) +{ + std::array<std::string_view, 12> Types{"", "Depends", "PreDepends", "Suggests", + "Recommends", "Conflicts", "Replaces", + "Obsoletes", "Breaks", "Enhances"}; + if (Type < Types.size()) + return Types[Type]; + return {}; +} /*}}}*/ // Cache::Priority - Convert a priority value to a string /*{{{*/ -// --------------------------------------------------------------------- -/* */ const char *pkgCache::Priority(unsigned char Prio) { - const char *Mapping[] = {0,_("required"),_("important"),_("standard"), - _("optional"),_("extra")}; - if (Prio < APT_ARRAY_SIZE(Mapping)) + std::array<char const *, 6> Mapping{nullptr, _("required"), _("important"), _("standard"), + _("optional"), _("extra")}; + if (Prio < Mapping.size()) + return Mapping[Prio]; + return nullptr; +} +std::string_view pkgCache::Priority_NoL10n(unsigned char Prio) +{ + constexpr std::array<std::string_view, 6> const Mapping{ + "", "required", "important", "standard", "optional", "extra" + }; + if (Prio < Mapping.size()) return Mapping[Prio]; - return 0; + return {}; } /*}}}*/ // GrpIterator::FindPkg - Locate a package by arch /*{{{*/ diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index 7c16f0dee..476a01514 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -245,7 +245,8 @@ class APT_PUBLIC pkgCache /*{{{*/ // Useful transformation things static const char *Priority(unsigned char Priority); - + static std::string_view Priority_NoL10n(unsigned char Prio); + // Accessors GrpIterator FindGrp(APT::StringView Name); PkgIterator FindPkg(APT::StringView Name); @@ -278,6 +279,7 @@ class APT_PUBLIC pkgCache /*{{{*/ static const char *CompTypeDeb(unsigned char Comp) APT_PURE; static const char *CompType(unsigned char Comp) APT_PURE; static const char *DepType(unsigned char Dep); + static std::string_view DepType_NoL10n(unsigned char Dep); pkgCache(MMap *Map,bool DoMap = true); virtual ~pkgCache(); |
