[FarGroup/FarManager] master: Refactoring (e02f8610f)

0 views
Skip to first unread message

farg...@farmanager.com

unread,
Apr 7, 2026, 2:16:01 PM (9 days ago) Apr 7
to farco...@googlegroups.com
Repository : https://github.com/FarGroup/FarManager
On branch : master
Link : https://github.com/FarGroup/FarManager/commit/e02f8610f79ac91b6cf9e94e314531e9f9edce0d

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

commit e02f8610f79ac91b6cf9e94e314531e9f9edce0d
Author: Alex Alabuzhev <alab...@gmail.com>
Date: Tue Apr 7 19:00:03 2026 +0100

Refactoring


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

e02f8610f79ac91b6cf9e94e314531e9f9edce0d
far/FarDlgBuilder.cpp | 2 +-
far/PluginA.cpp | 8 ++++----
far/RegExp.cpp | 2 +-
far/platform.chrono.cpp | 48 +++++++++++++++++++++++++++++-------------------
far/platform.cpp | 8 ++++----
far/qview.cpp | 4 ++--
far/stddlg.cpp | 16 ++++++++--------
far/uchardet.cpp | 4 ++--
8 files changed, 51 insertions(+), 41 deletions(-)

diff --git a/far/FarDlgBuilder.cpp b/far/FarDlgBuilder.cpp
index 66a82701d..b06f62496 100644
--- a/far/FarDlgBuilder.cpp
+++ b/far/FarDlgBuilder.cpp
@@ -186,7 +186,7 @@ public:

auto data() const
{
- return far::format(L"{0:064b}", as_unsigned(m_IntValue->Get()));
+ return far::format(L"{0:064b}"sv, as_unsigned(m_IntValue->Get()));
}

void SaveValue(DialogItemEx const& Item, int const RadioGroupIndex) override
diff --git a/far/PluginA.cpp b/far/PluginA.cpp
index ae4734d05..83fe993d3 100644
--- a/far/PluginA.cpp
+++ b/far/PluginA.cpp
@@ -1776,8 +1776,8 @@ static char* WINAPI TruncStrA(char *Str, int MaxLength) noexcept
if (MaxLength > 3)
{
const auto MovePos = Str + Length - MaxLength + 3;
- std::copy_n(MovePos, strlen(MovePos) + 1, Str + 3);
- std::copy_n("...", 3, Str);
+ std::ranges::copy_n(MovePos, strlen(MovePos) + 1, Str + 3);
+ std::ranges::copy("..."sv, Str);
}

Str[MaxLength] = 0;
@@ -1813,8 +1813,8 @@ static char* WINAPI TruncPathStrA(char *Str, int MaxLength) noexcept
return TruncStrA(Str, MaxLength);

const auto lpInPos = Start + 3 + (nLength - MaxLength);
- std::copy_n(lpInPos, strlen(lpInPos) + 1, Start + 3);
- std::copy_n("...", 3, Start);
+ std::ranges::copy_n(lpInPos, strlen(lpInPos) + 1, Start + 3);
+ std::ranges::copy("..."sv, Start);
}
return Str;
});
diff --git a/far/RegExp.cpp b/far/RegExp.cpp
index 70e2d4c91..d4438db30 100644
--- a/far/RegExp.cpp
+++ b/far/RegExp.cpp
@@ -3757,7 +3757,7 @@ TEST_CASE("regex.list.special")
}
Tests[]
{
- { L"[]]", L"!"sv, L"]"sv, { { 0, 1 } } },
+ { L"[]]"sv, L"!"sv, L"]"sv, { { 0, 1 } } },
{ L"[^]]"sv, L"]"sv, L"!"sv, { { 0, 1 } } },
};

diff --git a/far/platform.chrono.cpp b/far/platform.chrono.cpp
index 0acfa3929..83e4e25a0 100644
--- a/far/platform.chrono.cpp
+++ b/far/platform.chrono.cpp
@@ -328,29 +328,35 @@ namespace os::chrono

