#include "stdafx.h"

#include "NameMatcher.hpp"

#include "Utility.hpp"

CNameMatcher::CNameMatcher(const tstring& pattern)
{
	// セミコロン区切りで分割する。
	LPCTSTR p = pattern.c_str();
	LPCTSTR pSt = p;
	while (*p) {
		while (*p && *p != ';') {
			p = CharNext(p);
		}
		size_t len = p - pSt;
		if (len > 0) {
			tstring ptn(pSt, len);
			patterns_.push_back(ptn);
			p = CharNext(p);
			pSt = p;
		}
	}
}


bool CNameMatcher::operator()(const tstring& name) const throw()
{
	for (std::list<tstring>::const_iterator ite = patterns_.begin();
		ite != patterns_.end();
		++ite) {
		const tstring& ptn = *ite;
		if (IsMatch(name.c_str(), ptn.c_str())) {
			return true;
		}
	}
	return false;
}


