[FarGroup/FarManager] master: Minor refactoring (cb6784a42)

1 view
Skip to first unread message

farg...@farmanager.com

unread,
Oct 3, 2022, 6:30:46 PM10/3/22
to farco...@googlegroups.com
Repository : https://github.com/FarGroup/FarManager
On branch : master
Link : https://github.com/FarGroup/FarManager/commit/cb6784a4209c783c7d44132389b7f20fe839dfea

>---------------------------------------------------------------

commit cb6784a4209c783c7d44132389b7f20fe839dfea
Author: Alex Alabuzhev <alab...@gmail.com>
Date: Mon Oct 3 23:23:55 2022 +0100

Minor refactoring


>---------------------------------------------------------------

cb6784a4209c783c7d44132389b7f20fe839dfea
far/editor.cpp | 2 +-
far/help.cpp | 2 +-
far/strmix.cpp | 22 +++++++++++-----------
far/strmix.hpp | 7 +++++--
4 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/far/editor.cpp b/far/editor.cpp
index a5edb3960..1bc5f4472 100644
--- a/far/editor.cpp
+++ b/far/editor.cpp
@@ -3505,7 +3505,7 @@ bool Editor::Search(bool Next)
ReverseSearch,
Regexp,
PreserveStyle,
- &SearchLength,
+ SearchLength,
GetWordDiv()
))
{
diff --git a/far/help.cpp b/far/help.cpp
index 148a8ce27..d9ce4614c 100644
--- a/far/help.cpp
+++ b/far/help.cpp
@@ -2012,7 +2012,7 @@ void Help::Search(const os::fs::file& HelpFile,uintptr_t nCodePage)
LastSearchWholeWords,
false,
LastSearchRegexp,
- &SearchLength,
+ SearchLength,
Global->Opt->EdOpt.strWordDiv
))
{
diff --git a/far/strmix.cpp b/far/strmix.cpp
index 177c3e9d9..dba37553b 100644
--- a/far/strmix.cpp
+++ b/far/strmix.cpp
@@ -673,15 +673,13 @@ unsigned long long ConvertFileSizeString(string_view const FileSizeStr)
}
}

-namespace
-{
- string ReplaceBrackets(
+string ReplaceBrackets(
const string_view SearchStr,
const string_view ReplaceStr,
span<RegExpMatch const> Match,
const named_regex_match* NamedMatch,
int& CurPos,
- int* SearchLength)
+ int& SearchLength)
{
string result;
for (size_t i = 0, length = ReplaceStr.size(); i < length; ++i)
@@ -761,11 +759,13 @@ namespace
}
}

- *SearchLength = Match[0].end - Match[0].start;
+ SearchLength = Match[0].end - Match[0].start;
CurPos = Match[0].start;
return result;
}

+namespace
+{
bool CanContainWholeWord(string_view const Haystack, size_t const Offset, size_t const NeedleSize, string_view const WordDiv)
{
const auto BlankOrWordDiv = [&WordDiv](wchar_t Ch)
@@ -792,7 +792,7 @@ namespace
bool const Reverse,
string& ReplaceStr,
int& CurPos,
- int* SearchLength,
+ int& SearchLength,
string_view WordDiv)
{
if (!Reverse)
@@ -862,7 +862,7 @@ bool SearchString(
bool const WholeWords,
bool const Reverse,
bool const Regexp,
- int* const SearchLength,
+ int& SearchLength,
string_view WordDiv)
{
string Dummy;
@@ -899,15 +899,15 @@ bool SearchAndReplaceString(
bool const Reverse,
bool const Regexp,
bool const PreserveStyle,
- int* const SearchLength,
+ int& SearchLength,
string_view WordDiv)
{
- *SearchLength = 0;
+ SearchLength = 0;

if (WordDiv.empty())
WordDiv = Global->Opt->strWordDiv;

- if (!Regexp && PreserveStyle && PreserveStyleReplaceString(Haystack, Needle, ReplaceStr, CurPos, CaseFold, WholeWords, WordDiv, Reverse, *SearchLength))
+ if (!Regexp && PreserveStyle && PreserveStyleReplaceString(Haystack, Needle, ReplaceStr, CurPos, CaseFold, WholeWords, WordDiv, Reverse, SearchLength))
return true;

if (Needle.empty())
@@ -965,7 +965,7 @@ bool SearchAndReplaceString(
}

CurPos = static_cast<int>(AbsoluteOffset);
- *SearchLength = static_cast<int>(FoundSize);
+ SearchLength = static_cast<int>(FoundSize);

// В случае PreserveStyle: если не получилось сделать замену c помощью PreserveStyleReplaceString,
// то хотя бы сохранить регистр первой буквы.
diff --git a/far/strmix.hpp b/far/strmix.hpp
index 5e990111e..39277dd40 100644
--- a/far/strmix.hpp
+++ b/far/strmix.hpp
@@ -128,6 +128,9 @@ bool CheckFileSizeStringFormat(string_view FileSizeStr);
[[nodiscard]]
unsigned long long ConvertFileSizeString(string_view FileSizeStr);

+[[nodiscard]]
+string ReplaceBrackets(string_view SearchStr, string_view ReplaceStr, span<RegExpMatch const> Match, const named_regex_match* NamedMatch, int& CurPos, int& SearchLength);
+
[[nodiscard]]
string GroupDigits(unsigned long long Value);

@@ -196,7 +199,7 @@ bool SearchString(
bool WholeWords,
bool Reverse,
bool Regexp,
- int* SearchLength,
+ int& SearchLength,
string_view WordDiv
);

@@ -215,7 +218,7 @@ bool SearchAndReplaceString(
bool Reverse,
bool Regexp,
bool PreserveStyle,
- int* SearchLength,
+ int& SearchLength,
string_view WordDiv
);



Reply all
Reply to author
Forward
0 new messages