TEST_CASE("chrono.timepoint_conversions")
{
- enum direction
+ enum direction: unsigned
{
- to_time = 0_bit,
- from_time = 1_bit,
- both = to_time | from_time,
+ to_utc = 0_bit,
+ from_utc = 1_bit,
+ to_local = 2_bit,
+ from_local = 3_bit,
+ utc = to_utc | from_utc,
+ local = to_local | from_local,
+ to = to_utc | to_local,
+ from = from_utc | from_local,
+ all = utc | local,
};

static constexpr struct
{
std::optional<os::chrono::time> Time;
std::optional<os::chrono::duration> TimeSinceEpoch;
- direction Direction = direction::both;
+ unsigned Direction = direction::all;
}
Tests[]
{
- { {{ 1600, 1, 1, 0, 0, 0, 0 }}, { } }, // Prehistoric
- { {{ 1601, 1, 1, 0, 0, 0, 0 }}, { 0_hns, } }, // Epoch
- { {{ 1601, 1, 1, 0, 0, 0, 1 }}, { 1_hns, } },
- { {{ 2026, 4, 6, 13, 47, 4, 1234567 }}, { 134199568241234567_hns }, },
- { {{ 30827, 12, 31, 23, 59, 59, 9990000 }}, { 0x7fff35f4f06c58f0_hns }, }, // Latest possible SYSTEMTIME
- { {{ 30828, 9, 14, 2, 48, 5, 4775807 }}, { 0x7fffffffffffffff_hns }, to_time }, // Latest possible FILETIME
- { {{ 30828, 9, 14, 2, 48, 5, 4775808 }}, { }, }, // Post-apocalyptic
- { {{ 65535, 13, 32, 25, 60, 60, 9999999 }}, { }, }, // Rubbish
+ { {{ 1600, 1, 1, 0, 0, 0, 0 }}, { }, }, // Prehistoric
+ { {{ 1601, 1, 1, 0, 0, 0, 0 }}, { 0_hns }, utc }, // Epoch. No localtime test because it might fail in the Western Hemisphere.
+ { {{ 1601, 1, 1, 0, 0, 0, 1 }}, { 1_hns }, utc }, // No localtime test because it might fail in the Western Hemisphere.
+ { {{ 2026, 4, 6, 13, 47, 4, 1234567 }}, { 134199568241234567_hns }, },
+ { {{ 30827, 12, 31, 23, 59, 59, 9990000 }}, { 0x7fff35f4f06c58f0_hns }, utc | to_local }, // Latest possible SYSTEMTIME. No localtime test because it might resolve to 30828 in the Eastern Hemisphere.
+ { {{ 30828, 9, 14, 2, 48, 5, 4775807 }}, { 0x7fffffffffffffff_hns }, to, }, // Latest possible FILETIME
+ { {{ 30828, 9, 14, 2, 48, 5, 4775808 }}, { }, }, // Post-apocalyptic
+ { {{ 65535, 13, 32, 25, 60, 60, 9999999 }}, { }, }, // Rubbish
};

for (const auto& i: Tests)
@@ -359,27 +365,31 @@ TEST_CASE("chrono.timepoint_conversions")
{
if (i.TimeSinceEpoch)
{
- if (i.Direction & direction::from_time)
+ if (i.Direction & direction::from_utc)
{
os::chrono::time_point UtcResult;
REQUIRE(os::chrono::utc_to_timepoint(os::chrono::utc_time{ *i.Time }, UtcResult));
REQUIRE(i.TimeSinceEpoch == UtcResult.time_since_epoch());
}

- if (i.Direction & direction::to_time)
+ if (i.Direction & direction::to_utc)
{
os::chrono::utc_time UtcTimeResult;
REQUIRE(os::chrono::timepoint_to_utc(os::chrono::time_point{ *i.TimeSinceEpoch }, UtcTimeResult));
REQUIRE(*i.Time == UtcTimeResult);
}

- if (i.Direction == direction::both)
+ if (i.Direction & direction::to_local)
{
os::chrono::local_time LocalTimeResult;
REQUIRE(os::chrono::timepoint_to_localtime(os::chrono::time_point{ *i.TimeSinceEpoch }, LocalTimeResult));
- os::chrono::time_point TimePoint;
- REQUIRE(os::chrono::localtime_to_timepoint(LocalTimeResult, TimePoint));
- REQUIRE(i.TimeSinceEpoch == TimePoint.time_since_epoch());
+
+ if (i.Direction & direction::from_local)
+ {
+ os::chrono::time_point TimePoint;
+ REQUIRE(os::chrono::localtime_to_timepoint(LocalTimeResult, TimePoint));
+ REQUIRE(i.TimeSinceEpoch == TimePoint.time_since_epoch());
+ }
}
}
else
diff --git a/far/platform.cpp b/far/platform.cpp
index 512e412fd..8cdb64122 100644
--- a/far/platform.cpp
+++ b/far/platform.cpp
@@ -828,7 +828,7 @@ static auto get_keyboard_layout_list_registry_base()
}
catch (std::exception const& e)
{
- LOGWARNING(L"{}", e);
+ LOGWARNING(L"{}"sv, e);
}
}

