void CScraperParser::ConvertJSON(CStdString &string) { CRegExp reg; reg.RegComp("\\\\u([0-f]{4})"); while (reg.RegFind(string.c_str()) > -1) { int pos = reg.GetSubStart(1); std::string szReplace(reg.GetMatch(1)); CStdString replace = StringUtils::Format("&#x%s;", szReplace.c_str()); string.replace(string.begin()+pos-2, string.begin()+pos+4, replace); } CRegExp reg2; reg2.RegComp("\\\\x([0-9]{2})([^\\\\]+;)"); while (reg2.RegFind(string.c_str()) > -1) { int pos1 = reg2.GetSubStart(1); int pos2 = reg2.GetSubStart(2); std::string szHexValue(reg2.GetMatch(1)); CStdString replace = StringUtils::Format("%c", strtol(szHexValue.c_str(), NULL, 16)); string.replace(string.begin()+pos1-2, string.begin()+pos2+reg2.GetSubLength(2), replace); } StringUtils::Replace(string, "\\\"","\""); }
void PathReadWriter::GetPathList(const CStdString& sPathList, std::vector<CStdString>& pathList) { pathList.clear(); pathList.reserve(std::count(sPathList.begin(), sPathList.end(), _T(';')) + 1); int nStartPos = 0; for (int nEndPos = (int) sPathList.find(_T(';')); nEndPos >= 0; nEndPos = (int) sPathList.find(_T(';'), nStartPos = nEndPos + 1)) { CStdString sSubPath = sPathList.Mid(nStartPos, nEndPos - nStartPos).Trim(); if (!sSubPath.IsEmpty()) { ::PathRemoveBackslash(sSubPath.GetBuffer(MAX_PATH)); sSubPath.ReleaseBuffer(); pathList.push_back(sSubPath); } } CStdString sSubPath = sPathList.Mid(nStartPos).Trim(); if (!sSubPath.IsEmpty()) { ::PathRemoveBackslash(sSubPath.GetBuffer(MAX_PATH)); sSubPath.ReleaseBuffer(); pathList.push_back(sSubPath); } }
std::vector<CStdString> split(const CStdString& s, const CStdString& delim, const bool keep_empty) { std::vector<CStdString> result; if (delim.empty()) { result.push_back(s); return result; } CStdString::const_iterator substart = s.begin(), subend; while (true) { subend = search(substart, s.end(), delim.begin(), delim.end()); CStdString temp(substart, subend); if (keep_empty || !temp.empty()) { result.push_back(temp); } if (subend == s.end()) { break; } substart = subend + delim.size(); } return result; }
void CScraperParser::ReplaceBuffers(CStdString& strDest) { // insert buffers int iIndex; for (int i=MAX_SCRAPER_BUFFERS-1; i>=0; i--) { CStdString temp; iIndex = 0; temp.Format("$$%i",i+1); while ((size_t)(iIndex = strDest.find(temp,iIndex)) != CStdString::npos) // COPIED FROM CStdString WITH THE ADDITION OF $ ESCAPING { strDest.replace(strDest.begin()+iIndex,strDest.begin()+iIndex+temp.GetLength(),m_param[i]); iIndex += m_param[i].length(); } } // insert settings iIndex = 0; while ((size_t)(iIndex = strDest.find("$INFO[",iIndex)) != CStdString::npos) { int iEnd = strDest.Find("]",iIndex); CStdString strInfo = strDest.Mid(iIndex+6,iEnd-iIndex-6); CStdString strReplace; if (m_scraper) strReplace = m_scraper->GetSetting(strInfo); strDest.replace(strDest.begin()+iIndex,strDest.begin()+iEnd+1,strReplace); iIndex += strReplace.length(); } iIndex = 0; while ((size_t)(iIndex = strDest.find("\\n",iIndex)) != CStdString::npos) strDest.replace(strDest.begin()+iIndex,strDest.begin()+iIndex+2,"\n"); }
CStdString DocProvHelper::ReplaceInvalidFileNameChars(CStdString sString) const { while (true) { /* TXTEX_IGNORE */ int iPos = sString.FindOneOf(_T(":*?\"&<>|")); if (iPos==-1) break; sString.erase(sString.begin()+iPos); } return sString; }
void CScraperParser::ReplaceBuffers(CStdString& strDest) { // insert buffers size_t iIndex; for (int i=MAX_SCRAPER_BUFFERS-1; i>=0; i--) { iIndex = 0; CStdString temp = StringUtils::Format("$$%i",i+1); while ((iIndex = strDest.find(temp,iIndex)) != CStdString::npos) // COPIED FROM CStdString WITH THE ADDITION OF $ ESCAPING { strDest.replace(strDest.begin()+iIndex,strDest.begin()+iIndex+temp.size(),m_param[i]); iIndex += m_param[i].length(); } } // insert settings iIndex = 0; while ((iIndex = strDest.find("$INFO[", iIndex)) != CStdString::npos) { size_t iEnd = strDest.find("]", iIndex); CStdString strInfo = strDest.substr(iIndex+6, iEnd - iIndex - 6); CStdString strReplace; if (m_scraper) strReplace = m_scraper->GetSetting(strInfo); strDest.replace(strDest.begin()+iIndex,strDest.begin()+iEnd+1,strReplace); iIndex += strReplace.length(); } // insert localize strings iIndex = 0; while ((iIndex = strDest.find("$LOCALIZE[", iIndex)) != CStdString::npos) { size_t iEnd = strDest.find("]", iIndex); CStdString strInfo = strDest.substr(iIndex+10, iEnd - iIndex - 10); CStdString strReplace; if (m_scraper) strReplace = m_scraper->GetString(strtol(strInfo.c_str(),NULL,10)); strDest.replace(strDest.begin()+iIndex,strDest.begin()+iEnd+1,strReplace); iIndex += strReplace.length(); } iIndex = 0; while ((iIndex = strDest.find("\\n",iIndex)) != CStdString::npos) strDest.replace(strDest.begin()+iIndex,strDest.begin()+iIndex+2,"\n"); }