Skip to content

Commit 632b65b

Browse files
authored
Merge pull request #450 from lifenjoiner/var
${filepath}/${filename}/${fileext} only for regex mode
2 parents 4f399ef + 2576aa5 commit 632b65b

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

src/SearchDlg.cpp

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3713,22 +3713,25 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
37133713
// we keep it simple:
37143714
// files bigger than 30MB are considered binary. Binary files are searched
37153715
// as if they're ANSI text files.
3716-
std::wstring localSearchString = searchString;
3716+
std::wstring localSearchString = searchString;
3717+
std::wstring fileNameFull = sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1);
37173718

3718-
SearchReplace(localSearchString, L"${filepath}", sInfo.filePath);
3719-
std::wstring fileNameFull = sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1);
3720-
auto dotPos = fileNameFull.find_last_of('.');
3721-
if (dotPos != std::string::npos)
3719+
if (bUseRegex)
37223720
{
3723-
std::wstring filename = fileNameFull.substr(0, dotPos);
3724-
SearchReplace(localSearchString, L"${filename}", filename);
3725-
if (fileNameFull.size() > dotPos)
3721+
SearchReplace(localSearchString, L"${filepath}", sInfo.filePath);
3722+
auto dotPos = fileNameFull.find_last_of('.');
3723+
if (dotPos != std::string::npos)
37263724
{
3727-
std::wstring fileExt = fileNameFull.substr(dotPos + 1);
3728-
SearchReplace(localSearchString, L"${fileext}", fileExt);
3725+
std::wstring filename = fileNameFull.substr(0, dotPos);
3726+
SearchReplace(localSearchString, L"${filename}", filename);
3727+
if (fileNameFull.size() > dotPos)
3728+
{
3729+
std::wstring fileExt = fileNameFull.substr(dotPos + 1);
3730+
SearchReplace(localSearchString, L"${fileext}", fileExt);
3731+
}
37293732
}
37303733
}
3731-
if (!bUseRegex)
3734+
else
37323735
{
37333736
using namespace std::string_literals;
37343737
for (const auto& c : {L"\\"s, L"^"s, L"$"s, L"."s, L"|"s, L"?"s, L"*"s, L"+"s, L"("s, L")"s, L"["s, L"{"s})
@@ -3874,17 +3877,20 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
38743877
flags &= ~boost::match_prev_avail;
38753878
flags &= ~boost::match_not_bob;
38763879
RegexReplaceFormatter replaceFmt(m_replaceString);
3877-
replaceFmt.SetReplacePair(L"${filepath}", sInfo.filePath);
3878-
std::wstring fileNameFullW = sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1);
3879-
auto dotPosW = fileNameFullW.find_last_of('.');
3880-
if (dotPosW != std::string::npos)
3880+
if (bUseRegex)
38813881
{
3882-
std::wstring filename = fileNameFullW.substr(0, dotPosW);
3883-
replaceFmt.SetReplacePair(L"${filename}", filename);
3884-
if (fileNameFullW.size() > dotPosW)
3882+
replaceFmt.SetReplacePair(L"${filepath}", sInfo.filePath);
3883+
std::wstring fileNameFullW = sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1);
3884+
auto dotPosW = fileNameFullW.find_last_of('.');
3885+
if (dotPosW != std::string::npos)
38853886
{
3886-
std::wstring fileExt = fileNameFullW.substr(dotPosW + 1);
3887-
replaceFmt.SetReplacePair(L"${fileext}", fileExt);
3887+
std::wstring filename = fileNameFullW.substr(0, dotPosW);
3888+
replaceFmt.SetReplacePair(L"${filename}", filename);
3889+
if (fileNameFullW.size() > dotPosW)
3890+
{
3891+
std::wstring fileExt = fileNameFullW.substr(dotPosW + 1);
3892+
replaceFmt.SetReplacePair(L"${fileext}", fileExt);
3893+
}
38883894
}
38893895
}
38903896
std::wstring replaced = regex_replace(textFile.GetFileString(), expression, replaceFmt, flags);
@@ -4149,16 +4155,19 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
41494155
flags &= ~boost::match_not_bob;
41504156
RegexReplaceFormatterA replaceFmt(CUnicodeUtils::StdGetUTF8(m_replaceString));
41514157
replaceFmt.SetReplacePair("${filepath}", CUnicodeUtils::StdGetUTF8(sInfo.filePath));
4152-
std::string fileNameFullA = CUnicodeUtils::StdGetUTF8(sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1));
4153-
auto dotPosA = fileNameFullA.find_last_of('.');
4154-
if (dotPosA != std::string::npos)
4158+
if (bUseRegex)
41554159
{
4156-
std::string filename = fileNameFullA.substr(0, dotPosA);
4157-
replaceFmt.SetReplacePair("${filename}", filename);
4158-
if (fileNameFull.size() > dotPosA)
4160+
std::string fileNameFullA = CUnicodeUtils::StdGetUTF8(sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1));
4161+
auto dotPosA = fileNameFullA.find_last_of('.');
4162+
if (dotPosA != std::string::npos)
41594163
{
4160-
std::string fileExt = fileNameFullA.substr(dotPosA + 1);
4161-
replaceFmt.SetReplacePair("${fileext}", fileExt);
4164+
std::string filename = fileNameFullA.substr(0, dotPosA);
4165+
replaceFmt.SetReplacePair("${filename}", filename);
4166+
if (fileNameFull.size() > dotPosA)
4167+
{
4168+
std::string fileExt = fileNameFullA.substr(dotPosA + 1);
4169+
replaceFmt.SetReplacePair("${fileext}", fileExt);
4170+
}
41624171
}
41634172
}
41644173

0 commit comments

Comments
 (0)