Index: src/libchcore/TStringPattern.cpp =================================================================== diff -u -r22c7d5559ca17c9b1859d2283b667516b23ac597 -r3401d5079f33b29a7783b65bfad5f34d89a33ba5 --- src/libchcore/TStringPattern.cpp (.../TStringPattern.cpp) (revision 22c7d5559ca17c9b1859d2283b667516b23ac597) +++ src/libchcore/TStringPattern.cpp (.../TStringPattern.cpp) (revision 3401d5079f33b29a7783b65bfad5f34d89a33ba5) @@ -1,3 +1,21 @@ +// ============================================================================ +// Copyright (C) 2001-2020 by Jozef Starosczyk +// ixen {at} copyhandler [dot] com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ #include "stdafx.h" #include "TStringPattern.h" #include @@ -129,9 +147,15 @@ return bMatch; } - bool TStringPattern::Matches(const TString& strTextToMatch) const + bool TStringPattern::Matches(const TSmartPath& pathToMatch) const { - return MatchMask(m_strPattern.c_str(), strTextToMatch.c_str()); + switch(m_ePatternType) + { + case EPatternType::eType_Wildcard: + return MatchMask(m_strPattern.c_str(), pathToMatch.GetFileName().ToString()); + default: + throw std::invalid_argument("Unsupported pattern type"); + } } void TStringPattern::SetPattern(const TString& strPattern, EPatternType ePatternType) Index: src/libchcore/TStringPattern.h =================================================================== diff -u -r22c7d5559ca17c9b1859d2283b667516b23ac597 -r3401d5079f33b29a7783b65bfad5f34d89a33ba5 --- src/libchcore/TStringPattern.h (.../TStringPattern.h) (revision 22c7d5559ca17c9b1859d2283b667516b23ac597) +++ src/libchcore/TStringPattern.h (.../TStringPattern.h) (revision 3401d5079f33b29a7783b65bfad5f34d89a33ba5) @@ -20,6 +20,7 @@ #include "../libstring/TString.h" #include "libchcore.h" +#include "TPath.h" namespace chcore { @@ -36,7 +37,7 @@ explicit TStringPattern(const string::TString& strPattern, EPatternType ePatternType = EPatternType::eType_Wildcard); void SetPattern(const string::TString& strPattern, EPatternType ePatternType = EPatternType::eType_Wildcard); - bool Matches(const string::TString& strTextToMatch) const; + bool Matches(const TSmartPath& pathToMatch) const; EPatternType GetPatternType() const { return m_ePatternType; } string::TString GetPattern() const { return m_strPattern; } Index: src/libchcore/TStringPatternArray.cpp =================================================================== diff -u -r22c7d5559ca17c9b1859d2283b667516b23ac597 -r3401d5079f33b29a7783b65bfad5f34d89a33ba5 --- src/libchcore/TStringPatternArray.cpp (.../TStringPatternArray.cpp) (revision 22c7d5559ca17c9b1859d2283b667516b23ac597) +++ src/libchcore/TStringPatternArray.cpp (.../TStringPatternArray.cpp) (revision 3401d5079f33b29a7783b65bfad5f34d89a33ba5) @@ -24,22 +24,22 @@ namespace chcore { - bool TStringPatternArray::MatchesAny(const TString& strTextToMatch) const + bool TStringPatternArray::MatchesAny(const TSmartPath& pathToMatch) const { for (const TStringPattern& pattern : m_vItems) { - if (pattern.Matches(strTextToMatch)) + if (pattern.Matches(pathToMatch)) return true; } return false; } - bool TStringPatternArray::MatchesAll(const TString& strTextToMatch) const + bool TStringPatternArray::MatchesAll(const TSmartPath& pathToMatch) const { for (const TStringPattern& pattern : m_vItems) { - if (!pattern.Matches(strTextToMatch)) + if (!pattern.Matches(pathToMatch)) return false; } Index: src/libchcore/TStringPatternArray.h =================================================================== diff -u -r22c7d5559ca17c9b1859d2283b667516b23ac597 -r3401d5079f33b29a7783b65bfad5f34d89a33ba5 --- src/libchcore/TStringPatternArray.h (.../TStringPatternArray.h) (revision 22c7d5559ca17c9b1859d2283b667516b23ac597) +++ src/libchcore/TStringPatternArray.h (.../TStringPatternArray.h) (revision 3401d5079f33b29a7783b65bfad5f34d89a33ba5) @@ -40,8 +40,8 @@ { public: // pattern api - bool MatchesAny(const string::TString& strTextToMatch) const; - bool MatchesAll(const string::TString& strTextToMatch) const; + bool MatchesAny(const TSmartPath& pathToMatch) const; + bool MatchesAll(const TSmartPath& pathToMatch) const; // string parsing void FromString(const string::TString& strPatterns, TStringPattern::EPatternType eDefaultPatternType = TStringPattern::EPatternType::eType_Wildcard); Index: src/libchcore/Tests/TestsTStringPattern.cpp =================================================================== diff -u -r22c7d5559ca17c9b1859d2283b667516b23ac597 -r3401d5079f33b29a7783b65bfad5f34d89a33ba5 --- src/libchcore/Tests/TestsTStringPattern.cpp (.../TestsTStringPattern.cpp) (revision 22c7d5559ca17c9b1859d2283b667516b23ac597) +++ src/libchcore/Tests/TestsTStringPattern.cpp (.../TestsTStringPattern.cpp) (revision 3401d5079f33b29a7783b65bfad5f34d89a33ba5) @@ -55,28 +55,28 @@ { TStringPattern patternEmpty(L"*.bat", TStringPattern::EPatternType::eType_Wildcard); - EXPECT_TRUE(patternEmpty.Matches(L"autorun.bat")); + EXPECT_TRUE(patternEmpty.Matches(PathFromString(L"autorun.bat"))); } TEST(TestsTStringPattern, Matches_Negative_StarDotBat) { TStringPattern patternEmpty(L"*.bat", TStringPattern::EPatternType::eType_Wildcard); - EXPECT_FALSE(patternEmpty.Matches(L"autorun.batx")); + EXPECT_FALSE(patternEmpty.Matches(PathFromString(L"autorun.batx"))); } TEST(TestsTStringPattern, Matches_Positive_StarDotStar) { TStringPattern patternEmpty(L"*.*", TStringPattern::EPatternType::eType_Wildcard); - EXPECT_TRUE(patternEmpty.Matches(L"autorun.bat")); + EXPECT_TRUE(patternEmpty.Matches(PathFromString(L"autorun.bat"))); } TEST(TestsTStringPattern, Matches_Negative_StarDotStar) { TStringPattern patternEmpty(L"*.*", TStringPattern::EPatternType::eType_Wildcard); - EXPECT_FALSE(patternEmpty.Matches(L"autorun")); + EXPECT_FALSE(patternEmpty.Matches(PathFromString(L"autorun"))); } /////////////////////////////////////////////////////////// @@ -86,14 +86,14 @@ { TStringPattern patternEmpty(L"ad*bo*", TStringPattern::EPatternType::eType_Wildcard); - EXPECT_TRUE(patternEmpty.Matches(L"addon-boo.bat")); + EXPECT_TRUE(patternEmpty.Matches(PathFromString(L"addon-boo.bat"))); } TEST(TestsTStringPattern, Matches_Negative_MultiStar) { TStringPattern patternEmpty(L"ad*bo*", TStringPattern::EPatternType::eType_Wildcard); - EXPECT_FALSE(patternEmpty.Matches(L"addon-doo.bat")); + EXPECT_FALSE(patternEmpty.Matches(PathFromString(L"addon-doo.bat"))); } //////////////////////////////////////////////////////////// @@ -103,12 +103,12 @@ { TStringPattern patternEmpty(L"a??b?r", TStringPattern::EPatternType::eType_Wildcard); - EXPECT_TRUE(patternEmpty.Matches(L"arbbar")); + EXPECT_TRUE(patternEmpty.Matches(PathFromString(L"arbbar"))); } TEST(TestsTStringPattern, Matches_Negative_QuestionMultiPos) { TStringPattern patternEmpty(L"a??b?r", TStringPattern::EPatternType::eType_Wildcard); - EXPECT_FALSE(patternEmpty.Matches(L"arbxar")); + EXPECT_FALSE(patternEmpty.Matches(PathFromString(L"arbxar"))); } Index: src/libchcore/Tests/TestsTStringPatternArray.cpp =================================================================== diff -u -r22c7d5559ca17c9b1859d2283b667516b23ac597 -r3401d5079f33b29a7783b65bfad5f34d89a33ba5 --- src/libchcore/Tests/TestsTStringPatternArray.cpp (.../TestsTStringPatternArray.cpp) (revision 22c7d5559ca17c9b1859d2283b667516b23ac597) +++ src/libchcore/Tests/TestsTStringPatternArray.cpp (.../TestsTStringPatternArray.cpp) (revision 3401d5079f33b29a7783b65bfad5f34d89a33ba5) @@ -86,7 +86,7 @@ arrPatterns.Add(TStringPattern(L"*.bat", TStringPattern::EPatternType::eType_Wildcard)); arrPatterns.Add(TStringPattern(L"*.exe", TStringPattern::EPatternType::eType_Wildcard)); - EXPECT_TRUE(arrPatterns.MatchesAny(L"autostart.bat")); + EXPECT_TRUE(arrPatterns.MatchesAny(PathFromString(L"autostart.bat"))); } TEST(TestsTStringPatternArray, MatchesAny_Negative) @@ -96,7 +96,7 @@ arrPatterns.Add(TStringPattern(L"*.bat", TStringPattern::EPatternType::eType_Wildcard)); arrPatterns.Add(TStringPattern(L"*.exe", TStringPattern::EPatternType::eType_Wildcard)); - EXPECT_FALSE(arrPatterns.MatchesAny(L"autostart.com")); + EXPECT_FALSE(arrPatterns.MatchesAny(PathFromString(L"autostart.com"))); } ///////////////////////////////////////////////// @@ -108,7 +108,7 @@ arrPatterns.Add(TStringPattern(L"*.bat", TStringPattern::EPatternType::eType_Wildcard)); arrPatterns.Add(TStringPattern(L"autostart.*", TStringPattern::EPatternType::eType_Wildcard)); - EXPECT_TRUE(arrPatterns.MatchesAll(L"autostart.bat")); + EXPECT_TRUE(arrPatterns.MatchesAll(PathFromString(L"autostart.bat"))); } TEST(TestsTStringPatternArray, MatchesAll_Negative) @@ -118,7 +118,7 @@ arrPatterns.Add(TStringPattern(L"*.bat", TStringPattern::EPatternType::eType_Wildcard)); arrPatterns.Add(TStringPattern(L"autostart.*", TStringPattern::EPatternType::eType_Wildcard)); - EXPECT_FALSE(arrPatterns.MatchesAll(L"autostart.exe")); + EXPECT_FALSE(arrPatterns.MatchesAll(PathFromString(L"autostart.exe"))); } ///////////////////////////////////////////////// Index: src/libchengine/FeedbackAlreadyExistsRule.cpp =================================================================== diff -u -r22c7d5559ca17c9b1859d2283b667516b23ac597 -r3401d5079f33b29a7783b65bfad5f34d89a33ba5 --- src/libchengine/FeedbackAlreadyExistsRule.cpp (.../FeedbackAlreadyExistsRule.cpp) (revision 22c7d5559ca17c9b1859d2283b667516b23ac597) +++ src/libchengine/FeedbackAlreadyExistsRule.cpp (.../FeedbackAlreadyExistsRule.cpp) (revision 3401d5079f33b29a7783b65bfad5f34d89a33ba5) @@ -105,12 +105,12 @@ if(m_bUseMask) { - if(!m_spaMask.Get().MatchesAny(rDstFile.GetFullFilePath().GetFileName().ToString())) + if(!m_spaMask.Get().MatchesAny(rDstFile.GetFullFilePath())) return false; } if(m_bUseExcludeMask) { - if(m_spaExcludeMask.Get().MatchesAny(rDstFile.GetFullFilePath().GetFileName().ToString())) + if(m_spaExcludeMask.Get().MatchesAny(rDstFile.GetFullFilePath())) return false; } if(m_bUseDateCompare) Index: src/libchengine/FeedbackErrorRule.cpp =================================================================== diff -u -re6f64ea0eecaf86dfa1a42c80604d227b69be768 -r3401d5079f33b29a7783b65bfad5f34d89a33ba5 --- src/libchengine/FeedbackErrorRule.cpp (.../FeedbackErrorRule.cpp) (revision e6f64ea0eecaf86dfa1a42c80604d227b69be768) +++ src/libchengine/FeedbackErrorRule.cpp (.../FeedbackErrorRule.cpp) (revision 3401d5079f33b29a7783b65bfad5f34d89a33ba5) @@ -108,12 +108,12 @@ TSmartPath path = PathFromWString(strSrcPath); if(m_bUseMask) { - if(!m_spaMask.Get().MatchesAny(path.GetFileName().ToString())) + if(!m_spaMask.Get().MatchesAny(path)) return false; } if(m_bUseExcludeMask) { - if(m_spaExcludeMask.Get().MatchesAny(path.GetFileName().ToString())) + if(m_spaExcludeMask.Get().MatchesAny(path)) return false; } if(m_bUseErrorType) Index: src/libchengine/FeedbackNotEnoughSpaceRule.cpp =================================================================== diff -u -re6f64ea0eecaf86dfa1a42c80604d227b69be768 -r3401d5079f33b29a7783b65bfad5f34d89a33ba5 --- src/libchengine/FeedbackNotEnoughSpaceRule.cpp (.../FeedbackNotEnoughSpaceRule.cpp) (revision e6f64ea0eecaf86dfa1a42c80604d227b69be768) +++ src/libchengine/FeedbackNotEnoughSpaceRule.cpp (.../FeedbackNotEnoughSpaceRule.cpp) (revision 3401d5079f33b29a7783b65bfad5f34d89a33ba5) @@ -86,12 +86,12 @@ TSmartPath path = PathFromWString(strDstPath); if(m_bUseMask) { - if(!m_spaMask.Get().MatchesAny(path.GetFileName().ToString())) + if(!m_spaMask.Get().MatchesAny(path)) return false; } if(m_bUseExcludeMask) { - if(m_spaExcludeMask.Get().MatchesAny(path.GetFileName().ToString())) + if(m_spaExcludeMask.Get().MatchesAny(path)) return false; } Index: src/libchengine/TFileFilter.cpp =================================================================== diff -u -r22c7d5559ca17c9b1859d2283b667516b23ac597 -r3401d5079f33b29a7783b65bfad5f34d89a33ba5 --- src/libchengine/TFileFilter.cpp (.../TFileFilter.cpp) (revision 22c7d5559ca17c9b1859d2283b667516b23ac597) +++ src/libchengine/TFileFilter.cpp (.../TFileFilter.cpp) (revision 3401d5079f33b29a7783b65bfad5f34d89a33ba5) @@ -322,14 +322,14 @@ // check by mask if (m_bUseMask) { - if (!m_astrMask.Get().MatchesAny(spInfo->GetFullFilePath().GetFileName().ToString())) + if (!m_astrMask.Get().MatchesAny(spInfo->GetFullFilePath())) return false; } // excluding mask if (m_bUseExcludeMask) { - if (m_astrExcludeMask.Get().MatchesAny(spInfo->GetFullFilePath().GetFileName().ToString())) + if (m_astrExcludeMask.Get().MatchesAny(spInfo->GetFullFilePath())) return false; }