// Copyright (C) 2010, Guy Barrand. All rights reserved. // See the file tools.license for terms. #ifndef tools_smatch #define tools_smatch #include "words" #include namespace tools { inline bool match(const std::string& a_string,const std::string& a_pattern,bool a_check_for_wilds = true){ std::string::size_type lpattern = a_pattern.length(); std::string::size_type lstring = a_string.length(); if ((lpattern==0)&&(lstring==0)) return true; if ((lpattern==0)&&(lstring!=0)) return true; if ((lpattern!=0)&&(lstring==0)) return false; if((lpattern==1)&&(a_pattern[0]=='*')) return true; if(a_check_for_wilds) { bool some_star = false; for(std::string::size_type count=0;count1024) return false; //throw std::string::size_type wps[1024]; //OPTIMIZATION : we gain a lot with that. unsigned int wn; std::string::size_type* wls = wps+lpattern; words(a_pattern,"*",false,wn,wps,wls); if(!wn) { //delete [] wps; return true; // only wildcards : } // tricky case : char* token = (char*)a_string.c_str(); {for(unsigned int count=0;count& a_v, const std::string& a_pattern, bool a_check_for_wilds = true){ std::vector::iterator it; for(it=a_v.begin();it!=a_v.end();) { if(match(*it,a_pattern,a_check_for_wilds)) { it++; } else { it = a_v.erase(it); } } } } #endif