Upstream | cc2ee17 | 1970-01-12 13:46:40 +0000 | [diff] [blame^] | 1 | /** |
| 2 | * @file glob_filter.cpp |
| 3 | * Filter strings based on globbed exclude/include list |
| 4 | * |
| 5 | * @remark Copyright 2002 OProfile authors |
| 6 | * @remark Read the file COPYING |
| 7 | * |
| 8 | * @author Philippe Elie |
| 9 | * @author John Levon |
| 10 | */ |
| 11 | |
| 12 | #include <fnmatch.h> |
| 13 | |
| 14 | #include <algorithm> |
| 15 | |
| 16 | #include "glob_filter.h" |
| 17 | #include "string_manip.h" |
| 18 | |
| 19 | using namespace std; |
| 20 | |
| 21 | bool glob_filter::fnmatcher::operator()(string const & s) |
| 22 | { |
| 23 | return fnmatch(s.c_str(), str_.c_str(), 0) != FNM_NOMATCH; |
| 24 | } |
| 25 | |
| 26 | |
| 27 | bool glob_filter::match(string const & str) const |
| 28 | { |
| 29 | vector<string>::const_iterator cit; |
| 30 | cit = find_if(exclude.begin(), exclude.end(), fnmatcher(str)); |
| 31 | if (cit != exclude.end()) |
| 32 | return false; |
| 33 | |
| 34 | cit = find_if(include.begin(), include.end(), fnmatcher(str)); |
| 35 | if (include.empty() || cit != include.end()) |
| 36 | return true; |
| 37 | |
| 38 | return false; |
| 39 | } |