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; }