summaryrefslogtreecommitdiff
path: root/apt-pkg/pkgcache.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2024-12-26 20:43:34 +0000
committerDavid Kalnischkies <david@kalnischkies.de>2025-01-05 22:16:08 +0000
commit6828ae2c2f9268c8187f0fa91b3c464ed84a8476 (patch)
treef873c20a03ce4e5885531666ee45d33126e7ca57 /apt-pkg/pkgcache.cc
parentf73593a4034d9eec0ec4466b8e173d4a4daece1f (diff)
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.
Diffstat (limited to 'apt-pkg/pkgcache.cc')
-rw-r--r--apt-pkg/pkgcache.cc37
1 files changed, 27 insertions, 10 deletions
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 /*{{{*/