1/** 2 * @file string_filter.cpp 3 * Filter strings based on 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 <algorithm> 13 14#include "string_filter.h" 15#include "string_manip.h" 16 17using namespace std; 18 19 20string_filter::string_filter(string const & include_patterns, 21 string const & exclude_patterns) 22 : include(separate_token(include_patterns, ',')), 23 exclude(separate_token(exclude_patterns, ',')) 24{ 25} 26 27 28string_filter::string_filter(vector<string> const & include_patterns, 29 vector<string> const & exclude_patterns) 30 : include(include_patterns), 31 exclude(exclude_patterns) 32{ 33} 34 35 36// FIXME: PP reference 37bool string_filter::match(string const & str) const 38{ 39 vector<string>::const_iterator cit; 40 cit = find(exclude.begin(), exclude.end(), str); 41 if (cit != exclude.end()) 42 return false; 43 44 cit = find(include.begin(), include.end(), str); 45 if (include.empty() || cit != include.end()) 46 return true; 47 48 return false; 49} 50