bool CStrUtil::IsValidNumericString(LPCTSTR source) { if ( source == NULL || lstrlen(source) == 0 ) return false; //// check if it's numeric # CAtlRegExp<> reNumeric; //// five match groups: scheme, authority, path, query, fragment REParseError status = reNumeric.Parse(_T("^[-+]?[0-9]*[.]?[0-9]+([eE][-+]?[0-9]+)?$")); if (REPARSE_ERROR_OK != status) { // // Unexpected error. // CAWDException* e = new CAWDException(CAWDException::EXCEPTION_STR2LONG, __AWDFILE__, __AWDLINE__); // throw e; ATLASSERT(FALSE); ATLTRACE(_T("failed to parse regex\n")); return false; } CAtlREMatchContext<> mcNumeric; if (!reNumeric.Match(source,&mcNumeric)) { // CAWDException* e = new CAWDException(CAWDException::EXCEPTION_STR2LONG, __AWDFILE__, __AWDLINE__); // throw e; return false; } return true; }
void CAddIPAddressRuleDlg::OnOK(void) { CString sIPAddress; m_cIPAddress.GetWindowText(sIPAddress); // this reg exp should allow entry of an IP address of up to 4 octets CAtlRegExp<> re; re.Parse(_T("{[0-2]?\\d?\\d}{\\.[0-2]?\\d?\\d}?{\\.[0-2]?\\d?\\d}?{\\.[0-2]?\\d?\\d}?")); CAtlREMatchContext<> mc; const TCHAR* pszStart = sIPAddress; const TCHAR* pszEnd = NULL; if (sIPAddress.GetLength() <= 0 || re.Match(sIPAddress, &mc, &pszEnd) == FALSE || ((int) (pszEnd - pszStart)) != sIPAddress.GetLength()) { CString sCaption; sCaption.LoadString(IDS_IISXPRESS_APPNAME); CString sError; sError.LoadString(IDS_ERROR_INCORRECTIPADDRESS); MessageBox(sError, sCaption, MB_OK | MB_ICONWARNING); m_cIPAddress.SetFocus(); return; } m_sNewIPAddress = sIPAddress; CHelpAwareDialogBase::OnOK(); }
bool CStrUtil::IsValidFilePath(LPCTSTR source) { if ( source == NULL || lstrlen(source) == 0 ) return false; //// check if it's numeric # CAtlRegExp<> reFilePath; //// five match groups: scheme, authority, path, query, fragment REParseError status = reFilePath.Parse(_T("^[a-zA-Z]:")); //\\(?:[^\\/:*?\"<>|\r\n]+\\)*[^\\/:*?\"<>|\r\n]*$ if (REPARSE_ERROR_OK != status) { // // Unexpected error. // CAWDException* e = new CAWDException(CAWDException::EXCEPTION_STR2LONG, __AWDFILE__, __AWDLINE__); // throw e; ATLASSERT(FALSE); ATLTRACE(_T("failed to parse regex\n")); return false; } CAtlREMatchContext<> mcNumeric; if (!reFilePath.Match(source,&mcNumeric)) { // CAWDException* e = new CAWDException(CAWDException::EXCEPTION_STR2LONG, __AWDFILE__, __AWDLINE__); // throw e; return false; } return true; }
// 正则匹配 //************************************ //使用方法: //RegexMatch("98a76", "[0-9][0-9]"); //前者为需要匹配的字串,后者为正则表达式 //************************************ BOOL CStringChecker::RegexMatch(const char* pStr, const char* pStrRegex) { CAtlRegExp<> re; CAtlREMatchContext<> mc; re.Parse(pStrRegex); return re.Match(pStr, &mc); }
CString CStandaloneTabItem::GetFilteredLogString(){ m_filteredLogStringList.RemoveAll(); POSITION headPosition = m_allLogStringList.GetHeadPosition(); CString keywordCopy = m_keyword; keywordCopy.MakeLower(); while (headPosition != NULL){ CString &s = m_allLogStringList.GetNext(headPosition); CString sCopy = s; sCopy.MakeLower(); if (m_useRegularExpression) { CAtlRegExp<CAtlRECharTraitsW> reRule; wchar_t *wt = (wchar_t *)(LPCTSTR)keywordCopy; REParseError status = reRule.Parse((const ATL::CAtlRegExp<CAtlRECharTraitsW>::RECHAR *)wt); if (REPARSE_ERROR_OK != status) { return _T(""); } CAtlREMatchContext<CAtlRECharTraitsW> mcRule; wt = (wchar_t *)(LPCTSTR)sCopy; if (reRule.Match((const ATL::CAtlRegExp<CAtlRECharTraitsW>::RECHAR *)wt, &mcRule)) { m_filteredLogStringList.AddTail(s); } else{ } } else{ if (sCopy.Find(keywordCopy) != -1){ cout << "found occurrence in " << s << endl; m_filteredLogStringList.AddTail(s); } else{ cout << "not found in " << s << endl; continue; } } } CString result; POSITION position = m_filteredLogStringList.GetHeadPosition(); while (position != NULL){ CString& s = m_filteredLogStringList.GetNext(position); result.Append(s); //result.Append(_T("\n")); } return result; }
void CGoToDlg::OnBnClickedOk2() { UpdateData(); int frame = 0; float fps = 0; CAtlRegExp<> re; REParseError status = re.Parse(_T("{\\z}[^0-9\\.]+{[0-9\\.]+}"), FALSE); if(REPARSE_ERROR_OK == status) { CAtlREMatchContext<> mc; const CAtlREMatchContext<>::RECHAR* s = m_framestr.GetBuffer(); const CAtlREMatchContext<>::RECHAR* e = NULL; if(re.Match(s, &mc, &e)) { const CAtlREMatchContext<>::RECHAR* szStart = 0; const CAtlREMatchContext<>::RECHAR* szEnd = 0; mc.GetMatch(0, &szStart, &szEnd); frame = _tcstol(szStart, (TCHAR**)&szStart, 10); mc.GetMatch(1, &szStart, &szEnd); if(_stscanf(szStart, _T("%f"), &fps) != 1) fps = 0; else AfxGetMyApp()->WriteProfileString(ResStr(IDS_R_SETTINGS), _T("fps"), szStart); } else { AfxMessageBox(_T("Error parsing entered text!")); return; } if(fps == 0) { AfxMessageBox(_T("Error parsing entered frame-rate!")); return; } m_time = (int)(1000.0*frame/fps) + 1; AfxGetMyApp()->WriteProfileInt(ResStr(IDS_R_SETTINGS), _T("gotoluf"), 1); OnOK(); } }
void CGoToDlg::OnBnClickedOk1() { UpdateData(); int hh, mm, ss, ms; hh = mm = ss = ms = 0; CAtlRegExp<> re; REParseError status = re.Parse(_T("{\\z}"), FALSE); if(REPARSE_ERROR_OK == status) { CAtlREMatchContext<> mc; const CAtlREMatchContext<>::RECHAR* s = m_timestr.GetBuffer(); const CAtlREMatchContext<>::RECHAR* e = NULL; while(s && re.Match(s, &mc, &e)) { const CAtlREMatchContext<>::RECHAR* szStart = 0; const CAtlREMatchContext<>::RECHAR* szEnd = 0; mc.GetMatch(0, &szStart, &szEnd); if(hh != 0 || hh > 59 || mm > 59 || ss > 59) { AfxMessageBox(_T("Error parsing entered time!")); return; } hh = mm; mm = ss; ss = ms; ms = _tcstol(szStart, (TCHAR**)&szStart, 10); s = e; } m_time = ((hh*60+mm)*60+ss)*1000+ms; AfxGetMyApp()->WriteProfileInt(ResStr(IDS_R_SETTINGS), _T("gotoluf"), 0); OnOK(); } }
BOOL SearchFirstPath( LPCTSTR pszCmdLine, LPCTSTR* ppszStart, LPCTSTR* ppszEnd ) { BOOL bRet = FALSE; try { LPCTSTR pszFilePathReg = TEXT( "([a-zA-Z]:(\\\\[^\\\\/:*?\"<>|]+)+)" ); CAtlRegExp<> re; REParseError status = re.Parse( pszFilePathReg ); if( REPARSE_ERROR_OK != status ) throw 0; CAtlREMatchContext<> mc; if( !re.Match( pszCmdLine, &mc ) ) throw 0; ptrdiff_t nLength = mc.m_Match.szEnd - mc.m_Match.szStart; if( nLength <= 0 ) throw 0; *ppszStart = mc.m_Match.szStart; *ppszEnd = mc.m_Match.szEnd; bRet = TRUE; } catch( int ) { bRet = FALSE; } return bRet; }
void CRemoteGraphForm::OnRefreshClick() { // let's load objects from ROT CComPtr<IRunningObjectTable> rot; HRESULT hr; graphs.RemoveAll(); list_graphs.DeleteAllItems(); sel_graph = RemoteGraph(); hr = GetRunningObjectTable(0, &rot); if (FAILED(hr)) return ; // scan through running objects CComPtr<IEnumMoniker> emon; CComPtr<IMoniker> moniker; CComPtr<IBindCtx> bindctx; ULONG f; hr = CreateBindCtx(0, &bindctx); if (FAILED(hr)) { return ; } CAtlRegExp<> regex; REParseError status = regex.Parse(_T("^\\!FilterGraph {[0-9A-F]+} pid {[0-9A-F]+}(; process\\: {.+?}, time\\: {[0-9]+\\-[0-9]+\\-[0-9]+})?"), FALSE); rot->EnumRunning(&emon); emon->Reset(); while (emon->Next(1, &moniker, &f) == NOERROR) { // is this a graph object ? LPOLESTR displayname; moniker->GetDisplayName(bindctx, NULL, &displayname); CString name(displayname); if (name.Find(_T("!FilterGraph")) == 0 && !GraphStudio::DisplayGraph::IsOwnRotGraph(name)) { RemoteGraph gr = {0}; CAtlREMatchContext<> mc; gr.name = name; gr.moniker = moniker; gr.pid = 0; gr.instance = 0; gr.processIsWOW64 = FALSE; if (regex.Match(name, &mc)) { const CAtlREMatchContext<>::RECHAR* szStart = 0; const CAtlREMatchContext<>::RECHAR* szEnd = 0; mc.GetMatch(0, &szStart, &szEnd); int nLength = (int) (szEnd - szStart); const CString textInstance(szStart, nLength); StrToInt64ExW(CStringW(L"0x") + textInstance, STIF_SUPPORT_HEX, &reinterpret_cast<LONGLONG&>(gr.instance)); mc.GetMatch(1, &szStart, &szEnd); nLength = (int) (szEnd - szStart); const CString textPID(szStart, nLength); CString nameSuffix(szEnd ? szEnd : _T("")); nameSuffix.Trim(); if (StrToIntExW(CStringW(L"0x") + textPID, STIF_SUPPORT_HEX, &reinterpret_cast<INT&>(gr.pid))) { CHandle process; process.Attach(OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, gr.pid)); if (process) { TCHAR pszPath[MAX_PATH] = { 0 }; if (GetModuleFileNameEx(process, NULL, pszPath, sizeof(pszPath))) { gr.processImagePath = pszPath; // Extract filename int fileNamePos = gr.processImagePath.FindFileName(); if (fileNamePos >= 0) gr.processImageFileName = CString(gr.processImagePath).Mid(fileNamePos); } else { // a 32Bit process can't list the modules of a 64Bit process, so try to get the processImageFileName from the ROT-Name (works only for FilterGraphSpy-Entries) mc.GetMatch(2, &szStart, &szEnd); nLength = (int) (szEnd - szStart); if (nLength > 0) { CString textFileName(szStart, nLength); gr.processImageFileName = textFileName; } else if (nameSuffix.GetLength() > 0) { gr.processImageFileName = nameSuffix; // as a last resort add any suffix information from the ROT name rather than leaving blank #ifndef _WIN64 gr.processImageFileName += _T(" *64"); // If we're 32bit, assume that we can't get process name because remote process is 64bit and show this on the dialog #endif } } IsWow64Process(process, &gr.processIsWOW64); } } mc.GetMatch(3, &szStart, &szEnd); nLength = (int) (szEnd - szStart); if (nLength > 0) { CString textTime(szStart, nLength); textTime.Replace(_T("-"), _T(":")); gr.time = textTime; } } graphs.Add(gr); CString entryName = gr.name; if (gr.pid > 0) entryName.Format(_T("%d (0x%08lX)"), gr.pid, gr.pid); int nIndex = list_graphs.InsertItem(list_graphs.GetItemCount(), entryName); if (gr.processIsWOW64) { CString val = gr.processImageFileName; val.Append(_T(" *32")); list_graphs.SetItemText(nIndex, 1, val); } else list_graphs.SetItemText(nIndex, 1, gr.processImageFileName); if (gr.instance > 0) { CString val; val.Format(_T("0x%I64d"), gr.instance); list_graphs.SetItemText(nIndex, 2, val); } list_graphs.SetItemText(nIndex, 3, gr.time); list_graphs.SetItemText(nIndex, 4, gr.processImagePath); if (graphs.GetCount() == 1) { list_graphs.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED); list_graphs.SetSelectionMark(0); } } if (displayname) { CComPtr<IMalloc> alloc; if (SUCCEEDED(CoGetMalloc(0, &alloc))) { alloc->Free(displayname); } } moniker = NULL; } // Set column width automatically to fit contents refreshed above for (int n=0; n<=4; n++) { list_graphs.SetColumnWidth(n, LVSCW_AUTOSIZE_USEHEADER); } }
void CProjectInfoWriteDlg::OnBnClickedButtonSenddata() { // TODO: 在此添加控件通知处理程序代码 //更新成员内容 UpdateData(TRUE); //检查项目名称 if(m_ProjectName.IsEmpty()) { MessageBox(L"项目名称不能为空!",L"项目发送",MB_ICONWARNING); return; } //检查邮箱地址 if(m_MailAddr.IsEmpty()) { MessageBox(L"请填写一个邮箱地址!",L"项目发送",MB_ICONWARNING); return; } //检查邮箱格式 CString strRegex=L"({[a-zA-Z0-9_]+@[a-zA-Z0-9]+[.][a-zA-Z0-9]+[.]?[a-zA-Z0-9]+})"; CAtlRegExp<CAtlRECharTraitsW> reRule; wchar_t *wt = (wchar_t *)(LPCTSTR)strRegex; REParseError status = reRule.Parse((const ATL::CAtlRegExp<CAtlRECharTraitsW>::RECHAR *)wt); if (REPARSE_ERROR_OK != status) { AfxMessageBox(L"输入的邮件地址不合法!"); return; } CAtlREMatchContext<CAtlRECharTraitsW> mcRule; wt = (wchar_t *)(LPCTSTR)m_MailAddr; if (!reRule.Match((const ATL::CAtlRegExp<CAtlRECharTraitsW>::RECHAR *)wt,&mcRule)) { AfxMessageBox(L"输入的邮件地址不合法!"); return; } else { for (UINT nGroupIndex = 0; nGroupIndex < mcRule.m_uNumGroups; ++nGroupIndex) { const CAtlREMatchContext<>::RECHAR* szStart = 0; const CAtlREMatchContext<>::RECHAR* szEnd = 0; mcRule.GetMatch(nGroupIndex, &szStart, &szEnd); ptrdiff_t nLength = szEnd - szStart; CString strEmailAddress(szStart, static_cast<int>(nLength)); if(strEmailAddress.Compare(m_MailAddr)!=0) { CString strPrompt; strPrompt.Format(L"输入的邮件地址不合法,您要输入%s 吗!",strEmailAddress); AfxMessageBox(strPrompt); return; } } } //检查发送人姓名 if(m_SenderName.IsEmpty()) { MessageBox(L"请如实填写发送人姓名!",L"项目发送",MB_ICONWARNING); return; } if(m_AnaType.IsEmpty()) { MessageBox(L"请选择一个溯源模式!",L"项目发送",MB_ICONWARNING); return; } CDialogEx::OnOK(); }
void aux_sscanf(CAstSig &ast, const AstNode *pnode, const AstNode *p) { const char *fnsigs[] = { "(string, format_string)", 0}; checkNumArgs(pnode, p, fnsigs, 2, 0); string srcstring = ast.ComputeString(p); p = p->next; string fmtstring = ast.ComputeString(p); processEscapes(fmtstring); const char *fmtstr = fmtstring.c_str(); const char *srcstr = srcstring.c_str(); CAtlRegExp<> regexp; REParseError status = regexp.Parse("{%}([-+ #0]+)?({\\*})?({\\z})?[hlL]?{[cuoxXideEgGfs]}" ); if (REPARSE_ERROR_OK != status) throw "Internal error! RegExp.Parse( ) failed."; CAtlREMatchContext<> mcFormat; char fmttype; const char *fmtspec; // pointer to '%', for the error message. int CharWidth, fmtcnt = 0; for (const char *next; fmtstr && regexp.Match(fmtstr, &mcFormat, &next); fmtstr=next) { const CAtlREMatchContext<>::RECHAR* szStart = 0; const CAtlREMatchContext<>::RECHAR* szEnd = 0; bool fIgnore = false; for (UINT nGroupIndex = 0; nGroupIndex < mcFormat.m_uNumGroups; ++nGroupIndex) { mcFormat.GetMatch(nGroupIndex, &szStart, &szEnd); switch (nGroupIndex) { case 3: // type specifier if (++fmtcnt > 1) throw "Only one value can be read and returned."; fmttype = *szStart; break; case 2: // width specifier CharWidth = -1; if (szStart && sscanf(szStart, "%d", &CharWidth) != 1) throw "Invalid width."; break; case 1: // starting asterisk : read and ignore (don't store) if (szStart) fIgnore = true; break; case 0: // '%' fmtspec = szStart; break; } if (fIgnore) break; } if (fIgnore) continue; } int res, iv; unsigned uv; float fv; vector<char> vbuf; switch (fmttype) { case 'e': case 'E': case 'g': case 'G': case 'f': if ((res = sscanf(srcstr, fmtstring.c_str(), &fv)) == 1) ast.Sig.SetValue(fv); break; case 'd': case 'o': case 'x': case 'X': case 'i': if ((res = sscanf(srcstr, fmtstring.c_str(), &iv)) == 1) ast.Sig.SetValue(iv); break; case 'u': if ((res = sscanf(srcstr, fmtstring.c_str(), &uv)) == 1) ast.Sig.SetValue(uv); break; case 's': case 'c': if (CharWidth == -1) CharWidth = fmttype=='s'?(int)srcstring.size():1; vbuf.resize(CharWidth+1); if ((res = sscanf(srcstr, fmtstring.c_str(), &vbuf[0])) == 1) { ast.Sig.UpdateBuffer((int)strlen(&vbuf[0])); for (int i=0; vbuf[i]; ++i) ast.Sig.buf[i] = vbuf[i]; } } if (res != 1) throw CAstException(pnode, "sscanf failed at", fmtspec); return; }
void aux_fprintf(CAstSig &ast, const AstNode *pnode, const AstNode *p) { const char *fnsigs[] = { "(filename, format_string, ...)", 0}; checkNumArgs(pnode, p, fnsigs, 2, 0); CAtlRegExp<> regexp; REParseError status = regexp.Parse("%([-+ #0]+)?({\\z|\\*})?(\\.{\\z|\\*})?[hlL]?{[cuoxXideEgGfs]}" ); if (REPARSE_ERROR_OK != status) throw "Internal error! RegExp.Parse( ) failed."; string filename = ast.MakeFilename(ast.ComputeString(p), "txt"); FILE *file; if (!(file = fopen(filename.c_str(), "a"))) throw CAstException(pnode, "Cannot open file", filename); try { // need this to close the file on exception CAtlREMatchContext<> mcFormat; p = p->next; string fmtstring = ast.ComputeString(p); processEscapes(fmtstring); const char *fmtstr = fmtstring.c_str(); for (const char *next; fmtstr && regexp.Match(fmtstr, &mcFormat, &next); fmtstr=next) { const CAtlREMatchContext<>::RECHAR* szStart = 0; const CAtlREMatchContext<>::RECHAR* szEnd = 0; string vstring; double v; string fmt1string(fmtstr, mcFormat.m_Match.szEnd-fmtstr); for (UINT nGroupIndex = 0; nGroupIndex < mcFormat.m_uNumGroups; ++nGroupIndex) { mcFormat.GetMatch(nGroupIndex, &szStart, &szEnd); if (nGroupIndex == 2 || (nGroupIndex < 2 && szStart && *szStart == '*')) { // condition for consuming an argument if ((p = p->next) == NULL) throw CAstException(pnode, pnode, fnsigs, "Not enough arguments."); if (nGroupIndex == 2 && *szStart == 's') vstring = ast.ComputeString(p); else if (ast.Compute(p).IsScalar()) v = ast.Sig.value(); else throw CAstException(pnode, p, fnsigs, "Scalar value expected for this argument."); if (nGroupIndex != 2) { char width[20]; sprintf(width, "%d", round(v)); fmt1string.replace(szStart-fmtstr, 1, width); } } } switch (*szStart) { case 'e': case 'E': case 'g': case 'G': case 'f': fprintf(file, fmt1string.c_str(), v); break; case 'c': case 'o': case 'x': case 'X': case 'i': case 'u': case 'd': fprintf(file, fmt1string.c_str(), round(v)); break; case 's': fprintf(file, fmt1string.c_str(), vstring.c_str()); break; } } fprintf(file, fmtstr); fclose(file); } catch (const char *) { fclose(file); throw; } catch (const CAstException &) { fclose(file); throw; } }
void aux_sprintf(CAstSig &ast, const AstNode *pnode, const AstNode *p) { const char *fnsigs[] = { "(format_string, ...)", 0}; checkNumArgs(pnode, p, fnsigs, 1, 0); CAtlRegExp<> regexp; REParseError status = regexp.Parse("%([-+ #0]+)?({\\z|\\*})?(\\.{\\z|\\*})?[hlL]?{[cuoxXideEgGfs]}" ); if (REPARSE_ERROR_OK != status) throw "Internal error! RegExp.Parse( ) failed."; ast.Sig.Reset(2); // to get the output string CAstSig tast(&ast); // to preserve this->Sig CAtlREMatchContext<> mcFormat; string fmtstring = tast.ComputeString(p); processEscapes(fmtstring); const char *fmtstr = fmtstring.c_str(); for (const char *next; fmtstr && regexp.Match(fmtstr, &mcFormat, &next); fmtstr=next) { const CAtlREMatchContext<>::RECHAR* szStart = 0; const CAtlREMatchContext<>::RECHAR* szEnd = 0; string vstring; double v; string fmt1str(fmtstr, mcFormat.m_Match.szEnd-fmtstr); vector<char> outStr; outStr.resize(100); for (UINT nGroupIndex = 0; nGroupIndex < mcFormat.m_uNumGroups; ++nGroupIndex) { mcFormat.GetMatch(nGroupIndex, &szStart, &szEnd); if (nGroupIndex == 2 || (nGroupIndex < 2 && szStart && *szStart == '*')) { // condition for consuming an argument if ((p = p->next) == NULL) throw CAstException(pnode, pnode, fnsigs, "Not enough arguments."); if (nGroupIndex == 2 && *szStart == 's') vstring = tast.ComputeString(p); else if (tast.Compute(p).IsScalar()) v = tast.Sig.value(); else throw CAstException(pnode, p, fnsigs, "Scalar value expected for this argument."); if (nGroupIndex != 2) { char width[20]; sprintf(width, "%d", round(v)); fmt1str.replace(szStart-fmtstr, 1, width); } } } switch (*szStart) { case 'e': case 'E': case 'g': case 'G': case 'f': sprintf(&outStr[0], fmt1str.c_str(), v); break; case 'c': case 'o': case 'x': case 'X': case 'i': case 'u': case 'd': sprintf(&outStr[0], fmt1str.c_str(), round(v)); break; case 's': outStr.resize(vstring.size()+100); sprintf(&outStr[0], fmt1str.c_str(), vstring.c_str()); break; } int n = ast.Sig.nSamples; ast.Sig.UpdateBuffer(n + (int)strlen(&outStr[0])); for (int j=0; outStr[j]; j++) ast.Sig.buf[n+j] = outStr[j]; } int n = ast.Sig.nSamples; ast.Sig.UpdateBuffer(n + (int)strlen(fmtstr)); for (int j=0; fmtstr[j]; j++) ast.Sig.buf[n+j] = fmtstr[j]; }
//用正则表达式来转换 int CWebBase::HtmlCodeToUniCodeByteReg( char * pszHtmlcode, int iLen ) { int i; char * pcTemp = NULL; char * pcWord = NULL; REParseError status; CAtlRegExp<> reurl; CAtlREMatchContext<> mcurl; const CAtlREMatchContext<>::RECHAR * szStart = 0; const CAtlREMatchContext<>::RECHAR * szEnd = 0; unsigned short usData; char cbuffGbt[8] = {0}; char cBuffGbs[8] = {0}; pcTemp = strstr( pszHtmlcode, "&#") ; if( pcTemp == NULL ) { return iLen; } status = reurl.Parse( "&#{.*?};"); if( REPARSE_ERROR_OK != status) { return iLen; } for ( i = 0; i < 4000; i++ ) { if (!reurl.Match( pcTemp , &mcurl ) ) { break; } if( mcurl.m_uNumGroups <= 0 ) { break; } szStart = NULL; szEnd = NULL; mcurl.GetMatch( 0, &szStart, &szEnd ); pcTemp = (char*)szStart; if( pcTemp == NULL || szStart == NULL ) { break; } pcWord = pcTemp; //nLength = szEnd - szStart; usData = (unsigned short)atoi(pcWord); //转换Unicode码到Gb码繁体,使用API函数WideCharToMultiByte WideCharToMultiByte ( 936, 0, (PWSTR)&usData, -1, cbuffGbt,2, NULL, NULL) ; //转换Gb码繁体到Gb码简体,使用API函数LCMapString LCMapString( 0x0804,LCMAP_SIMPLIFIED_CHINESE, cbuffGbt, -1, cBuffGbs , 2); memcpy( pcWord, cBuffGbs, 2); memset( pcWord + 2, '^' , 3 ); } return iLen; }