Skip to content

Commit 2a9b77c

Browse files
committed
simplify match length calculation according to sktoolslib update
1 parent 939fb0b commit 2a9b77c

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

src/SearchDlg.cpp

+9-20
Original file line numberDiff line numberDiff line change
@@ -3835,26 +3835,17 @@ bool CSearchDlg::MatchPath(LPCTSTR pathBuf) const
38353835
return bPattern;
38363836
}
38373837

3838-
static long columnFromPosition(const std::wstring& textContent, long pos, long* lenLineEncodingPre)
3838+
static long columnFromPosition(const std::wstring& textContent, long pos)
38393839
{
3840-
*lenLineEncodingPre = 0;
3841-
if (pos == 0)
3842-
{
3843-
return 1;
3844-
}
3845-
38463840
long i = pos;
38473841
while (i > 0 && textContent[i] != L'\n' && textContent[i] != L'\r')
38483842
{
38493843
--i;
38503844
}
3851-
if (i >= 2 && textContent[i] == L'\n' && textContent[i - 1] == L'\r')
3845+
if (pos == i)
38523846
{
3853-
*lenLineEncodingPre = 2;
3854-
}
3855-
else if (i > 0)
3856-
{
3857-
*lenLineEncodingPre = 1;
3847+
// first/empty line starting
3848+
return 1;
38583849
}
38593850
return pos - i;
38603851
}
@@ -3941,13 +3932,12 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
39413932
long posMatch = static_cast<long>(whatC[0].first - textFile.GetFileString().begin());
39423933
long lineStart = textFile.LineFromPosition(posMatch);
39433934
long lineEnd = textFile.LineFromPosition(static_cast<long>(whatC[0].second - textFile.GetFileString().begin()));
3944-
long lenLineEncodingPre = 0;
3945-
long colMatch = columnFromPosition(textFile.GetFileString(), posMatch, &lenLineEncodingPre);
3935+
long colMatch = columnFromPosition(textFile.GetFileString(), posMatch);
39463936
long lenMatch = static_cast<long>(whatC[0].length());
39473937
for (long l = lineStart; l <= lineEnd; ++l)
39483938
{
39493939
auto sLine = textFile.GetLineString(l);
3950-
long lenLineMatch = static_cast<long>(sLine.length()) - colMatch;
3940+
long lenLineMatch = static_cast<long>(sLine.length()) - colMatch + 1;
39513941
if (lenMatch < lenLineMatch)
39523942
{
39533943
lenLineMatch = lenMatch;
@@ -3968,7 +3958,7 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
39683958
if (lenMatch > lenLineMatch)
39693959
{
39703960
colMatch = 1;
3971-
lenMatch -= lenLineMatch + lenLineEncodingPre;
3961+
lenMatch -= lenLineMatch;
39723962
}
39733963
}
39743964
++sInfo.matchCount;
@@ -4002,8 +3992,7 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
40023992
long posMatch = static_cast<long>(whatC[0].first - textFile.GetFileString().begin());
40033993
long lineStart = textFile.LineFromPosition(posMatch);
40043994
long lineEnd = textFile.LineFromPosition(static_cast<long>(whatC[0].second - textFile.GetFileString().begin()));
4005-
long lenLineEncodingPre = 0;
4006-
long colMatch = columnFromPosition(textFile.GetFileString(), posMatch, &lenLineEncodingPre);
3995+
long colMatch = columnFromPosition(textFile.GetFileString(), posMatch);
40073996
long lenMatch = static_cast<long>(whatC[0].length());
40083997
if (m_bCaptureSearch)
40093998
{
@@ -4030,7 +4019,7 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
40304019
if (lenMatch > lenLineMatch)
40314020
{
40324021
colMatch = 1;
4033-
lenMatch -= lenLineMatch + lenLineEncodingPre;
4022+
lenMatch -= lenLineMatch;
40344023
}
40354024
}
40364025
}

0 commit comments

Comments
 (0)