diff --git a/Source/.clang-tidy b/Source/.clang-tidy index d52431f37..3f23c2f2b 100644 --- a/Source/.clang-tidy +++ b/Source/.clang-tidy @@ -94,11 +94,11 @@ Checks: > readability-avoid-nested-conditional-operator, readability-avoid-return-with-void-value, # readability-avoid-unconditional-preprocessor-if, <-- sometimes is still usefull, can't blanketly disallow - # readability-braces-around-statements, - # readability-const-return-type, - # readability-container-contains, - # readability-container-data-pointer, - # readability-container-size-empty, + # readability-braces-around-statements, <-- maybe a good idea, but is a rather huge change to apply + readability-const-return-type, + readability-container-contains, + readability-container-data-pointer, + readability-container-size-empty, # readability-convert-member-functions-to-static, # readability-delete-null-pointer, # readability-duplicate-include, diff --git a/Source/Base/tests/LRUCache_Tests.cpp b/Source/Base/tests/LRUCache_Tests.cpp index 9f94361b6..e6cad1613 100644 --- a/Source/Base/tests/LRUCache_Tests.cpp +++ b/Source/Base/tests/LRUCache_Tests.cpp @@ -10,7 +10,7 @@ using nc::base::LRUCache; TEST_CASE(PREFIX "empty") { const LRUCache cache; - CHECK(cache.size() == 0); + CHECK(cache.size() == 0); // NOLINT CHECK(cache.max_size() == 32); CHECK(cache.empty() == true); } diff --git a/Source/Base/tests/StringsBulk_UT.cpp b/Source/Base/tests/StringsBulk_UT.cpp index 52cefd47c..b927524f9 100644 --- a/Source/Base/tests/StringsBulk_UT.cpp +++ b/Source/Base/tests/StringsBulk_UT.cpp @@ -10,11 +10,11 @@ using namespace std; TEST_CASE(PREFIX "empty") { const StringsBulk sb1; - CHECK(sb1.size() == 0); + CHECK(sb1.size() == 0); // NOLINT CHECK(sb1.empty() == true); const StringsBulk sb2 = StringsBulk::Builder{}.Build(); - CHECK(sb2.size() == 0); + CHECK(sb2.size() == 0); // NOLINT CHECK(sb2.empty() == true); } @@ -43,7 +43,7 @@ TEST_CASE(PREFIX "empty strings") std::string out; for( int i = 0; i < n; ++i ) out += sb[i]; - CHECK(out == ""); + CHECK(out == ""); // NOLINT } TEST_CASE(PREFIX "invalid at") diff --git a/Source/Base/tests/VariableContainer_UT.cpp b/Source/Base/tests/VariableContainer_UT.cpp index 1ba70fc2d..297022d04 100644 --- a/Source/Base/tests/VariableContainer_UT.cpp +++ b/Source/Base/tests/VariableContainer_UT.cpp @@ -14,8 +14,8 @@ TEST_CASE(PREFIX "Common storage") variable_container vc(variable_container<>::type::common); CHECK(vc.size() == 1); CHECK(vc.empty() == false); - CHECK(vc.at(0) == ""); // default-constructed - CHECK(vc[0] == ""); + CHECK(vc.at(0) == ""); // NOLINT default-constructed + CHECK(vc[0] == ""); // NOLINT vc.at(0) = "Meow"; CHECK(vc.at(0) == "Meow"); @@ -25,7 +25,7 @@ TEST_CASE(PREFIX "Common storage") TEST_CASE(PREFIX "Sparse storage") { variable_container vc(variable_container<>::type::sparse); - CHECK(vc.size() == 0); + CHECK(vc.size() == 0); // NOLINT CHECK(vc.empty() == true); vc.insert(5, "abra"); @@ -60,7 +60,7 @@ TEST_CASE(PREFIX "Dense storage") CHECK(vc.has(6)); CHECK(!vc.has(7)); - CHECK(vc.at(0) == ""); + CHECK(vc.at(0) == ""); // NOLINT variable_container vc2(vc); CHECK(vc2.at(5) == "abra!"); diff --git a/Source/Base/tests/algo_UT.cpp b/Source/Base/tests/algo_UT.cpp index 2c8836424..0ff01c0a9 100644 --- a/Source/Base/tests/algo_UT.cpp +++ b/Source/Base/tests/algo_UT.cpp @@ -9,10 +9,10 @@ using namespace nc::base; TEST_CASE(PREFIX "SplitByDelimiters") { using VS = std::vector; - CHECK(SplitByDelimiters("", "", true) == VS{}); - CHECK(SplitByDelimiters("", "", false) == VS{}); - CHECK(SplitByDelimiters("", ",", true) == VS{}); - CHECK(SplitByDelimiters("", ",", false) == VS{}); + CHECK(SplitByDelimiters("", "", true).empty()); + CHECK(SplitByDelimiters("", "", false).empty()); + CHECK(SplitByDelimiters("", ",", true).empty()); + CHECK(SplitByDelimiters("", ",", false).empty()); CHECK(SplitByDelimiters("1", "", true) == VS{"1"}); CHECK(SplitByDelimiters("1", "", false) == VS{"1"}); CHECK(SplitByDelimiters("12", "", true) == VS{"12"}); @@ -23,23 +23,23 @@ TEST_CASE(PREFIX "SplitByDelimiters") CHECK(SplitByDelimiters(",1,2,3,", ",", false) == VS{"", "1", "2", "3", ""}); CHECK(SplitByDelimiters(",,1,,2,,3,,", ",", true) == VS{"1", "2", "3"}); CHECK(SplitByDelimiters(",,1,,2,,3,,", ",", false) == VS{"", "", "1", "", "2", "", "3", "", ""}); - CHECK(SplitByDelimiters(",", ",", true) == VS{}); + CHECK(SplitByDelimiters(",", ",", true).empty()); CHECK(SplitByDelimiters(",", ",", false) == VS{"", ""}); - CHECK(SplitByDelimiters(",,", ",", true) == VS{}); + CHECK(SplitByDelimiters(",,", ",", true).empty()); CHECK(SplitByDelimiters(",,", ",", false) == VS{"", "", ""}); CHECK(SplitByDelimiters(",1.2,3,", ",.", true) == VS{"1", "2", "3"}); CHECK(SplitByDelimiters(",1.2,3,", ",.", false) == VS{"", "1", "2", "3", ""}); - CHECK(SplitByDelimiters(",,..", ",.", true) == VS{}); + CHECK(SplitByDelimiters(",,..", ",.", true).empty()); CHECK(SplitByDelimiters(",,..", ",.", false) == VS{"", "", "", "", ""}); } TEST_CASE(PREFIX "SplitByDelimiter") { using VS = std::vector; - CHECK(SplitByDelimiter("", '\0', true) == VS{}); - CHECK(SplitByDelimiter("", '\0', false) == VS{}); - CHECK(SplitByDelimiter("", ',', true) == VS{}); - CHECK(SplitByDelimiter("", ',', false) == VS{}); + CHECK(SplitByDelimiter("", '\0', true).empty()); + CHECK(SplitByDelimiter("", '\0', false).empty()); + CHECK(SplitByDelimiter("", ',', true).empty()); + CHECK(SplitByDelimiter("", ',', false).empty()); CHECK(SplitByDelimiter("1", '\0', true) == VS{"1"}); CHECK(SplitByDelimiter("1", '\0', false) == VS{"1"}); CHECK(SplitByDelimiter("12", '\0', true) == VS{"12"}); @@ -50,9 +50,9 @@ TEST_CASE(PREFIX "SplitByDelimiter") CHECK(SplitByDelimiter(",1,2,3,", ',', false) == VS{"", "1", "2", "3", ""}); CHECK(SplitByDelimiter(",,1,,2,,3,,", ',', true) == VS{"1", "2", "3"}); CHECK(SplitByDelimiter(",,1,,2,,3,,", ',', false) == VS{"", "", "1", "", "2", "", "3", "", ""}); - CHECK(SplitByDelimiter(",", ',', true) == VS{}); + CHECK(SplitByDelimiter(",", ',', true).empty()); CHECK(SplitByDelimiter(",", ',', false) == VS{"", ""}); - CHECK(SplitByDelimiter(",,", ',', true) == VS{}); + CHECK(SplitByDelimiter(",,", ',', true).empty()); CHECK(SplitByDelimiter(",,", ',', false) == VS{"", "", ""}); CHECK(SplitByDelimiter(",1.2,3,", '.', true) == VS{",1", "2,3,"}); CHECK(SplitByDelimiter(",1.2,3,", '.', false) == VS{",1", "2,3,"}); @@ -62,13 +62,13 @@ TEST_CASE(PREFIX "SplitByDelimiter") TEST_CASE(PREFIX "ReplaceAll(..., std::string_view, ...)") { - CHECK(ReplaceAll("", "", "") == ""); + CHECK(ReplaceAll("", "", "").empty()); CHECK(ReplaceAll("a", "", "") == "a"); CHECK(ReplaceAll("a", "", "b") == "a"); CHECK(ReplaceAll("a", "b", "c") == "a"); CHECK(ReplaceAll("a", "a", "b") == "b"); - CHECK(ReplaceAll("a", "a", "") == ""); - CHECK(ReplaceAll("aaaa", "a", "") == ""); + CHECK(ReplaceAll("a", "a", "").empty()); + CHECK(ReplaceAll("aaaa", "a", "").empty()); CHECK(ReplaceAll("aaaa", "a", "b") == "bbbb"); CHECK(ReplaceAll("aaaa", "aa", "b") == "bb"); CHECK(ReplaceAll("aaaaa", "aa", "b") == "bba"); diff --git a/Source/Base/tests/chained_strings_UT.cpp b/Source/Base/tests/chained_strings_UT.cpp index c0afd78bb..dad29ea05 100644 --- a/Source/Base/tests/chained_strings_UT.cpp +++ b/Source/Base/tests/chained_strings_UT.cpp @@ -13,7 +13,7 @@ TEST_CASE(PREFIX "basic") chained_strings strings; CHECK(strings.empty() == true); - CHECK(strings.size() == 0); + CHECK(strings.size() == 0); // NOLINT CHECK_THROWS(strings.front()); CHECK_THROWS(strings.back()); CHECK_THROWS(strings.push_back(nullptr, 0, nullptr)); @@ -45,7 +45,7 @@ TEST_CASE(PREFIX "basic") chained_strings empty; strings.swap(empty); CHECK(strings.empty() == true); - CHECK(strings.size() == 0); + CHECK(strings.size() == 0); // NOLINT } TEST_CASE(PREFIX "blocks") diff --git a/Source/Config/source/FileOverwritesStorage.cpp b/Source/Config/source/FileOverwritesStorage.cpp index 5d5b2fe84..2a34478c7 100644 --- a/Source/Config/source/FileOverwritesStorage.cpp +++ b/Source/Config/source/FileOverwritesStorage.cpp @@ -84,7 +84,7 @@ static std::optional Load(const std::string &_filepath) const auto length = in.tellg(); contents.resize(static_cast(length)); in.seekg(0, std::ios::beg); - in.read(&contents[0], length); + in.read(contents.data(), length); in.close(); return contents; } diff --git a/Source/Config/tests/ConfigImpl_UT.cpp b/Source/Config/tests/ConfigImpl_UT.cpp index 91d3a020f..7f19e1421 100644 --- a/Source/Config/tests/ConfigImpl_UT.cpp +++ b/Source/Config/tests/ConfigImpl_UT.cpp @@ -107,9 +107,9 @@ TEST_CASE("Config returns a valid string value or an empty string") const ConfigImpl config{json, MakeDummyStorage()}; CHECK(config.GetString("abra") == "abc"); - CHECK(config.GetString("cadabra") == ""); - CHECK(config.GetString("alakazam") == ""); - CHECK(config.GetString("foobar") == ""); + CHECK(config.GetString("cadabra").empty()); + CHECK(config.GetString("alakazam").empty()); + CHECK(config.GetString("foobar").empty()); } TEST_CASE("Config overwrites existing values with proper types and values") diff --git a/Source/NimbleCommander/NimbleCommander/Bootstrap/AppDelegate.mm b/Source/NimbleCommander/NimbleCommander/Bootstrap/AppDelegate.mm index 53e672513..33b777099 100644 --- a/Source/NimbleCommander/NimbleCommander/Bootstrap/AppDelegate.mm +++ b/Source/NimbleCommander/NimbleCommander/Bootstrap/AppDelegate.mm @@ -1002,7 +1002,7 @@ - (IBAction)onMainMenuShowLogs:(id)_sender in.seekg(0, std::ios::end); contents.resize(in.tellg()); in.seekg(0, std::ios::beg); - in.read(&contents[0], contents.size()); + in.read(contents.data(), contents.size()); in.close(); return contents; } diff --git a/Source/NimbleCommander/NimbleCommander/States/FilePanels/Actions/SpotlightSearch.mm b/Source/NimbleCommander/NimbleCommander/States/FilePanels/Actions/SpotlightSearch.mm index 19f630836..a954a736b 100644 --- a/Source/NimbleCommander/NimbleCommander/States/FilePanels/Actions/SpotlightSearch.mm +++ b/Source/NimbleCommander/NimbleCommander/States/FilePanels/Actions/SpotlightSearch.mm @@ -33,7 +33,7 @@ std::string result = _format; result = base::ReplaceAll(result, "#{query}", _input); - result = base::ReplaceAll(result, "#{query1}", words.size() > 0 ? words[0] : ""); + result = base::ReplaceAll(result, "#{query1}", !words.empty() ? words[0] : ""); result = base::ReplaceAll(result, "#{query2}", words.size() > 1 ? words[1] : ""); result = base::ReplaceAll(result, "#{query3}", words.size() > 2 ? words[2] : ""); result = base::ReplaceAll(result, "#{query4}", words.size() > 3 ? words[3] : ""); diff --git a/Source/NimbleCommander/NimbleCommander/States/FilePanels/ListingPromise.cpp b/Source/NimbleCommander/NimbleCommander/States/FilePanels/ListingPromise.cpp index 79a4ca357..89941d51c 100644 --- a/Source/NimbleCommander/NimbleCommander/States/FilePanels/ListingPromise.cpp +++ b/Source/NimbleCommander/NimbleCommander/States/FilePanels/ListingPromise.cpp @@ -154,7 +154,7 @@ size_t ListingPromise::NonUniformListing::EntriesCount() const noexcept size_t count = 0; for( auto &vfs : per_vfs ) for( auto &dir : vfs.entries ) { - assert(dir.size() != 0); + assert(!dir.empty()); count += dir.size() - 1; } return count; diff --git a/Source/NimbleCommander/NimbleCommander/States/FilePanels/PanelDataPersistency.cpp b/Source/NimbleCommander/NimbleCommander/States/FilePanels/PanelDataPersistency.cpp index 0ca4634d7..80aadd8fc 100644 --- a/Source/NimbleCommander/NimbleCommander/States/FilePanels/PanelDataPersistency.cpp +++ b/Source/NimbleCommander/NimbleCommander/States/FilePanels/PanelDataPersistency.cpp @@ -245,7 +245,7 @@ std::optional PanelDataPersistency::JSONToLocation(const jso else if( tag == vfs::XAttrHost::UniqueTag ) { if( !has_string(g_HostInfoJunctionKey) ) return std::nullopt; // invalid data - if( result.hosts.size() < 1 ) + if( result.hosts.empty() ) return std::nullopt; // invalid data result.hosts.emplace_back(XAttr{h[g_HostInfoJunctionKey].GetString()}); @@ -262,7 +262,7 @@ std::optional PanelDataPersistency::JSONToLocation(const jso else if( tag == vfs::ArchiveHost::UniqueTag ) { if( !has_string(g_HostInfoJunctionKey) ) return std::nullopt; // invalid data - if( result.hosts.size() < 1 ) + if( result.hosts.empty() ) return std::nullopt; // invalid data result.hosts.emplace_back(ArcLA{h[g_HostInfoJunctionKey].GetString()}); @@ -270,7 +270,7 @@ std::optional PanelDataPersistency::JSONToLocation(const jso else if( tag == vfs::ArchiveRawHost::UniqueTag ) { if( !has_string(g_HostInfoJunctionKey) ) return std::nullopt; // invalid data - if( result.hosts.size() < 1 ) + if( result.hosts.empty() ) return std::nullopt; // invalid data result.hosts.emplace_back(ArcLARaw{h[g_HostInfoJunctionKey].GetString()}); @@ -551,7 +551,7 @@ int PanelDataPersistency::CreateVFSFromLocation(const PersistentLocation &_state vfs.emplace_back(vfs::PSHost::GetSharedOrNew()); } else if( auto xattr = std::any_cast(&h) ) { - if( vfs.size() < 1 ) + if( vfs.empty() ) return VFSError::GenericError; // invalid data auto xattr_vfs = std::make_shared(xattr->junction.c_str(), vfs.back()); @@ -568,14 +568,14 @@ int PanelDataPersistency::CreateVFSFromLocation(const PersistentLocation &_state return VFSError::GenericError; // failed to find connection by uuid } else if( auto la = std::any_cast(&h) ) { - if( vfs.size() < 1 ) + if( vfs.empty() ) return VFSError::GenericError; // invalid data auto host = std::make_shared(la->junction.c_str(), vfs.back()); vfs.emplace_back(host); } else if( auto la_raw = std::any_cast(&h) ) { - if( vfs.size() < 1 ) + if( vfs.empty() ) return VFSError::GenericError; // invalid data auto host = std::make_shared(la_raw->junction.c_str(), vfs.back()); diff --git a/Source/NimbleCommander/NimbleCommander/States/FilePanels/PanelView.mm b/Source/NimbleCommander/NimbleCommander/States/FilePanels/PanelView.mm index 4c554aece..22a7878af 100644 --- a/Source/NimbleCommander/NimbleCommander/States/FilePanels/PanelView.mm +++ b/Source/NimbleCommander/NimbleCommander/States/FilePanels/PanelView.mm @@ -471,7 +471,7 @@ - (void)setCurpos:(int)_pos { dispatch_assert_main_queue(); - const auto clipped_pos = (m_Data->SortedDirectoryEntries().size() > 0 && _pos >= 0 && + const auto clipped_pos = (!m_Data->SortedDirectoryEntries().empty() && _pos >= 0 && _pos < static_cast(m_Data->SortedDirectoryEntries().size())) ? _pos : -1; @@ -830,7 +830,7 @@ - (void)panelChangedWithFocusedFilename:(const std::string &)_focused_filename l [self setCurpos:cur]; } - if( m_CursorPos < 0 && m_Data->SortedDirectoryEntries().size() > 0 ) { + if( m_CursorPos < 0 && !m_Data->SortedDirectoryEntries().empty() ) { [self setCurpos:0]; } diff --git a/Source/NimbleCommander/NimbleCommander/Tests/PanelBriefViewDynamicWidthLayoutEngine_UT.mm b/Source/NimbleCommander/NimbleCommander/Tests/PanelBriefViewDynamicWidthLayoutEngine_UT.mm index 0d4599b57..69f4e59c7 100644 --- a/Source/NimbleCommander/NimbleCommander/Tests/PanelBriefViewDynamicWidthLayoutEngine_UT.mm +++ b/Source/NimbleCommander/NimbleCommander/Tests/PanelBriefViewDynamicWidthLayoutEngine_UT.mm @@ -14,8 +14,8 @@ CHECK(engine.RowsNumber() == 0); CHECK(engine.ColumnsNumber() == 0); CHECK(NSEqualSizes(engine.ContentSize(), NSMakeSize(0.0, 0.0))); - CHECK(engine.ColumnsPositions().size() == 0); - CHECK(engine.ColumnsWidths().size() == 0); + CHECK(engine.ColumnsPositions().empty()); + CHECK(engine.ColumnsWidths().empty()); } TEST_CASE(PREFIX "rounds number of rows down") diff --git a/Source/NimbleCommander/NimbleCommander/Tests/PanelBriefViewFixedNumberLayoutEngine_UT.mm b/Source/NimbleCommander/NimbleCommander/Tests/PanelBriefViewFixedNumberLayoutEngine_UT.mm index d3ae1fd9b..de9604893 100644 --- a/Source/NimbleCommander/NimbleCommander/Tests/PanelBriefViewFixedNumberLayoutEngine_UT.mm +++ b/Source/NimbleCommander/NimbleCommander/Tests/PanelBriefViewFixedNumberLayoutEngine_UT.mm @@ -14,8 +14,8 @@ CHECK(engine.RowsNumber() == 0); CHECK(engine.ColumnsNumber() == 0); CHECK(NSEqualSizes(engine.ContentSize(), NSMakeSize(0.0, 0.0))); - CHECK(engine.ColumnsPositions().size() == 0); - CHECK(engine.ColumnsWidths().size() == 0); + CHECK(engine.ColumnsPositions().empty()); + CHECK(engine.ColumnsWidths().empty()); } TEST_CASE(PREFIX "rounds number of rows down") diff --git a/Source/NimbleCommander/NimbleCommander/Tests/PanelBriefViewFixedWidthLayoutEngine_UT.mm b/Source/NimbleCommander/NimbleCommander/Tests/PanelBriefViewFixedWidthLayoutEngine_UT.mm index b75ee37c1..6e97e70fd 100644 --- a/Source/NimbleCommander/NimbleCommander/Tests/PanelBriefViewFixedWidthLayoutEngine_UT.mm +++ b/Source/NimbleCommander/NimbleCommander/Tests/PanelBriefViewFixedWidthLayoutEngine_UT.mm @@ -14,8 +14,8 @@ CHECK(engine.RowsNumber() == 0); CHECK(engine.ColumnsNumber() == 0); CHECK(NSEqualSizes(engine.ContentSize(), NSMakeSize(0.0, 0.0))); - CHECK(engine.ColumnsPositions().size() == 0); - CHECK(engine.ColumnsWidths().size() == 0); + CHECK(engine.ColumnsPositions().empty()); + CHECK(engine.ColumnsWidths().empty()); } TEST_CASE(PREFIX "rounds number of rows down") diff --git a/Source/NimbleCommander/NimbleCommander/Tests/ThemesManager_UT.mm b/Source/NimbleCommander/NimbleCommander/Tests/ThemesManager_UT.mm index db70e103d..04e5083dd 100644 --- a/Source/NimbleCommander/NimbleCommander/Tests/ThemesManager_UT.mm +++ b/Source/NimbleCommander/NimbleCommander/Tests/ThemesManager_UT.mm @@ -328,7 +328,7 @@ CHECK(man.SuitableNameForNewTheme("1") == "1"); CHECK(man.SuitableNameForNewTheme(" 1") == " 1"); CHECK(man.SuitableNameForNewTheme("1 ") == "1 "); - CHECK(man.SuitableNameForNewTheme("") == ""); + CHECK(man.SuitableNameForNewTheme("").empty()); CHECK(man.SuitableNameForNewTheme(" ") == " "); } diff --git a/Source/Operations/tests/CopyingFindNonExistingItemPath_UT.cpp b/Source/Operations/tests/CopyingFindNonExistingItemPath_UT.cpp index 170008614..76c9418ba 100644 --- a/Source/Operations/tests/CopyingFindNonExistingItemPath_UT.cpp +++ b/Source/Operations/tests/CopyingFindNonExistingItemPath_UT.cpp @@ -103,5 +103,5 @@ TEST_CASE(PREFIX "returns empty string on cancellation") auto proposed_path = FindNonExistingItemPath(orig_path.native(), *TestEnv().vfs_native, cancel); - CHECK(proposed_path == ""); + CHECK(proposed_path.empty()); } diff --git a/Source/Operations/tests/DirectoryPathAutoCompetion_IT.mm b/Source/Operations/tests/DirectoryPathAutoCompetion_IT.mm index 796760b25..3e2618a7c 100644 --- a/Source/Operations/tests/DirectoryPathAutoCompetion_IT.mm +++ b/Source/Operations/tests/DirectoryPathAutoCompetion_IT.mm @@ -51,31 +51,31 @@ static bool MkFile(const std::string &_file_path) } { // starting with 'z' const auto completions = auto_completion.PossibleCompletions(dir + "z"); - CHECK(completions == std::vector{}); + CHECK(completions.empty()); } { // starting with 'adjagdjafgsdad' const auto completions = auto_completion.PossibleCompletions(dir + "adjagdjafgsdad"); - CHECK(completions == std::vector{}); + CHECK(completions.empty()); } { // starting with 'file' const auto completions = auto_completion.PossibleCompletions(dir + "file"); - CHECK(completions == std::vector{}); + CHECK(completions.empty()); } { // invalid dir const auto completions = auto_completion.PossibleCompletions(dir + "adasdadsa/"); - CHECK(completions == std::vector{}); + CHECK(completions.empty()); } { // invalid dir + invalid filename const auto completions = auto_completion.PossibleCompletions(dir + "adasdadsa/asdasdasd"); - CHECK(completions == std::vector{}); + CHECK(completions.empty()); } { // empty dir const auto completions = auto_completion.PossibleCompletions(""); - CHECK(completions == std::vector{}); + CHECK(completions.empty()); } { // some gibberish const auto completions = auto_completion.PossibleCompletions("sidfogsodyfgosdufg"); - CHECK(completions == std::vector{}); + CHECK(completions.empty()); } // completions diff --git a/Source/Panel/tests/ExternalTools_UT.mm b/Source/Panel/tests/ExternalTools_UT.mm index 887f38377..9705f7333 100644 --- a/Source/Panel/tests/ExternalTools_UT.mm +++ b/Source/Panel/tests/ExternalTools_UT.mm @@ -83,7 +83,7 @@ static void touch(const std::filesystem::path &p) const auto p = ExternalToolsParametersParser{}.Parse("%?").value(); REQUIRE(p.StepsAmount() == 1); REQUIRE(p.Steps()[0] == Step{Params::ActionType::EnterValue, 0}); - REQUIRE(p.GetEnterValue(0).name == ""); + REQUIRE(p.GetEnterValue(0).name.empty()); } { const auto p = ExternalToolsParametersParser{}.Parse("%\"hello\"?").value(); diff --git a/Source/Panel/tests/ItemVolatileData_UT.mm b/Source/Panel/tests/ItemVolatileData_UT.mm index ee4fdba63..64fdef6e8 100644 --- a/Source/Panel/tests/ItemVolatileData_UT.mm +++ b/Source/Panel/tests/ItemVolatileData_UT.mm @@ -13,7 +13,7 @@ TEST_CASE(PREFIX "empty constructor") { const QuickSearchHiglight hl; - CHECK(hl.size() == 0); + CHECK(hl.size() == 0); // NOLINT CHECK(hl.empty() == true); const auto r = hl.unpack(); CHECK(r.count == 0); @@ -24,7 +24,7 @@ SECTION("Empty") { const QuickSearchHiglight hl(std::span{}); - CHECK(hl.size() == 0); + CHECK(hl.size() == 0); // NOLINT CHECK(hl.empty() == true); const auto r = hl.unpack(); CHECK(r.count == 0); diff --git a/Source/Term/source/ExtendedCharRegistry.mm b/Source/Term/source/ExtendedCharRegistry.mm index ccbf155d6..b13b8d609 100644 --- a/Source/Term/source/ExtendedCharRegistry.mm +++ b/Source/Term/source/ExtendedCharRegistry.mm @@ -39,7 +39,7 @@ ExtendedCharRegistry::AppendResult ExtendedCharRegistry::Append(const std::u16string_view _input, char32_t _initial) { // No input - if( _input.data() == nullptr || _input.length() == 0 ) { + if( _input.data() == nullptr || _input.empty() ) { return {.newchar = _initial, .eaten = 0}; } diff --git a/Source/Term/source/Task.cpp b/Source/Term/source/Task.cpp index ea95b92af..391e1e67b 100644 --- a/Source/Term/source/Task.cpp +++ b/Source/Term/source/Task.cpp @@ -91,7 +91,7 @@ static std::string GetLocale() { // Keep a copy of the current locale setting for this process char *backupLocale = setlocale(LC_CTYPE, nullptr); - if( backupLocale != nullptr && std::string_view{backupLocale} != "" && std::string_view{backupLocale} != "C" ) { + if( backupLocale != nullptr && !std::string_view{backupLocale}.empty() && std::string_view{backupLocale} != "C" ) { return backupLocale; } diff --git a/Source/Term/tests/Parser2_UT.cpp b/Source/Term/tests/Parser2_UT.cpp index 95642250c..11eafa248 100644 --- a/Source/Term/tests/Parser2_UT.cpp +++ b/Source/Term/tests/Parser2_UT.cpp @@ -257,7 +257,7 @@ TEST_CASE(PREFIX "Handles control characters") { r = parser.Parse(to_bytes("\x1F")); } - CHECK(r.size() == 0); + CHECK(r.empty()); } SECTION("linefeed") { @@ -829,7 +829,7 @@ TEST_CASE(PREFIX "CSI J") { auto r = parser.Parse(to_bytes("\x1B" "[4J")); - REQUIRE(r.size() == 0); + REQUIRE(r.empty()); } CHECK(parser.GetEscState() == ParserImpl::EscState::Text); } @@ -874,7 +874,7 @@ TEST_CASE(PREFIX "CSI K") { auto r = parser.Parse(to_bytes("\x1B" "[3K")); - REQUIRE(r.size() == 0); + REQUIRE(r.empty()); } CHECK(parser.GetEscState() == ParserImpl::EscState::Text); } @@ -1225,13 +1225,13 @@ TEST_CASE(PREFIX "CSI g") { auto r = parser.Parse(to_bytes("\x1B" "[1g")); - CHECK(r.size() == 0); + CHECK(r.empty()); } SECTION("ESC [ 2 g") { auto r = parser.Parse(to_bytes("\x1B" "[2g")); - CHECK(r.size() == 0); + CHECK(r.empty()); } SECTION("ESC [ 3 g") { @@ -1873,13 +1873,13 @@ TEST_CASE(PREFIX "CSI n") { auto r = parser.Parse(to_bytes("\x1B" "[n")); - REQUIRE(r.size() == 0); + REQUIRE(r.empty()); } SECTION("ESC [ 0 n") { auto r = parser.Parse(to_bytes("\x1B" "[0n")); - REQUIRE(r.size() == 0); + REQUIRE(r.empty()); } CHECK(parser.GetEscState() == ParserImpl::EscState::Text); } @@ -2232,7 +2232,7 @@ TEST_CASE(PREFIX "Properly handles torn sequences") SECTION("ESC [ 34 P") { auto r1 = parser.Parse(to_bytes("\x1B")); - REQUIRE(r1.size() == 0); + REQUIRE(r1.empty()); auto r2 = parser.Parse(to_bytes("[34P")); REQUIRE(r2.size() == 1); CHECK(r2[0].type == Type::delete_characters); @@ -2241,7 +2241,7 @@ TEST_CASE(PREFIX "Properly handles torn sequences") SECTION("\xf0\x9f\x98\xb1") { // 😱 auto r1 = parser.Parse(to_bytes("\xf0\x9f")); - REQUIRE(r1.size() == 0); + REQUIRE(r1.empty()); auto r2 = parser.Parse(to_bytes("\x98\xb1\xf0\x9f\x98")); REQUIRE(r2.size() == 1); CHECK(r2[0].type == Type::text); diff --git a/Source/Term/tests/ScreenBuffer_UT.cpp b/Source/Term/tests/ScreenBuffer_UT.cpp index af91d0701..febf55f06 100644 --- a/Source/Term/tests/ScreenBuffer_UT.cpp +++ b/Source/Term/tests/ScreenBuffer_UT.cpp @@ -44,8 +44,8 @@ TEST_CASE(PREFIX "Init") auto l1 = buffer.LineFromNo(0); auto l2 = buffer.LineFromNo(1); REQUIRE(l1.data() == l1.data()); - REQUIRE(l1.size() == 0); - REQUIRE(l2.size() == 0); + REQUIRE(l1.empty()); + REQUIRE(l2.empty()); } } diff --git a/Source/Utility/source/NativeFSManagerImpl.mm b/Source/Utility/source/NativeFSManagerImpl.mm index 9ab9b32c0..b93bb930b 100644 --- a/Source/Utility/source/NativeFSManagerImpl.mm +++ b/Source/Utility/source/NativeFSManagerImpl.mm @@ -778,7 +778,7 @@ static DASessionRef DASessionForMainThread() in.seekg(0, std::ios::end); mapping.resize(in.tellg()); in.seekg(0, std::ios::beg); - in.read(&mapping[0], mapping.size()); + in.read(mapping.data(), mapping.size()); in.close(); FirmlinksMappingParser parser; diff --git a/Source/Utility/source/PathManip.cpp b/Source/Utility/source/PathManip.cpp index f3e408616..03ad79614 100644 --- a/Source/Utility/source/PathManip.cpp +++ b/Source/Utility/source/PathManip.cpp @@ -159,7 +159,7 @@ namespace nc::utility { bool PathManip::IsAbsolute(std::string_view _path) noexcept { - return _path.length() > 0 && _path.front() == '/'; + return !_path.empty() && _path.front() == '/'; } std::string_view PathManip::Filename(std::string_view _path) noexcept diff --git a/Source/Utility/source/SystemInformation.mm b/Source/Utility/source/SystemInformation.mm index 96305adb4..71bb1fd92 100644 --- a/Source/Utility/source/SystemInformation.mm +++ b/Source/Utility/source/SystemInformation.mm @@ -379,10 +379,10 @@ bool GetSystemOverview(SystemOverview &_overview) return; coded_model = hw_model; - if( auto name1 = ExtractReadableModelNameFromFrameworks(coded_model); name1 != "" ) { + if( auto name1 = ExtractReadableModelNameFromFrameworks(coded_model); !name1.empty() ) { human_model = name1; } - else if( auto name2 = ExtractReadableModelNameFromSystemProfiler(); name2 != "" ) { + else if( auto name2 = ExtractReadableModelNameFromSystemProfiler(); !name2.empty() ) { human_model = name2; } }); diff --git a/Source/Utility/tests/DiskUtility_UT.mm b/Source/Utility/tests/DiskUtility_UT.mm index b742d1029..a6c4f0994 100644 --- a/Source/Utility/tests/DiskUtility_UT.mm +++ b/Source/Utility/tests/DiskUtility_UT.mm @@ -127,7 +127,7 @@ const auto disk6_data = tree.FindVolumesInContainerWithRole("disk6", APFSTree::Role::Data); REQUIRE(disk6_data); - CHECK(disk6_data->size() == 0); + CHECK(disk6_data->empty()); } TEST_CASE(PREFIX "APFSTree can find volumes by role from a container name (10_15)") diff --git a/Source/Utility/tests/FirmlinksMappingParser_UT.cpp b/Source/Utility/tests/FirmlinksMappingParser_UT.cpp index 696294902..914587079 100644 --- a/Source/Utility/tests/FirmlinksMappingParser_UT.cpp +++ b/Source/Utility/tests/FirmlinksMappingParser_UT.cpp @@ -81,11 +81,11 @@ TEST_CASE(PREFIX "Works against system mapping") in.seekg(0, std::ios::end); mapping.resize(in.tellg()); in.seekg(0, std::ios::beg); - in.read(&mapping[0], mapping.size()); + in.read(mapping.data(), mapping.size()); in.close(); FirmlinksMappingParser parser; auto parsed = parser.Parse(mapping); - CHECK(parsed.size() > 0); + CHECK(!parsed.empty()); } diff --git a/Source/Utility/tests/Tags_UT.mm b/Source/Utility/tests/Tags_UT.mm index e82bec48e..dc43497b0 100644 --- a/Source/Utility/tests/Tags_UT.mm +++ b/Source/Utility/tests/Tags_UT.mm @@ -762,7 +762,7 @@ Tags::RemoveTagFromAllItems(label1); // Verify the change - CHECK(Tags::ReadTags(p1) == std::vector{}); + CHECK(Tags::ReadTags(p1).empty()); CHECK(Tags::ReadTags(p2) == std::vector{{&label2, color2}}); CHECK(Tags::ReadTags(p3) == std::vector{{&label2, color2}}); } diff --git a/Source/Utility/tests/TemporaryFileStorageImpl_UT.mm b/Source/Utility/tests/TemporaryFileStorageImpl_UT.mm index 1bb9e44a4..c879af152 100644 --- a/Source/Utility/tests/TemporaryFileStorageImpl_UT.mm +++ b/Source/Utility/tests/TemporaryFileStorageImpl_UT.mm @@ -288,7 +288,7 @@ static int RMRF(const std::string &_path) in.seekg(0, std::ios::end); contents.resize(in.tellg()); in.seekg(0, std::ios::beg); - in.read(&contents[0], contents.size()); + in.read(contents.data(), contents.size()); in.close(); return contents; } diff --git a/Source/VFS/source/Host.cpp b/Source/VFS/source/Host.cpp index 8159b159e..7204ac47b 100644 --- a/Source/VFS/source/Host.cpp +++ b/Source/VFS/source/Host.cpp @@ -578,8 +578,10 @@ std::string Host::MakePathVerbose(std::string_view _path) const } // make one and only one memory allocation - const size_t total_len = std::accumulate( - &strings[0], &strings[0] + strings_n, size_t(0), [](auto sum, auto string) { return sum + string.length(); }); + const size_t total_len = + std::accumulate(strings.data(), strings.data() + strings_n, size_t(0), [](auto sum, auto string) { + return sum + string.length(); + }); std::string verbose_path; verbose_path.reserve(total_len); for( size_t index = strings_n - 1; index < strings_n; --index ) diff --git a/Source/VFS/source/NetDropbox/Host.mm b/Source/VFS/source/NetDropbox/Host.mm index fb14fe08a..3ef353b8a 100644 --- a/Source/VFS/source/NetDropbox/Host.mm +++ b/Source/VFS/source/NetDropbox/Host.mm @@ -372,7 +372,7 @@ static VFSNetDropboxHostConfiguration Compose(const std::string &_account, listing_source.ctimes.reset(variable_container<>::type::sparse); listing_source.mtimes.reset(variable_container<>::type::sparse); int listing_index = 0; - if( !(_flags & VFSFlags::F_NoDotDot) && path != "" ) { + if( !(_flags & VFSFlags::F_NoDotDot) && !path.empty() ) { listing_source.filenames.emplace_back(".."); listing_source.unix_modes.emplace_back(DirectoryAccessMode); listing_source.unix_types.emplace_back(DT_DIR); diff --git a/Source/VFS/source/NetFTP/Host.cpp b/Source/VFS/source/NetFTP/Host.cpp index 3b6bb3eb3..9241ad2c9 100644 --- a/Source/VFS/source/NetFTP/Host.cpp +++ b/Source/VFS/source/NetFTP/Host.cpp @@ -662,9 +662,9 @@ void FTPHost::BasicOptsSetup(CURLInstance *_inst) _inst->EasySetOpt(CURLOPT_VERBOSE, g_CURLVerbose); _inst->EasySetOpt(CURLOPT_FTP_FILEMETHOD, g_CURLFTPMethod); - if( Config().user != "" ) + if( !Config().user.empty() ) _inst->EasySetOpt(CURLOPT_USERNAME, Config().user.c_str()); - if( Config().passwd != "" ) + if( !Config().passwd.empty() ) _inst->EasySetOpt(CURLOPT_PASSWORD, Config().passwd.c_str()); if( Config().port > 0 ) _inst->EasySetOpt(CURLOPT_PORT, Config().port); diff --git a/Source/VFS/source/NetWebDAV/WebDAVHost.cpp b/Source/VFS/source/NetWebDAV/WebDAVHost.cpp index 20404bd6d..8de204bcc 100644 --- a/Source/VFS/source/NetWebDAV/WebDAVHost.cpp +++ b/Source/VFS/source/NetWebDAV/WebDAVHost.cpp @@ -469,7 +469,7 @@ static VFSConfiguration ComposeConfiguration(const std::string &_serv_url, static bool IsValidInputPath(std::string_view _path) { - return _path.length() > 0 && _path[0] == '/'; + return !_path.empty() && _path[0] == '/'; } } // namespace nc::vfs diff --git a/Source/VFS/tests/SearchForFiles_IT.cpp b/Source/VFS/tests/SearchForFiles_IT.cpp index b442634de..09436943d 100644 --- a/Source/VFS/tests/SearchForFiles_IT.cpp +++ b/Source/VFS/tests/SearchForFiles_IT.cpp @@ -66,7 +66,7 @@ TEST_CASE(PREFIX "Test basic searching") { search.SetFilterName(FileMask("*.jpg")); do_search(Options::GoIntoSubDirs | Options::SearchForDirs | Options::SearchForFiles); - CHECK(filenames == set{}); + CHECK(filenames.empty()); } SECTION("search for all entries with mask='*filename*'") { @@ -176,7 +176,7 @@ TEST_CASE(PREFIX "Test content filter") filter.case_sensitive = true; search.SetFilterContent(filter); do_search(Options::GoIntoSubDirs | Options::SearchForFiles | Options::SearchForDirs); - CHECK(filenames == set{}); + CHECK(filenames.empty()); } SECTION("hello, not containing") { @@ -203,7 +203,7 @@ TEST_CASE(PREFIX "Test content filter") filter.whole_phrase = true; search.SetFilterContent(filter); do_search(Options::GoIntoSubDirs | Options::SearchForFiles | Options::SearchForDirs); - CHECK(filenames == set{}); + CHECK(filenames.empty()); } SECTION("мир, UTF8") { @@ -220,7 +220,7 @@ TEST_CASE(PREFIX "Test content filter") filter.encoding = nc::utility::Encoding::ENCODING_MACOS_ROMAN_WESTERN; search.SetFilterContent(filter); do_search(Options::GoIntoSubDirs | Options::SearchForFiles | Options::SearchForDirs); - CHECK(filenames == set{}); + CHECK(filenames.empty()); } } diff --git a/Source/VFS/tests/VFSArchive_IT.mm b/Source/VFS/tests/VFSArchive_IT.mm index 9196fddb7..1f4ee4a69 100644 --- a/Source/VFS/tests/VFSArchive_IT.mm +++ b/Source/VFS/tests/VFSArchive_IT.mm @@ -129,7 +129,7 @@ static int VFSCompareEntries(const std::filesystem::path &_file1_full_path, std::this_thread::sleep_for(std::chrono::milliseconds(5)); auto d = file->ReadFile(); REQUIRE(d); - REQUIRE(d->size() > 0); + REQUIRE(!d->empty()); REQUIRE(d->size() == local_st.size); }); diff --git a/Source/VFS/tests/VFSArchive_UT.cpp b/Source/VFS/tests/VFSArchive_UT.cpp index 6c0027861..da63d8742 100644 --- a/Source/VFS/tests/VFSArchive_UT.cpp +++ b/Source/VFS/tests/VFSArchive_UT.cpp @@ -283,7 +283,7 @@ TEST_CASE(PREFIX "Can unrar a file with japanese filenames") REQUIRE(file->Open(VFSFlags::OF_Read) == 0); auto bytes = file->ReadFile(); REQUIRE(bytes); - REQUIRE(bytes->size() == 0); + REQUIRE(bytes->empty()); REQUIRE(host->CreateFile(reinterpret_cast(u8"/表だよ/漢字長いファイル名long-filename-in-漢字.txt"), file, diff --git a/Source/VFS/tests/VFSPS_IT.cpp b/Source/VFS/tests/VFSPS_IT.cpp index d291e47ef..d39e7b66c 100644 --- a/Source/VFS/tests/VFSPS_IT.cpp +++ b/Source/VFS/tests/VFSPS_IT.cpp @@ -43,7 +43,7 @@ TEST_CASE(PREFIX "can read info about kernel_task") REQUIRE(file->Open(Flags::OF_Read) == 0); const auto file_contents = file->ReadFile(); REQUIRE(file_contents != std::nullopt); - REQUIRE(file_contents->size() != 0); + REQUIRE(!file_contents->empty()); const std::string_view proc_info(reinterpret_cast(file_contents->data()), file_contents->size()); CHECK(proc_info.find("Name: kernel_task") != std::string_view::npos); diff --git a/Source/VFSIcon/tests/IconRepositoryImpl_UnitTests.mm b/Source/VFSIcon/tests/IconRepositoryImpl_UnitTests.mm index 746de9a67..70fe11e5a 100644 --- a/Source/VFSIcon/tests/IconRepositoryImpl_UnitTests.mm +++ b/Source/VFSIcon/tests/IconRepositoryImpl_UnitTests.mm @@ -161,7 +161,7 @@ repository.Unregister(key); CHECK(repository.IsValidSlot(key) == false); - CHECK(repository.AllSlots().size() == 0); + CHECK(repository.AllSlots().empty()); } TEST_CASE("IconRepositoryImpl reuses unregistered keys") diff --git a/Source/Viewer/source/HexModeLayout.cpp b/Source/Viewer/source/HexModeLayout.cpp index a0f079cfd..3c53323b5 100644 --- a/Source/Viewer/source/HexModeLayout.cpp +++ b/Source/Viewer/source/HexModeLayout.cpp @@ -75,7 +75,7 @@ std::optional HexModeLayout::FindRowToScrollWithGlobalOffset(int64_t _globa if( _global_offset >= working_set_pos && _global_offset < working_set_pos + working_set_len ) { // seems that we can satisfy this request immediately, without I/O const auto local_offset = static_cast(_global_offset - working_set_pos); - const auto first_row = &m_Frame->Rows()[0]; + const auto first_row = m_Frame->Rows().data(); const auto last_row = first_row + number_of_rows; const int closest = HexModeFrame::FindFloorClosest(first_row, last_row, local_offset); if( closest + rows_in_view < number_of_rows ) { diff --git a/Source/Viewer/source/TextModeView.mm b/Source/Viewer/source/TextModeView.mm index 91e18e15b..930a845d6 100644 --- a/Source/Viewer/source/TextModeView.mm +++ b/Source/Viewer/source/TextModeView.mm @@ -1086,7 +1086,7 @@ static int64_t CalculateGlobalBytesOffsetFromScrollPosition(const TextModeFrame if( _global_offset >= working_set_pos && _global_offset < working_set_pos + working_set_len ) { // seems that we can satisfy this request immediately, without I/O const auto local_offset = static_cast(_global_offset - working_set_pos); - const auto first_line = &_frame.Lines()[0]; + const auto first_line = _frame.Lines().data(); const auto last_line = first_line + _frame.LinesNumber(); const int closest = FindFloorClosestLineIndex(first_line, last_line, local_offset); if( closest + lines_per_view < _frame.LinesNumber() ) { diff --git a/Source/Viewer/source/ViewerFooter.mm b/Source/Viewer/source/ViewerFooter.mm index 0eedaa398..912947a6a 100644 --- a/Source/Viewer/source/ViewerFooter.mm +++ b/Source/Viewer/source/ViewerFooter.mm @@ -381,7 +381,7 @@ - (void)setHighlightingLanguage:(const std::string &)_highlighting_language [self didChangeValueForKey:@"highlightingLanguage"]; long tag = -1; - if( m_HighlightingLanguage == "" ) { + if( m_HighlightingLanguage.empty() ) { tag = 0; } else if( auto it = std::ranges::find(m_Languages, m_HighlightingLanguage); it != m_Languages.end() ) {