@@ -3971,6 +3971,19 @@ int CSearchDlg::SearchOnTextFile(CSearchInfo& sInfo, const std::wstring& searchR
39713971 if (m_bReplace) // synchronize Replace and Search for cancellation and reducing repetitive work on huge files
39723972 {
39733973 m_backupAndTempFiles.insert (filePathTemp);
3974+ replaceFmt.SetReplacePair (L" ${filepath}" , sInfo .filePath );
3975+ std::wstring fileNameFullW = sInfo .filePath .substr (sInfo .filePath .find_last_of (' \\ ' ) + 1 );
3976+ auto dotPosW = fileNameFullW.find_last_of (' .' );
3977+ if (dotPosW != std::string::npos)
3978+ {
3979+ std::wstring filename = fileNameFullW.substr (0 , dotPosW);
3980+ replaceFmt.SetReplacePair (L" ${filename}" , filename);
3981+ if (fileNameFullW.size () > dotPosW)
3982+ {
3983+ std::wstring fileExt = fileNameFullW.substr (dotPosW + 1 );
3984+ replaceFmt.SetReplacePair (L" ${fileext}" , fileExt);
3985+ }
3986+ }
39743987 }
39753988 do
39763989 {
@@ -4219,6 +4232,40 @@ int CSearchDlg::SearchByFilePath(CSearchInfo& sInfo, const std::wstring& searchR
42194232 return -1 ;
42204233 }
42214234 outFileBufA.sputn (inData, skipSize);
4235+
4236+ if constexpr (sizeof (CharT) > 1 )
4237+ {
4238+ replaceFmt.SetReplacePair (L" ${filepath}" , sInfo .filePath );
4239+ std::wstring fileNameFullW = sInfo .filePath .substr (sInfo .filePath .find_last_of (' \\ ' ) + 1 );
4240+ auto dotPosW = fileNameFullW.find_last_of (' .' );
4241+ if (dotPosW != std::string::npos)
4242+ {
4243+ std::wstring filename = fileNameFullW.substr (0 , dotPosW);
4244+ replaceFmt.SetReplacePair (L" ${filename}" , filename);
4245+ if (fileNameFullW.size () > dotPosW)
4246+ {
4247+ std::wstring fileExt = fileNameFullW.substr (dotPosW + 1 );
4248+ replaceFmt.SetReplacePair (L" ${fileext}" , fileExt);
4249+ }
4250+ }
4251+ }
4252+ else
4253+ {
4254+ std::basic_string<CharT> filePathA = ConvertToString<CharT>(sInfo .filePath , sInfo .encoding );
4255+ replaceFmt.SetReplacePair (" ${filepath}" , filePathA);
4256+ std::string fileNameFullA = filePathA.substr (filePathA.find_last_of (' \\ ' ) + 1 );
4257+ auto dotPosA = fileNameFullA.find_last_of (' .' );
4258+ if (dotPosA != std::string::npos)
4259+ {
4260+ std::string filename = fileNameFullA.substr (0 , dotPosA);
4261+ replaceFmt.SetReplacePair (" ${filename}" , filename);
4262+ if (fileNameFullA.size () > dotPosA)
4263+ {
4264+ std::string fileExt = fileNameFullA.substr (dotPosA + 1 );
4265+ replaceFmt.SetReplacePair (" ${fileext}" , fileExt);
4266+ }
4267+ }
4268+ }
42224269 }
42234270
42244271 do
0 commit comments