From 6828ae2c2f9268c8187f0fa91b3c464ed84a8476 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 26 Dec 2024 20:43:34 +0000 Subject: Add pkgCache::{Priority,DepType}_NoL10n to avoid duplication We don't have many places, but lets reduce the amount of duplicating these short strings, so that we may find all the places we have to change if that ever happens. --- apt-pkg/pkgcache.cc | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'apt-pkg/pkgcache.cc') 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 #include +#include #include #include #include @@ -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 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 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 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 const Mapping{ + "", "required", "important", "standard", "optional", "extra" + }; + if (Prio < Mapping.size()) return Mapping[Prio]; - return 0; + return {}; } /*}}}*/ // GrpIterator::FindPkg - Locate a package by arch /*{{{*/ -- cgit v1.2.3-70-g09d2