From 2e46f9bbefc27b8583e9146741cc7b502d713cfc Mon Sep 17 00:00:00 2001 From: wildfire Date: Mon, 25 Sep 2023 16:37:13 +0100 Subject: [PATCH] Extract path comparison function --- tools/knarc/Narc.cpp | 53 ++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/tools/knarc/Narc.cpp b/tools/knarc/Narc.cpp index 26486b9f1a..aa25ff1a24 100644 --- a/tools/knarc/Narc.cpp +++ b/tools/knarc/Narc.cpp @@ -105,6 +105,23 @@ std::vector read_knarcorder_file(fs::path file) return ordered_files; } +static bool lex_sort(fs::path a, fs::path b) { + string aStr = a.filename().string(); + string bStr = b.filename().string(); + + for (size_t i = 0; i < aStr.size(); ++i) { + aStr[i] = tolower(aStr[i]); + } + + for (size_t i = 0; i < bStr.size(); ++i) { + bStr[i] = tolower(bStr[i]); + } + // std::transform(aStr.begin(), aStr.end(), aStr.begin(), ::tolower); + // std::transform(bStr.begin(), bStr.end(), bStr.begin(), ::tolower); + + return aStr < bStr; +} + std::vector Narc::KnarcInputIterator(const std::vector& paths, bool recursive, bool lexSort) const { std::vector ordered_files; @@ -156,23 +173,7 @@ std::vector Narc::KnarcInputIterator(const std::vector& path } if (lexSort) { - std::sort(unordered_files.begin(), unordered_files.end(), [](const fs::path& a, const fs::path& b) { - // I fucking hate C++ - string aStr = a.filename().string(); - string bStr = b.filename().string(); - - for (size_t i = 0; i < aStr.size(); ++i) { - aStr[i] = tolower(aStr[i]); - } - - for (size_t i = 0; i < bStr.size(); ++i) { - bStr[i] = tolower(bStr[i]); - } - // std::transform(aStr.begin(), aStr.end(), aStr.begin(), ::tolower); - // std::transform(bStr.begin(), bStr.end(), bStr.begin(), ::tolower); - - return aStr < bStr; - }); + std::sort(unordered_files.begin(), unordered_files.end(), lex_sort); } ordered_files.insert(ordered_files.end(), unordered_files.begin(), unordered_files.end()); @@ -194,23 +195,7 @@ vector Narc::InputIterator(const std::vector& paths, bool re } if (lexSort) { - std::sort(v.begin(), v.end(), [](const fs::path& a, const fs::path& b) { - // I fucking hate C++ - string aStr = a.filename().string(); - string bStr = b.filename().string(); - - for (size_t i = 0; i < aStr.size(); ++i) { - aStr[i] = tolower(aStr[i]); - } - - for (size_t i = 0; i < bStr.size(); ++i) { - bStr[i] = tolower(bStr[i]); - } - // std::transform(aStr.begin(), aStr.end(), aStr.begin(), ::tolower); - // std::transform(bStr.begin(), bStr.end(), bStr.begin(), ::tolower); - - return aStr < bStr; - }); + std::sort(v.begin(), v.end(), lex_sort); } if (recursive) {