Skip to content

Commit

Permalink
Merge pull request #450 from lifenjoiner/var
Browse files Browse the repository at this point in the history
${filepath}/${filename}/${fileext} only for regex mode
  • Loading branch information
stefankueng authored Feb 7, 2024
2 parents 4f399ef + 2576aa5 commit 632b65b
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions src/SearchDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3713,22 +3713,25 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
// we keep it simple:
// files bigger than 30MB are considered binary. Binary files are searched
// as if they're ANSI text files.
std::wstring localSearchString = searchString;
std::wstring localSearchString = searchString;
std::wstring fileNameFull = sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1);

SearchReplace(localSearchString, L"${filepath}", sInfo.filePath);
std::wstring fileNameFull = sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1);
auto dotPos = fileNameFull.find_last_of('.');
if (dotPos != std::string::npos)
if (bUseRegex)
{
std::wstring filename = fileNameFull.substr(0, dotPos);
SearchReplace(localSearchString, L"${filename}", filename);
if (fileNameFull.size() > dotPos)
SearchReplace(localSearchString, L"${filepath}", sInfo.filePath);
auto dotPos = fileNameFull.find_last_of('.');
if (dotPos != std::string::npos)
{
std::wstring fileExt = fileNameFull.substr(dotPos + 1);
SearchReplace(localSearchString, L"${fileext}", fileExt);
std::wstring filename = fileNameFull.substr(0, dotPos);
SearchReplace(localSearchString, L"${filename}", filename);
if (fileNameFull.size() > dotPos)
{
std::wstring fileExt = fileNameFull.substr(dotPos + 1);
SearchReplace(localSearchString, L"${fileext}", fileExt);
}
}
}
if (!bUseRegex)
else
{
using namespace std::string_literals;
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})
Expand Down Expand Up @@ -3874,17 +3877,20 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
flags &= ~boost::match_prev_avail;
flags &= ~boost::match_not_bob;
RegexReplaceFormatter replaceFmt(m_replaceString);
replaceFmt.SetReplacePair(L"${filepath}", sInfo.filePath);
std::wstring fileNameFullW = sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1);
auto dotPosW = fileNameFullW.find_last_of('.');
if (dotPosW != std::string::npos)
if (bUseRegex)
{
std::wstring filename = fileNameFullW.substr(0, dotPosW);
replaceFmt.SetReplacePair(L"${filename}", filename);
if (fileNameFullW.size() > dotPosW)
replaceFmt.SetReplacePair(L"${filepath}", sInfo.filePath);
std::wstring fileNameFullW = sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1);
auto dotPosW = fileNameFullW.find_last_of('.');
if (dotPosW != std::string::npos)
{
std::wstring fileExt = fileNameFullW.substr(dotPosW + 1);
replaceFmt.SetReplacePair(L"${fileext}", fileExt);
std::wstring filename = fileNameFullW.substr(0, dotPosW);
replaceFmt.SetReplacePair(L"${filename}", filename);
if (fileNameFullW.size() > dotPosW)
{
std::wstring fileExt = fileNameFullW.substr(dotPosW + 1);
replaceFmt.SetReplacePair(L"${fileext}", fileExt);
}
}
}
std::wstring replaced = regex_replace(textFile.GetFileString(), expression, replaceFmt, flags);
Expand Down Expand Up @@ -4149,16 +4155,19 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
flags &= ~boost::match_not_bob;
RegexReplaceFormatterA replaceFmt(CUnicodeUtils::StdGetUTF8(m_replaceString));
replaceFmt.SetReplacePair("${filepath}", CUnicodeUtils::StdGetUTF8(sInfo.filePath));
std::string fileNameFullA = CUnicodeUtils::StdGetUTF8(sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1));
auto dotPosA = fileNameFullA.find_last_of('.');
if (dotPosA != std::string::npos)
if (bUseRegex)
{
std::string filename = fileNameFullA.substr(0, dotPosA);
replaceFmt.SetReplacePair("${filename}", filename);
if (fileNameFull.size() > dotPosA)
std::string fileNameFullA = CUnicodeUtils::StdGetUTF8(sInfo.filePath.substr(sInfo.filePath.find_last_of('\\') + 1));
auto dotPosA = fileNameFullA.find_last_of('.');
if (dotPosA != std::string::npos)
{
std::string fileExt = fileNameFullA.substr(dotPosA + 1);
replaceFmt.SetReplacePair("${fileext}", fileExt);
std::string filename = fileNameFullA.substr(0, dotPosA);
replaceFmt.SetReplacePair("${filename}", filename);
if (fileNameFull.size() > dotPosA)
{
std::string fileExt = fileNameFullA.substr(dotPosA + 1);
replaceFmt.SetReplacePair("${fileext}", fileExt);
}
}
}

Expand Down

0 comments on commit 632b65b

Please sign in to comment.