std::string CStackDirectory::GetStackedTitlePath(const std::string &strPath, VECCREGEXP& RegExps) { CStackDirectory stack; CFileItemList files; std::string strStackTitlePath, strCommonDir = URIUtils::GetParentPath(strPath); const CURL pathToUrl(strPath); stack.GetDirectory(pathToUrl, files); if (files.Size() > 1) { std::string strStackTitle; std::string File1 = URIUtils::GetFileName(files[0]->GetPath()); std::string File2 = URIUtils::GetFileName(files[1]->GetPath()); // Check if source path uses URL encoding if (URIUtils::HasEncodedFilename(CURL(strCommonDir))) { File1 = CURL::Decode(File1); File2 = CURL::Decode(File2); } std::vector<CRegExp>::iterator itRegExp = RegExps.begin(); int offset = 0; while (itRegExp != RegExps.end()) { if (itRegExp->RegFind(File1, offset) != -1) { std::string Title1 = itRegExp->GetMatch(1), Volume1 = itRegExp->GetMatch(2), Ignore1 = itRegExp->GetMatch(3), Extension1 = itRegExp->GetMatch(4); if (offset) Title1 = File1.substr(0, itRegExp->GetSubStart(2)); if (itRegExp->RegFind(File2, offset) != -1) { std::string Title2 = itRegExp->GetMatch(1), Volume2 = itRegExp->GetMatch(2), Ignore2 = itRegExp->GetMatch(3), Extension2 = itRegExp->GetMatch(4); if (offset) Title2 = File2.substr(0, itRegExp->GetSubStart(2)); if (StringUtils::EqualsNoCase(Title1, Title2)) { if (!StringUtils::EqualsNoCase(Volume1, Volume2)) { if (StringUtils::EqualsNoCase(Ignore1, Ignore2) && StringUtils::EqualsNoCase(Extension1, Extension2)) { // got it strStackTitle = Title1 + Ignore1 + Extension1; // Check if source path uses URL encoding if (URIUtils::HasEncodedFilename(CURL(strCommonDir))) strStackTitle = CURL::Encode(strStackTitle); itRegExp = RegExps.end(); break; } else // Invalid stack break; } else // Early match, retry with offset { offset = itRegExp->GetSubStart(3); continue; } } } } offset = 0; itRegExp++; } if (!strCommonDir.empty() && !strStackTitle.empty()) strStackTitlePath = strCommonDir + strStackTitle; } return strStackTitlePath; }
CStdString CStackDirectory::GetStackedTitlePath(const CStdString &strPath, VECCREGEXP& RegExps) { CStackDirectory stack; CFileItemList files; CStdString strStackTitlePath, strCommonDir = URIUtils::GetParentPath(strPath); stack.GetDirectory(strPath, files); if (files.Size() > 1) { CStdString strStackTitle; CStdString File1 = URIUtils::GetFileName(files[0]->m_strPath); CStdString File2 = URIUtils::GetFileName(files[1]->m_strPath); std::vector<CRegExp>::iterator itRegExp = RegExps.begin(); int offset = 0; while (itRegExp != RegExps.end()) { if (itRegExp->RegFind(File1, offset) != -1) { CStdString Title1 = itRegExp->GetMatch(1), Volume1 = itRegExp->GetMatch(2), Ignore1 = itRegExp->GetMatch(3), Extension1 = itRegExp->GetMatch(4); if (offset) Title1 = File1.substr(0, itRegExp->GetSubStart(2)); if (itRegExp->RegFind(File2, offset) != -1) { CStdString Title2 = itRegExp->GetMatch(1), Volume2 = itRegExp->GetMatch(2), Ignore2 = itRegExp->GetMatch(3), Extension2 = itRegExp->GetMatch(4); if (offset) Title2 = File2.substr(0, itRegExp->GetSubStart(2)); if (Title1.Equals(Title2)) { if (!Volume1.Equals(Volume2)) { if (Ignore1.Equals(Ignore2) && Extension1.Equals(Extension2)) { // got it strStackTitle = Title1 + Ignore1 + Extension1; itRegExp = RegExps.end(); break; } else // Invalid stack break; } else // Early match, retry with offset { offset = itRegExp->GetSubStart(3); continue; } } } } offset = 0; itRegExp++; } if (!strCommonDir.empty() && !strStackTitle.empty()) strStackTitlePath = strCommonDir + strStackTitle; } return strStackTitlePath; }