@@ -860,7 +860,7 @@ static auto keyboard_layout_list_hr(std::span<HKL const> const List)
{
for (const auto& Key: LayoutsKey->enum_keys())
{
- const auto LayoutIdStr = reg::key::local_machine.get_string(concat(LayoutsPath, L"\\", Key), L"Layout Id"sv);
+ const auto LayoutIdStr = reg::key::local_machine.get_string(concat(LayoutsPath, L'\\', Key), L"Layout Id"sv);
if (!LayoutIdStr)
continue;

@@ -895,7 +895,7 @@ static auto keyboard_layout_list_hr(std::span<HKL const> const List)
if (!get_locale_value(Locale, LOCALE_SLOCALIZEDDISPLAYNAME, LanguageName)) // < Windows 7
LanguageName = far::format(L"{:08X}"sv, Locale);

- const auto LayoutName = reg::key::local_machine.get_string(concat(LayoutsPath, L"\\", LayoutKey), L"Layout Text"sv);
+ const auto LayoutName = reg::key::local_machine.get_string(concat(LayoutsPath, L'\\', LayoutKey), L"Layout Text"sv);

far::format_to(Result, L"\n{:08X} {} / {}"sv, LayoutValue, LanguageName, LayoutName? *LayoutName : LayoutKey);
}
@@ -911,7 +911,7 @@ static std::vector<HKL> try_get_keyboard_list(function_ref<std::vector<HKL>()> C
}
catch (std::exception const& e)
{
- LOGWARNING(L"{}", e);
+ LOGWARNING(L"{}"sv, e);
return {};
}
}
diff --git a/far/qview.cpp b/far/qview.cpp
index 274f501eb..35b5c9cc1 100644
--- a/far/qview.cpp
+++ b/far/qview.cpp
@@ -150,7 +150,7 @@ void QuickView::DisplayObject()
SetColor(COL_PANELTEXT);
GotoXY(m_Where.left + 2, m_Where.top + 2);
const auto DisplayName = truncate_path(strCurFileName, std::max(0uz, m_Where.width() - 2 - msg(lng::MListFolder).size() - 5));
- PrintText(far::format(LR"({} "{}")", msg(lng::MListFolder), DisplayName));
+ PrintText(far::format(LR"({} "{}")"sv, msg(lng::MListFolder), DisplayName));

