Repository :
https://github.com/FarGroup/FarManager
On branch : master
Link :
https://github.com/FarGroup/FarManager/commit/50b9a7758cec4e2da68e6327db0596b662413b74
>---------------------------------------------------------------
commit 50b9a7758cec4e2da68e6327db0596b662413b74
Author: Alex Alabuzhev <
alab...@gmail.com>
Date: Sun Jan 11 14:05:57 2026 +0000
Refactoring
>---------------------------------------------------------------
50b9a7758cec4e2da68e6327db0596b662413b74
far/common.tests.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++++
far/common/chrono.hpp | 3 ++-
far/common/exception.hpp | 1 -
far/common/expected.hpp | 1 -
far/common/monitored.hpp | 10 ++--------
far/common/singleton.hpp | 2 ++
far/common/uuid.hpp | 16 ++++-----------
7 files changed, 61 insertions(+), 23 deletions(-)
diff --git a/far/common.tests.cpp b/far/common.tests.cpp
index 5258e9c41..56af3e2a6 100644
--- a/far/common.tests.cpp
+++ b/far/common.tests.cpp
@@ -468,13 +468,21 @@ TEST_CASE("bytes")
{
uint32_t Value = 0;
const auto BytesRef = edit_bytes(Value);
+
std::fill(BytesRef.begin(), BytesRef.end(), std::byte{0x42});
REQUIRE(Value == 0x42424242);
+
const auto View = view_bytes(Value);
REQUIRE(View == "\x42\x42\x42\x42"_bv);
+
bytes Copy(View);
REQUIRE(Copy == View);
+ uint32_t NewValue = 0;
+ REQUIRE(!deserialise(View.substr(0, sizeof(NewValue) - 1), NewValue));
+ REQUIRE(deserialise(View, NewValue));
+ REQUIRE(NewValue == Value);
+
const auto Str = "BANANA"sv;
const auto Bytes = view_bytes(Str);
REQUIRE(Bytes == "BANANA"_bv);
@@ -739,7 +747,10 @@ TEST_CASE("from_string")
REQUIRE_THROWS_MATCHES(from_string<int>({}), far_exception, InvalidArgumentMatcher);
REQUIRE_THROWS_MATCHES(from_string<int>(L" 42"sv), far_exception, InvalidArgumentMatcher);
REQUIRE_THROWS_MATCHES(from_string<int>(L" +42"sv), far_exception, InvalidArgumentMatcher);
+ REQUIRE_THROWS_MATCHES(from_string<int>(L"+42"sv), far_exception, InvalidArgumentMatcher);
REQUIRE_THROWS_MATCHES(from_string<double>(L"1"sv, {}, 3), far_exception, InvalidArgumentMatcher);
+ REQUIRE_THROWS_MATCHES(from_string<int>(L"-"sv), far_exception, InvalidArgumentMatcher);
+ REQUIRE_THROWS_MATCHES(from_string<int>(L"+"sv), far_exception, InvalidArgumentMatcher);
{
int Value;
@@ -940,6 +951,10 @@ TEST_CASE("lazy")
TEST_CASE("monitored")
{
+ monitored<int> def;
+ REQUIRE(def.value() == 0);
+ REQUIRE(!def.touched());
+
monitored a(42);
REQUIRE(!a.touched());
a = 33;
@@ -948,6 +963,24 @@ TEST_CASE("monitored")
a.forget();
REQUIRE(!a.touched());
REQUIRE(a == 33);
+
+ monitored b(a);
+ REQUIRE(b.value() == 33);
+ REQUIRE(!b.touched());
+
+ monitored c(10);
+ REQUIRE(!c.touched());
+ c = b;
+ REQUIRE(c.value() == 33);
+ REQUIRE(c.touched());
+
+ monitored d(monitored(std::make_unique<int>(100)));
+ REQUIRE(*d.value().get() == 100);
+ REQUIRE(!d.touched());
+
+ monitored f(123);
+ int Raw = f;
+ REQUIRE(Raw == 123);
}
//----------------------------------------------------------------------------
@@ -1429,6 +1462,10 @@ TEST_CASE("singleton")
class c: public singleton<c>
{
IMPLEMENTS_SINGLETON;
+
+ private:
+ c() = default;
+ ~c() = default;
};
const auto& Ref1 = c::instance();
@@ -1506,6 +1543,14 @@ TEST_CASE("smart_ptr.block_ptr")
#include "common/string_utils.hpp"
+TEST_CASE("string_utils.copy_string")
+{
+ const auto Str = L"Kiełbasa"sv;
+ std::vector<wchar_t> Buffer(Str.size() + 1);
+ const auto It = copy_string(Str, Buffer.begin());
+ REQUIRE(std::ranges::equal(Str, std::span{Buffer.begin(), It}));
+}
+
TEST_CASE("string_utils.trim")
{
static const struct
@@ -1599,6 +1644,8 @@ TEST_CASE("string_utils.quotes")
{ LR"("12" 345")"sv, L"12 345"sv, LR"("12" 345")"sv, LR"(""12" 345"")"sv, LR"("12 345")"sv, LR"("12" 345")"sv, },
};
+ string Buffer;
+
for (const auto& i: Tests)
{
REQUIRE(unquote(i.Src) == i.ResultUnquote);
@@ -1606,6 +1653,10 @@ TEST_CASE("string_utils.quotes")
REQUIRE(quote_unconditional(i.Src) == i.ResultQuoteUnconditional);
REQUIRE(quote_normalise(i.Src) == i.ResultQuoteNormalise);
REQUIRE(quote_space(i.Src) == i.ResultQuoteSpace);
+
+ Buffer.clear();
+ copy::unquote(i.Src, std::back_inserter(Buffer));
+ REQUIRE(Buffer == i.ResultUnquote);
}
}
diff --git a/far/common/chrono.hpp b/far/common/chrono.hpp
index b27d90fbe..492afd778 100644
--- a/far/common/chrono.hpp
+++ b/far/common/chrono.hpp
@@ -41,7 +41,8 @@ template<typename... tuple_types>
class split_duration: public std::tuple<tuple_types...>
{
public:
- constexpr explicit split_duration(auto Duration)
+ template<class Rep, class Period>
+ constexpr explicit split_duration(std::chrono::duration<Rep, Period> Duration)
{
(..., (set_and_chop<tuple_types>(Duration)));
}
diff --git a/far/common/exception.hpp b/far/common/exception.hpp
index f2d546b8d..1444c4d26 100644
--- a/far/common/exception.hpp
+++ b/far/common/exception.hpp
@@ -32,7 +32,6 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "preprocessor.hpp"
#include "source_location.hpp"
#include <stdexcept>
diff --git a/far/common/expected.hpp b/far/common/expected.hpp
index 282bdc360..b6b07a76b 100644
--- a/far/common/expected.hpp
+++ b/far/common/expected.hpp
@@ -35,7 +35,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "exception.hpp"
#include "preprocessor.hpp"
-#include <stdexcept>
#include <variant>
//----------------------------------------------------------------------------
diff --git a/far/common/monitored.hpp b/far/common/monitored.hpp
index 3ab314c24..208e0235e 100644
--- a/far/common/monitored.hpp
+++ b/far/common/monitored.hpp
@@ -34,7 +34,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "preprocessor.hpp"
-#include <iterator>
+#include <utility>
//----------------------------------------------------------------------------
@@ -42,7 +42,7 @@ template<class T>
class monitored
{
public:
- MOVABLE(monitored);
+ MOVE_CONSTRUCTIBLE(monitored);
monitored(): m_Value(), m_Touched() {}
explicit(false) monitored(const T& Value): m_Value(Value), m_Touched() {}
@@ -55,15 +55,9 @@ public:
auto& operator=(T&& Value) noexcept { m_Value = std::move(Value); m_Touched = true; return *this; }
- [[nodiscard]]
- auto& value() noexcept { return m_Value; }
-
[[nodiscard]]
const auto& value() const noexcept { return m_Value; }
- [[nodiscard]]
- explicit(false) operator T&() noexcept { return m_Value; }
-
[[nodiscard]]
explicit(false) operator const T&() const noexcept { return m_Value; }
diff --git a/far/common/singleton.hpp b/far/common/singleton.hpp
index 0110b2c69..26c7a7458 100644
--- a/far/common/singleton.hpp
+++ b/far/common/singleton.hpp
@@ -36,6 +36,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <concepts>
+#include <cassert>
+
//----------------------------------------------------------------------------
template<typename type>
diff --git a/far/common/uuid.hpp b/far/common/uuid.hpp
index 1a2a3f227..4d2c65bc6 100644
--- a/far/common/uuid.hpp
+++ b/far/common/uuid.hpp
@@ -35,7 +35,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "exception.hpp"
#include <optional>
-#include <stdexcept>
#include <string_view>
#include <rpc.h>
@@ -62,7 +61,6 @@ namespace uuid
if (L'A' <= c && c <= L'F')
return c - L'A' + 10;
- using namespace std::string_view_literals;
throw_exception("Invalid character"sv);
}
@@ -95,10 +93,7 @@ namespace uuid
constexpr auto& operator+=(std::random_access_iterator auto& Iterator, separator_t)
{
if (*Iterator != L'-')
- {
- using namespace std::string_view_literals;
throw_exception("Invalid character"sv);
- }
return ++Iterator;
}
@@ -126,10 +121,10 @@ namespace uuid
template<size_t Digit>
[[nodiscard]]
- constexpr char int_to_hex(unsigned Value)
+ constexpr wchar_t int_to_hex(unsigned Value)
{
const auto i = (Value & (0xFu << 4 * Digit)) >> 4 * Digit;
- return i < 10? i + '0' : i - 10 + 'A';
+ return i < 10? i + L'0' : i - 10 + L'A';
}
template<size_t... I>
@@ -153,10 +148,7 @@ namespace uuid
constexpr auto parse(std::basic_string_view<char_type> const Str)
{
if (!(Str.size() == uuid_length || (Str.size() == uuid_length + 2 && Str.front() == L'{' && Str.back() == L'}')))
- {
- using namespace std::string_view_literals;
throw_exception("Incorrect format"sv);
- }
return detail::parse(Str.data() + (Str.size() != uuid_length));
}
@@ -209,7 +201,7 @@ namespace uuid
std::wstring Result;
Result.reserve(detail::uuid_length);
- const auto put = [&](char const c)
+ const auto put = [&](wchar_t const c)
{
Result.push_back(c);
};
@@ -219,7 +211,7 @@ namespace uuid
detail::serialise(i, put);
};
- constexpr auto Separator = '-';
+ constexpr auto Separator = L'-';
serialise(Uuid.Data1);
put(Separator);