2 * File: ExcludesListMatcher.cpp
4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 * See included license file for license details.
8 #include "ExcludesListMatcher.h"
10 using namespace elftosb;
12 ExcludesListMatcher::ExcludesListMatcher()
17 ExcludesListMatcher::~ExcludesListMatcher()
21 //! \param isInclude True if this pattern is an include, false if it is an exclude.
22 //! \param pattern String containing the glob pattern.
23 void ExcludesListMatcher::addPattern(bool isInclude, const std::string & pattern)
25 glob_list_item_t item;
26 item.m_isInclude = isInclude;
27 item.m_glob = pattern;
30 m_patterns.push_back(item);
33 //! If there are no entries in the match list, the match fails.
35 //! \param testValue The string to match against the pattern list.
36 //! \retval true The \a testValue argument matches.
37 //! \retval false No match was made against the argument.
38 bool ExcludesListMatcher::match(const std::string & testValue)
40 if (!m_patterns.size())
45 // Iterate over the match list. Includes act as an OR operator, while
46 // excludes act as an AND operator.
47 bool didMatch = false;
48 bool isFirstItem = true;
49 glob_list_t::iterator it = m_patterns.begin();
50 for (; it != m_patterns.end(); ++it)
52 glob_list_item_t & item = *it;
54 // if this pattern is an include and it doesn't match, or
55 // if this pattern is an exclude and it does match, then the match fails
56 bool didItemMatch = globMatch(testValue.c_str(), item.m_glob.c_str());
63 didMatch = didItemMatch;
67 didMatch = didMatch || didItemMatch;
75 didMatch = !didItemMatch;
79 didMatch = didMatch && !didItemMatch;