const auto currAttr = os::fs::get_file_attributes(strCurFileName); // обламывается, если нет доступа
if (currAttr != INVALID_FILE_ATTRIBUTES && (currAttr&FILE_ATTRIBUTE_REPARSE_POINT))
@@ -196,7 +196,7 @@ void QuickView::DisplayObject()
SetColor(COL_PANELTEXT);
GotoXY(m_Where.left + 2, m_Where.top + 3);
PrintText(KnownReparseTag?
- far::format(LR"({} "{}")", TypeName, Target) :
+ far::format(LR"({} "{}")"sv, TypeName, Target) :
msg(lng::MQuickViewUnknownReparsePoint)
);
}
diff --git a/far/stddlg.cpp b/far/stddlg.cpp
index 93056a9a7..3e1ff4b05 100644
--- a/far/stddlg.cpp
+++ b/far/stddlg.cpp
@@ -1176,18 +1176,18 @@ void regex_playground()

auto RegexDlgItems = MakeDialogItems<rp_count>(
{
- { DI_DOUBLEBOX, {{3, 1}, {72,15}}, DIF_NONE, L"Regular expressions", },
- { DI_TEXT, {{5, 2}, {0, 2}}, DIF_NONE, L"Regex:" },
+ { DI_DOUBLEBOX, {{3, 1}, {72,15}}, DIF_NONE, L"Regular expressions"sv, },
+ { DI_TEXT, {{5, 2}, {0, 2}}, DIF_NONE, L"Regex:"sv },
{ DI_EDIT, {{5, 3}, {45, 3}}, DIF_HISTORY, },
- { DI_TEXT, {{5, 4}, {45, 4}}, DIF_NONE, L"" },
- { DI_TEXT, {{5, 5}, {0, 5}}, DIF_NONE, L"Test string:" },
+ { DI_TEXT, {{5, 4}, {45, 4}}, DIF_NONE, L""sv },
+ { DI_TEXT, {{5, 5}, {0, 5}}, DIF_NONE, L"Test string:"sv },
{ DI_EDIT, {{5, 6}, {45, 6}}, DIF_HISTORY, },
- { DI_TEXT, {{5, 7}, {0, 7}}, DIF_NONE, L"Substitution:" },
+ { DI_TEXT, {{5, 7}, {0, 7}}, DIF_NONE, L"Substitution:"sv },
{ DI_EDIT, {{5, 8}, {45, 8}}, DIF_HISTORY, },
- { DI_TEXT, {{5, 9}, {0, 9}}, DIF_NONE, L"Result:" },
+ { DI_TEXT, {{5, 9}, {0, 9}}, DIF_NONE, L"Result:"sv },
{ DI_EDIT, {{5, 10}, {45,10}}, DIF_READONLY, },
- { DI_LISTBOX, {{47, 2}, {70,11}}, DIF_LISTNOCLOSE, L"Matches" },
- { DI_TEXT, {{5, 11}, {0, 11}}, DIF_NONE, L"Status:" },
+ { DI_LISTBOX, {{47, 2}, {70,11}}, DIF_LISTNOCLOSE, L"Matches"sv },
+ { DI_TEXT, {{5, 11}, {0, 11}}, DIF_NONE, L"Status:"sv },
{ DI_EDIT, {{5, 12}, {70,12}}, DIF_READONLY, },
{ DI_TEXT, {{-1,13}, {0, 13}}, DIF_SEPARATOR, },
{ DI_BUTTON, {{0, 14}, {0, 14}}, DIF_CENTERGROUP | DIF_DEFAULTBUTTON, msg(lng::MOk), },
diff --git a/far/uchardet.cpp b/far/uchardet.cpp
index 9703dc0d1..3f804cd42 100644
--- a/far/uchardet.cpp
+++ b/far/uchardet.cpp
@@ -235,9 +235,9 @@ static const auto& CpMap()

{ "TIS-620"sv, 874 },
{ "SHIFT_JIS"sv, 932 },
- { "UHC", 949 },
+ { "UHC"sv, 949 },
{ "BIG5"sv, 950 },
- { "Johab", 1361 },
+ { "Johab"sv, 1361 },
{ "KOI8-R"sv, 20866 },
{ "VISCII"sv, 28591 }, // No direct mapping, the closest one
{ "HZ-GB-2312"sv, 52936 },


Reply all
Reply to author
Forward
0 new messages