12 inline bool match(
const std::string& a_string,
const std::string& a_pattern,
bool a_check_for_wilds =
true){
13 std::string::size_type lpattern = a_pattern.length();
14 std::string::size_type lstring = a_string.length();
15 if ((lpattern==0)&&(lstring==0))
return true;
16 if ((lpattern==0)&&(lstring!=0))
return true;
17 if ((lpattern!=0)&&(lstring==0))
return false;
19 if((lpattern==1)&&(a_pattern[0]==
'*'))
return true;
21 if(a_check_for_wilds) {
22 bool some_star =
false;
23 for(std::string::size_type count=0;count<lpattern;count++) {
24 if(a_pattern[count]==
'*') {some_star =
true;
break;}
27 return (a_pattern==a_string ?
true :
false );
33 if((2*lpattern)>1024)
return false;
34 std::string::size_type
wps[1024];
37 std::string::size_type* wls =
wps+lpattern;
38 words(a_pattern,
"*",
false,wn,
wps,wls);
45 char* token = (
char*)a_string.c_str();
46 {
for(
unsigned int count=0;count<wn;count++) {
47 size_t lword = wls[count];
50 char* ws_pos = (
char*)(a_pattern.c_str()+
wps[count]);
52 if(a_pattern[0]!=
'*') {
54 if(::strncmp(token,ws_pos,lword)) {
58 token = token + lword;
62 char old_char = *(ws_pos+lword);
64 char* pos = ::strstr(token,ws_pos);
65 *(ws_pos+lword) = old_char;
70 if((count==(wn-1)) && (a_pattern[lpattern-1]!=
'*') ) {
72 if(::strncmp(a_string.c_str()+lstring-lword,ws_pos,lword)) {
87 inline bool match2(
const std::string& a_string,
const std::string& a_pattern){
88 return match(a_string,a_pattern,
true);
91 inline void filter(std::vector<std::string>& a_v,
92 const std::string& a_pattern,
93 bool a_check_for_wilds =
true){
94 std::vector<std::string>::iterator it;
95 for(it=a_v.begin();it!=a_v.end();) {
96 if(
match(*it,a_pattern,a_check_for_wilds)) {