From cc6370366dfab801233d7aa99f7b1900125185c6 Mon Sep 17 00:00:00 2001 From: Daniel Hartwig Date: Fri, 8 Jun 2012 17:12:32 +0800 Subject: Regex strings count as search patterns Apt-utils treat regex strings as a search pattern, we should too. --- NEWS | 10 ++++++++++ src/generic/apt/matching/pattern.cc | 4 +++- src/generic/apt/matching/pattern.h | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 2bb1bc62..5aab4b38 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,16 @@ [6/8/2012] Version 0.6.9 "All in a days work" +- New features: + + * [cmdline]: Regular expressions are now supported to match names + (same as apt-utils): + + $ aptitude show ^tf$ + + Previously this would result in a "no such package" + error. + - Internal changes: * Unified the way packages are selected from command line diff --git a/src/generic/apt/matching/pattern.cc b/src/generic/apt/matching/pattern.cc index 5743a2a7..75339e1d 100644 --- a/src/generic/apt/matching/pattern.cc +++ b/src/generic/apt/matching/pattern.cc @@ -79,7 +79,9 @@ namespace aptitude bool is_pattern(const std::string &s) { - return s.find_first_of("~?") != s.npos; + // regex characters are ".?+*|[^$" + // pattern characters are "~?" + return s.find_first_of("~?.?+*|[^$") != s.npos; } } } diff --git a/src/generic/apt/matching/pattern.h b/src/generic/apt/matching/pattern.h index 5aad42f8..96d48550 100644 --- a/src/generic/apt/matching/pattern.h +++ b/src/generic/apt/matching/pattern.h @@ -2021,8 +2021,8 @@ namespace aptitude * This is used in situations where it would be counterintuitive * for all strings to be treated as search patterns, but where we * want search patterns to be available. Strings are considered - * to be seach patterns if they contain a tilde (~) or a question - * mark (?). + * to be seach patterns if they contain a tilde (~), a question + * mark (?), or any regex characters (.?+*|[^$). * * \return \b true if the string qualifies as a search pattern. */ -- cgit v1.2.3