summaryrefslogtreecommitdiff
path: root/apt-pkg/cachefilter-patterns.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2025-01-13 20:12:45 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2025-02-14 19:45:12 +0100
commit973d506288c8868a086a7fd62603773701abf4f4 (patch)
tree885194d46caaf5ba4b5f2545f4972202dcabcdb0 /apt-pkg/cachefilter-patterns.cc
parenta356af349cc04b649bc4635c26ff81e3d7c7ade5 (diff)
BaseRegexMatcher: Use std::optional [ABI]
Diffstat (limited to 'apt-pkg/cachefilter-patterns.cc')
-rw-r--r--apt-pkg/cachefilter-patterns.cc19
1 files changed, 9 insertions, 10 deletions
diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc
index 31eb05016..838c71a81 100644
--- a/apt-pkg/cachefilter-patterns.cc
+++ b/apt-pkg/cachefilter-patterns.cc
@@ -559,30 +559,29 @@ namespace Patterns
BaseRegexMatcher::BaseRegexMatcher(std::string const &Pattern)
{
- pattern = new regex_t;
- int const Res = regcomp(pattern, Pattern.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB);
+ pattern.emplace();
+ int const Res = regcomp(&*pattern, Pattern.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB);
if (Res == 0)
return;
- delete pattern;
- pattern = NULL;
char Error[300];
- regerror(Res, pattern, Error, sizeof(Error));
+ regerror(Res, &*pattern, Error, sizeof(Error));
_error->Error(_("Regex compilation error - %s"), Error);
+
+ pattern.reset();
}
bool BaseRegexMatcher::operator()(const char *string)
{
- if (unlikely(pattern == nullptr) || string == nullptr)
+ if (unlikely(pattern == std::nullopt) || string == nullptr)
return false;
else
- return regexec(pattern, string, 0, 0, 0) == 0;
+ return regexec(&*pattern, string, 0, 0, 0) == 0;
}
BaseRegexMatcher::~BaseRegexMatcher()
{
- if (pattern == NULL)
+ if (pattern == std::nullopt)
return;
- regfree(pattern);
- delete pattern;
+ regfree(&*pattern);
}
} // namespace Patterns