From 2af4ce11f7e148812fcd4d65a055e62b99124713 Mon Sep 17 00:00:00 2001 From: wildfire Date: Mon, 25 Sep 2023 16:53:32 +0100 Subject: [PATCH] Extract path comparison function --- tools/knarc/Narc.cpp | 64 ++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 38 deletions(-) diff --git a/tools/knarc/Narc.cpp b/tools/knarc/Narc.cpp index 26486b9f1a..85fe485295 100644 --- a/tools/knarc/Narc.cpp +++ b/tools/knarc/Narc.cpp @@ -105,6 +105,24 @@ 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 +174,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 +196,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) { @@ -298,10 +284,12 @@ bool Narc::Pack(const fs::path& outputPath, const std::vector& inputPa " * DO NOT MODIFY!!!\n" " */\n" "\n" - "#ifndef NARC_" << stem_upper << "_NAIX_\n" - "#define NARC_" << stem_upper << "_NAIX_\n" - "\n" - "enum {\n"; + "#ifndef NARC_" + << stem_upper << "_NAIX_\n" + "#define NARC_" + << stem_upper << "_NAIX_\n" + "\n" + "enum {\n"; } vector fatEntries; uint16_t directoryCounter = 1;