diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2007-05-14 11:31:11 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2007-05-14 11:31:11 +0000 |
commit | 037b79a9cea1bcacb511986449a52578c40ef1bf (patch) | |
tree | 4ae670fc5b4f95c770d0c0ace0ec1f0e764b6494 | |
parent | 8131554814c6ddf6df3c93366f96d307a497458c (diff) |
for completion, allow Stem object to filter as well.
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Search.pm | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Search.pm b/usr.sbin/pkg_add/OpenBSD/Search.pm index 4f5a549a514..10060e2a21a 100644 --- a/usr.sbin/pkg_add/OpenBSD/Search.pm +++ b/usr.sbin/pkg_add/OpenBSD/Search.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Search.pm,v 1.2 2007/05/14 11:22:00 espie Exp $ +# $OpenBSD: Search.pm,v 1.3 2007/05/14 11:31:10 espie Exp $ # # Copyright (c) 2007 Marc Espie <espie@openbsd.org> # @@ -75,6 +75,25 @@ sub match return $o->stemlist->find($self->{stem}); } +sub _keep +{ + my ($self, $stem) = @_; + return $self->{stem} eq $stem; +} + +sub filter +{ + my ($self, @l) = @_; + my @result = (); + require OpenBSD::PackageName; + for my $pkg (@l) { + if ($self->_keep(OpenBSD::PackageName::splitstem($pkgname))) { + push(@result, $pkg); + } + } + return @result; +} + package OpenBSD::Search::PartialStem; our @ISA=(qw(OpenBSD::Search::Stem)); @@ -84,6 +103,13 @@ sub match return $o->stemlist->find_partial($self->{stem}); } +sub _keep +{ + my ($self, $stem) = @_; + my $partial = $self->{stem}; + return $stem =~ /\Q$partial\E/; +} + package OpenBSD::Search::Filter; our @ISA=(qw(OpenBSD::Search)); |