//////////////////////////////////
if( nChar==VK_ESCAPE ) CDialog::OnOK(); else if( nChar==VK_F5 ) //匹配查找 { UpdateData(); m_strResult = ""; match_results result; REGEX_FLAGS dw = GLOBAL | ALLBACKREFS; if( m_bCase ) dw |= NOCASE; if( m_bMulti ) dw |= MULTILINE; if( m_bSingle ) dw |= SINGLELINE; // double tmS = clock(); // rpattern pat((LPCTSTR)m_strReg, dw); int iGroups = pat.cgroups(); int nCount = 0; match_results::backref_type br = pat.match( (LPCTSTR)m_strSource, result ); if( 0 )//遍历结果方式1,任选一种方式即可 { match_results::backref_vector vec = result.all_backrefs(); match_results::backref_vector::iterator iter; if( br.matched ) { for( iter = vec.begin(); iter != vec.end(); iter++ ) { nCount++; string str = (*iter).str(); m_strResult += str.c_str(); m_strResult += "\r\n---------------------------------------------\r\n"; } } } if( 1 )//遍历结果方式2 { if( br.matched ) { for( int i=0;i<result.cbackrefs();i++ ) { if( i%iGroups == 0 ) { nCount++; m_strResult += result.backref(i).str().c_str(); m_strResult += "\r\n---------------------------------------------\r\n"; } } } } double tmE = clock(); CString strTip; strTip.Format(_T(" 运行时间 %.2fms, 共找到 %d个匹配;"), double(tmE-tmS), nCount); GetDlgItem(IDC_STATIC_TIP)->SetWindowText(strTip); // UpdateData(FALSE); } else if( nChar == VK_F6 )//替换 { UpdateData(); m_strResult = ""; // REGEX_FLAGS dw = GLOBAL | ALLBACKREFS; if( m_bCase ) dw |= NOCASE; if( m_bMulti ) dw |= MULTILINE; if( m_bSingle ) dw |= SINGLELINE; double tmS = clock(); // rpattern pat((LPCTSTR)m_strReg, (LPCTSTR)m_strSub, dw); subst_results subResult; // string str((LPCTSTR)m_strSource); int nCount = pat.substitute(str, subResult); m_strResult = str.c_str(); // double tmE = clock(); CString strTip; strTip.Format(_T(" 运行时间 %.2fms, 共完成替换 %d处;"), double(tmE-tmS), nCount); GetDlgItem(IDC_STATIC_TIP)->SetWindowText(strTip); // UpdateData(FALSE); } else if( nChar == VK_F7 )//分割字符串 { UpdateData(); m_strResult = ""; // REGEX_FLAGS dw = GLOBAL | ALLBACKREFS; if( m_bCase ) dw |= NOCASE; if( m_bMulti ) dw |= MULTILINE; if( m_bSingle ) dw |= SINGLELINE; double tmS = clock(); // rpattern pat((LPCTSTR)m_strReg, dw); split_results splitResult; // string str((LPCTSTR)m_strSource); int nCount = pat.split(str, splitResult); for( int ni=0;ni<nCount;ni++ ) { string strSplit = splitResult[ni]; m_strResult += strSplit.c_str(); m_strResult += "\r\n---------------------------------------------\r\n"; } // double tmE = clock(); CString strTip; strTip.Format(_T(" 运行时间 %.2fms, 共找到 %d个匹配;"), double(tmE-tmS), nCount); GetDlgItem(IDC_STATIC_TIP)->SetWindowText(strTip); // UpdateData(FALSE); }
/////----------结束-----------//////// |
该工程项目代码在这里下载,已经包含了greta2.6.4源码文件;
以上为初步测试结果,可能在使用和介绍中有错误和不当之初,欢迎大家多交流探讨。