Skip to content

Commit 2576aa5

Browse files
committed
${filepath}/${filename}/${fileext} only for regex mode
Text mode always keeps the original; or we can't use them as strings.
1 parent 373655e commit 2576aa5

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
@@ -3618,22 +3618,25 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
36183618
// we keep it simple:
36193619
// files bigger than 30MB are considered binary. Binary files are searched
36203620
// as if they're ANSI text files.
3621-
std::wstring localSearchString = searchString;
3621+
std::wstring localSearchString = searchString;
3622+
std::wstring fileNameFull = sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1);
36223623

3623-
SearchReplace(localSearchString, L"${filepath}", sInfo.filePath);
3624-
std::wstring fileNameFull = sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1);
3625-
auto dotPos = fileNameFull.find_last_of('.');
3626-
if (dotPos != std::string::npos)
3624+
if (bUseRegex)
36273625
{
3628-
std::wstring filename = fileNameFull.substr(0, dotPos);
3629-
SearchReplace(localSearchString, L"${filename}", filename);
3630-
if (fileNameFull.size() > dotPos)
3626+
SearchReplace(localSearchString, L"${filepath}", sInfo.filePath);
3627+
auto dotPos = fileNameFull.find_last_of('.');
3628+
if (dotPos != std::string::npos)
36313629
{
3632-
std::wstring fileExt = fileNameFull.substr(dotPos + 1);
3633-
SearchReplace(localSearchString, L"${fileext}", fileExt);
3630+
std::wstring filename = fileNameFull.substr(0, dotPos);
3631+
SearchReplace(localSearchString, L"${filename}", filename);
3632+
if (fileNameFull.size() > dotPos)
3633+
{
3634+
std::wstring fileExt = fileNameFull.substr(dotPos + 1);
3635+
SearchReplace(localSearchString, L"${fileext}", fileExt);
3636+
}
36343637
}
36353638
}
3636-
if (!bUseRegex)
3639+
else
36373640
{
36383641
using namespace std::string_literals;
36393642
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})
@@ -3779,17 +3782,20 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
37793782
flags &= ~boost::match_prev_avail;
37803783
flags &= ~boost::match_not_bob;
37813784
RegexReplaceFormatter replaceFmt(m_replaceString);
3782-
replaceFmt.SetReplacePair(L"${filepath}", sInfo.filePath);
3783-
std::wstring fileNameFullW = sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1);
3784-
auto dotPosW = fileNameFullW.find_last_of('.');
3785-
if (dotPosW != std::string::npos)
3785+
if (bUseRegex)
37863786
{
3787-
std::wstring filename = fileNameFullW.substr(0, dotPosW);
3788-
replaceFmt.SetReplacePair(L"${filename}", filename);
3789-
if (fileNameFullW.size() > dotPosW)
3787+
replaceFmt.SetReplacePair(L"${filepath}", sInfo.filePath);
3788+
std::wstring fileNameFullW = sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1);
3789+
auto dotPosW = fileNameFullW.find_last_of('.');
3790+
if (dotPosW != std::string::npos)
37903791
{
3791-
std::wstring fileExt = fileNameFullW.substr(dotPosW + 1);
3792-
replaceFmt.SetReplacePair(L"${fileext}", fileExt);
3792+
std::wstring filename = fileNameFullW.substr(0, dotPosW);
3793+
replaceFmt.SetReplacePair(L"${filename}", filename);
3794+
if (fileNameFullW.size() > dotPosW)
3795+
{
3796+
std::wstring fileExt = fileNameFullW.substr(dotPosW + 1);
3797+
replaceFmt.SetReplacePair(L"${fileext}", fileExt);
3798+
}
37933799
}
37943800
}
37953801
std::wstring replaced = regex_replace(textFile.GetFileString(), expression, replaceFmt, flags);
@@ -4054,16 +4060,19 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
40544060
flags &= ~boost::match_not_bob;
40554061
RegexReplaceFormatterA replaceFmt(CUnicodeUtils::StdGetUTF8(m_replaceString));
40564062
replaceFmt.SetReplacePair("${filepath}", CUnicodeUtils::StdGetUTF8(sInfo.filePath));
4057-
std::string fileNameFullA = CUnicodeUtils::StdGetUTF8(sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1));
4058-
auto dotPosA = fileNameFullA.find_last_of('.');
4059-
if (dotPosA != std::string::npos)
4063+
if (bUseRegex)
40604064
{
4061-
std::string filename = fileNameFullA.substr(0, dotPosA);
4062-
replaceFmt.SetReplacePair("${filename}", filename);
4063-
if (fileNameFull.size() > dotPosA)
4065+
std::string fileNameFullA = CUnicodeUtils::StdGetUTF8(sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1));
4066+
auto dotPosA = fileNameFullA.find_last_of('.');
4067+
if (dotPosA != std::string::npos)
40644068
{
4065-
std::string fileExt = fileNameFullA.substr(dotPosA + 1);
4066-
replaceFmt.SetReplacePair("${fileext}", fileExt);
4069+
std::string filename = fileNameFullA.substr(0, dotPosA);
4070+
replaceFmt.SetReplacePair("${filename}", filename);
4071+
if (fileNameFull.size() > dotPosA)
4072+
{
4073+
std::string fileExt = fileNameFullA.substr(dotPosA + 1);
4074+
replaceFmt.SetReplacePair("${fileext}", fileExt);
4075+
}
40674076
}
40684077
}
40694078

0 commit comments

Comments
 (0)