@@ -3713,22 +3713,25 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
3713
3713
// we keep it simple:
3714
3714
// files bigger than 30MB are considered binary. Binary files are searched
3715
3715
// 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 );
3717
3718
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)
3722
3720
{
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 )
3726
3724
{
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
+ }
3729
3732
}
3730
3733
}
3731
- if (!bUseRegex)
3734
+ else
3732
3735
{
3733
3736
using namespace std ::string_literals;
3734
3737
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
3874
3877
flags &= ~boost::match_prev_avail;
3875
3878
flags &= ~boost::match_not_bob;
3876
3879
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)
3881
3881
{
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)
3885
3886
{
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
+ }
3888
3894
}
3889
3895
}
3890
3896
std::wstring replaced = regex_replace (textFile.GetFileString (), expression, replaceFmt, flags);
@@ -4149,16 +4155,19 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
4149
4155
flags &= ~boost::match_not_bob;
4150
4156
RegexReplaceFormatterA replaceFmt (CUnicodeUtils::StdGetUTF8 (m_replaceString));
4151
4157
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)
4155
4159
{
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 )
4159
4163
{
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
+ }
4162
4171
}
4163
4172
}
4164
4173
0 commit comments