Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify match length calculation according to sktoolslib update #455

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions src/SearchDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3835,26 +3835,17 @@ bool CSearchDlg::MatchPath(LPCTSTR pathBuf) const
return bPattern;
}

static long columnFromPosition(const std::wstring& textContent, long pos, long* lenLineEncodingPre)
static long columnFromPosition(const std::wstring& textContent, long pos)
{
*lenLineEncodingPre = 0;
if (pos == 0)
{
return 1;
}

long i = pos;
while (i > 0 && textContent[i] != L'\n' && textContent[i] != L'\r')
{
--i;
}
if (i >= 2 && textContent[i] == L'\n' && textContent[i - 1] == L'\r')
if (pos == i)
{
*lenLineEncodingPre = 2;
}
else if (i > 0)
{
*lenLineEncodingPre = 1;
// first/empty line starting
return 1;
}
return pos - i;
}
Expand Down Expand Up @@ -3941,13 +3932,12 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
long posMatch = static_cast<long>(whatC[0].first - textFile.GetFileString().begin());
long lineStart = textFile.LineFromPosition(posMatch);
long lineEnd = textFile.LineFromPosition(static_cast<long>(whatC[0].second - textFile.GetFileString().begin()));
long lenLineEncodingPre = 0;
long colMatch = columnFromPosition(textFile.GetFileString(), posMatch, &lenLineEncodingPre);
long colMatch = columnFromPosition(textFile.GetFileString(), posMatch);
long lenMatch = static_cast<long>(whatC[0].length());
for (long l = lineStart; l <= lineEnd; ++l)
{
auto sLine = textFile.GetLineString(l);
long lenLineMatch = static_cast<long>(sLine.length()) - colMatch;
long lenLineMatch = static_cast<long>(sLine.length()) - colMatch + 1;
if (lenMatch < lenLineMatch)
{
lenLineMatch = lenMatch;
Expand All @@ -3968,7 +3958,7 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
if (lenMatch > lenLineMatch)
{
colMatch = 1;
lenMatch -= lenLineMatch + lenLineEncodingPre;
lenMatch -= lenLineMatch;
}
}
++sInfo.matchCount;
Expand Down Expand Up @@ -4002,8 +3992,7 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
long posMatch = static_cast<long>(whatC[0].first - textFile.GetFileString().begin());
long lineStart = textFile.LineFromPosition(posMatch);
long lineEnd = textFile.LineFromPosition(static_cast<long>(whatC[0].second - textFile.GetFileString().begin()));
long lenLineEncodingPre = 0;
long colMatch = columnFromPosition(textFile.GetFileString(), posMatch, &lenLineEncodingPre);
long colMatch = columnFromPosition(textFile.GetFileString(), posMatch);
long lenMatch = static_cast<long>(whatC[0].length());
if (m_bCaptureSearch)
{
Expand All @@ -4030,7 +4019,7 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
if (lenMatch > lenLineMatch)
{
colMatch = 1;
lenMatch -= lenLineMatch + lenLineEncodingPre;
lenMatch -= lenLineMatch;
}
}
}
Expand Down
Loading