// returned java script function name, input string is truncating CString CWebPage::ScanJScript(CString& strAText, CStringArray& args) { args.RemoveAll(); CString strDelim(" \n\r\t"),strSrc(strAText); bool bFound = false; while(!strSrc.IsEmpty()) { CString strStart = GetNextToken(strSrc,strDelim); if(strStart == "function") { bFound = true; break; } if(strStart == "/*") { // Skip comments while(!strSrc.IsEmpty()) { CString strStop = GetNextToken(strSrc,strDelim); if(strStop == "*/") { break; } } } } if(!bFound){ return _T(""); } CString strFunc = GetNextToken(strSrc, _T("("),true); CString strArgs = GetNextToken(strSrc, _T(")"),true); // Parse arguments CString strArg; while(!(strArg = GetNextToken(strArgs, _T(","))).IsEmpty()) args.Add(strArg); strAText= strSrc; return strFunc; }
// 切割字符串 std::vector<CString> Split(LPCTSTR pszStrLine, LPCTSTR pszDelim) { std::vector<CString> vecReturn; CString strLine(pszStrLine), strDelim(pszDelim); int nPos = strLine.Find(strDelim); while (-1 != nPos) { if (nPos > 0) { vecReturn.push_back(strLine.Left(nPos)); } strLine.Delete(0, nPos + strDelim.GetLength()); nPos = strLine.Find(strDelim); } if (!strLine.IsEmpty()) { vecReturn.push_back(strLine); } return vecReturn; }