0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews//
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews// Automated Testing Framework (atf)
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews//
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews// Copyright (c) 2007 The NetBSD Foundation, Inc.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews// All rights reserved.
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews//
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// Redistribution and use in source and binary forms, with or without
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// modification, are permitted provided that the following conditions
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// are met:
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// 1. Redistributions of source code must retain the above copyright
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// notice, this list of conditions and the following disclaimer.
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// 2. Redistributions in binary form must reproduce the above copyright
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// notice, this list of conditions and the following disclaimer in the
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// documentation and/or other materials provided with the distribution.
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews//
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews//
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews#if !defined(TOOLS_EXPAND_HPP)
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews#define TOOLS_EXPAND_HPP
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews#include <string>
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews#include <vector>
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews
598b502695802c3d4e23316b85368e54f39f5cabMark Andrewsnamespace tools {
598b502695802c3d4e23316b85368e54f39f5cabMark Andrewsnamespace expand {
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// ------------------------------------------------------------------------
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// Free functions.
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews// ------------------------------------------------------------------------
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews//!
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews//! \brief Checks if the given string is a glob pattern.
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews//!
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews//! Returns true if the given string is a glob pattern; i.e. if it contains
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews//! any character that will be expanded by expand_glob.
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews//!
598b502695802c3d4e23316b85368e54f39f5cabMark Andrewsbool is_glob(const std::string&);
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews//!
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews//! \brief Checks if a given string matches a glob pattern.
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews//!
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews//! Given a glob pattern and a string, checks whether the former matches
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews//! the latter. Returns a boolean indicating this condition.
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews//!
bool matches_glob(const std::string&, const std::string&);
//!
//! \brief Expands a glob pattern among multiple candidates.
//!
//! Given a glob pattern and a set of candidate strings, checks which of
//! those strings match the glob pattern and returns them.
//!
template< class T >
std::vector< std::string > expand_glob(const std::string& glob,
const T& candidates)
{
std::vector< std::string > exps;
for (typename T::const_iterator iter = candidates.begin();
iter != candidates.end(); iter++)
if (matches_glob(glob, *iter))
exps.push_back(*iter);
return exps;
}
} // namespace expand
} // namespace tools
#endif // !defined(TOOLS_EXPAND_HPP)