@@ -3835,21 +3835,6 @@ bool CSearchDlg::MatchPath(LPCTSTR pathBuf) const
3835
3835
return bPattern;
3836
3836
}
3837
3837
3838
- static long columnFromPosition (const std::wstring& textContent, long pos)
3839
- {
3840
- long i = pos;
3841
- while (i > 0 && textContent[i] != L' \n ' && textContent[i] != L' \r ' )
3842
- {
3843
- --i;
3844
- }
3845
- if (pos == i)
3846
- {
3847
- // first/empty line starting
3848
- return 1 ;
3849
- }
3850
- return pos - i;
3851
- }
3852
-
3853
3838
void CSearchDlg::SearchFile (CSearchInfo sInfo , const std::wstring& searchRoot, bool bSearchAlways, bool bIncludeBinary, bool bUseRegex, bool bCaseSensitive, bool bDotMatchesNewline, const std::wstring& searchString, const std::wstring& searchStringUtf16Le, std::atomic_bool& bCancelled)
3854
3839
{
3855
3840
int nFound = 0 ;
@@ -3929,11 +3914,14 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
3929
3914
nFound++;
3930
3915
if (m_bNotSearch)
3931
3916
break ;
3932
- long posMatch = static_cast <long >(whatC[0 ].first - textFile.GetFileString ().begin ());
3933
- long lineStart = textFile.LineFromPosition (posMatch);
3934
- long lineEnd = textFile.LineFromPosition (static_cast <long >(whatC[0 ].second - textFile.GetFileString ().begin ()));
3935
- long colMatch = columnFromPosition (textFile.GetFileString (), posMatch);
3936
- long lenMatch = static_cast <long >(whatC[0 ].length ());
3917
+ long posMatchHead = static_cast <long >(whatC[0 ].first - textFile.GetFileString ().begin ());
3918
+ long posMatchTail = static_cast <long >(whatC[0 ].second - textFile.GetFileString ().begin ());
3919
+ if (whatC[0 ].first < whatC[0 ].second ) // m[0].second is not part of the match
3920
+ --posMatchTail;
3921
+ long lineStart = textFile.LineFromPosition (posMatchHead);
3922
+ long lineEnd = textFile.LineFromPosition (posMatchTail);
3923
+ long colMatch = textFile.ColumnFromPosition (posMatchHead, lineStart);
3924
+ long lenMatch = static_cast <long >(whatC[0 ].length ());
3937
3925
for (long l = lineStart; l <= lineEnd; ++l)
3938
3926
{
3939
3927
auto sLine = textFile.GetLineString (l);
@@ -3964,14 +3952,11 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
3964
3952
++sInfo .matchCount ;
3965
3953
}
3966
3954
// update search position:
3967
- if ( start == whatC[0 ].second )
3968
- {
3969
- if (start == end)
3970
- break ;
3955
+ start = whatC[0 ].second ;
3956
+ if (start == end)
3957
+ break ;
3958
+ if (start == whatC[ 0 ]. first ) // ^$
3971
3959
++start;
3972
- }
3973
- else
3974
- start = whatC[0 ].second ;
3975
3960
// update flags:
3976
3961
flags |= boost::match_prev_avail;
3977
3962
flags |= boost::match_not_bob;
@@ -3989,11 +3974,14 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
3989
3974
nFound++;
3990
3975
if (m_bNotSearch)
3991
3976
break ;
3992
- long posMatch = static_cast <long >(whatC[0 ].first - textFile.GetFileString ().begin ());
3993
- long lineStart = textFile.LineFromPosition (posMatch);
3994
- long lineEnd = textFile.LineFromPosition (static_cast <long >(whatC[0 ].second - textFile.GetFileString ().begin ()));
3995
- long colMatch = columnFromPosition (textFile.GetFileString (), posMatch);
3996
- long lenMatch = static_cast <long >(whatC[0 ].length ());
3977
+ long posMatchHead = static_cast <long >(whatC[0 ].first - textFile.GetFileString ().begin ());
3978
+ long posMatchTail = static_cast <long >(whatC[0 ].second - textFile.GetFileString ().begin ());
3979
+ if (whatC[0 ].first < whatC[0 ].second ) // m[0].second is not part of the match
3980
+ --posMatchTail;
3981
+ long lineStart = textFile.LineFromPosition (posMatchHead);
3982
+ long lineEnd = textFile.LineFromPosition (posMatchTail);
3983
+ long colMatch = textFile.ColumnFromPosition (posMatchHead, lineStart);
3984
+ long lenMatch = static_cast <long >(whatC[0 ].length ());
3997
3985
if (m_bCaptureSearch)
3998
3986
{
3999
3987
auto out = whatC.format (m_replaceString, flags);
@@ -4026,14 +4014,11 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
4026
4014
++sInfo .matchCount ;
4027
4015
}
4028
4016
// update search position:
4029
- if ( start == whatC[0 ].second )
4030
- {
4031
- if (start == end)
4032
- break ;
4017
+ start = whatC[0 ].second ;
4018
+ if (start == end)
4019
+ break ;
4020
+ if (start == whatC[ 0 ]. first ) // ^$
4033
4021
++start;
4034
- }
4035
- else
4036
- start = whatC[0 ].second ;
4037
4022
// update flags:
4038
4023
flags |= boost::match_prev_avail;
4039
4024
flags |= boost::match_not_bob;
@@ -4192,7 +4177,7 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
4192
4177
boost::spirit::classic::file_iterator<> fBeg = start;
4193
4178
boost::spirit::classic::file_iterator<> end = start.make_end ();
4194
4179
boost::match_results<boost::spirit::classic::file_iterator<>> whatC;
4195
- while (boost::regex_search (start, end, whatC, expression, flags) && !bCancelled )
4180
+ while (boost::regex_search (start, end, whatC, expression, flags))
4196
4181
{
4197
4182
nFound++;
4198
4183
if (m_bNotSearch)
@@ -4202,6 +4187,10 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
4202
4187
++sInfo .matchCount ;
4203
4188
// update search position:
4204
4189
start = whatC[0 ].second ;
4190
+ if (start == end)
4191
+ break ;
4192
+ if (start == whatC[0 ].first ) // ^$
4193
+ ++start;
4205
4194
// update flags:
4206
4195
flags |= boost::match_prev_avail;
4207
4196
flags |= boost::match_not_bob;
@@ -4227,6 +4216,10 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
4227
4216
++sInfo .matchCount ;
4228
4217
// update search position:
4229
4218
start = whatC[0 ].second ;
4219
+ if (start == end)
4220
+ break ;
4221
+ if (start == whatC[0 ].first ) // ^$
4222
+ ++start;
4230
4223
// update flags:
4231
4224
flags |= boost::match_prev_avail;
4232
4225
flags |= boost::match_not_bob;
0 commit comments