/* */function: * 字符串匹配算法,包含通配符"*"、"?"的匹配 * */params * 1.srtT: 目标字符串 * 2.strP: 待匹配字符串 * */return * strP匹配strT,返回true; 否则返回false.*/ bool IsStringMatch(const string& strT, const string& strP, int start = 0, int end = 0) { size_t i = 0; size_t j =0; size_t n = strT.size(); size_t m = strP.size(); bool bStart = true; while(i < n && j < m) { if(strP.at(j) == '*') // wildcard ,then find the first position matched with next character { if ( j>= m-1) { return true; } ++j; while('*' == strP.at(j)) // "***..*" <=> "*" { ++j; } while(strT.at(i) != strP.at(j)) { if(i >= n-1) // finished, no matter matched or not { break; } ++i; } } if(strT.at(i) == strP.at(j) || '?' == strP.at(j)) { if(bStart) // new loop start { start = i; bStart = false; } ++i; ++j; if(j == m) // match finish end = i-1; } else // unmatched ,then backtrace(start a new loop) { static size_t ipp = 0; ++ipp; i = ipp; j = 0; bStart = true; } } if(j >= m) // succeeded to find the pattern { if( '*' == strP[0]) // postfix start = 0; if( '*' == strP[m-1]) // prefix end = n-1; return true; } else return false; }