From 973d506288c8868a086a7fd62603773701abf4f4 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 13 Jan 2025 20:12:45 +0100 Subject: BaseRegexMatcher: Use std::optional [ABI] --- apt-pkg/cachefilter-patterns.cc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'apt-pkg/cachefilter-patterns.cc') 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 -- cgit v1.2.3-70-g09d2