Skip to content

Commit

Permalink
Extract path comparison function
Browse files Browse the repository at this point in the history
  • Loading branch information
wildfire248 committed Sep 25, 2023
1 parent cf2b083 commit 2e46f9b
Showing 1 changed file with 19 additions and 34 deletions.
53 changes: 19 additions & 34 deletions tools/knarc/Narc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ std::vector<fs::path> 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<fs::path> Narc::KnarcInputIterator(const std::vector<fs::path>& paths, bool recursive, bool lexSort) const
{
std::vector<fs::path> ordered_files;
Expand Down Expand Up @@ -156,23 +173,7 @@ std::vector<fs::path> Narc::KnarcInputIterator(const std::vector<fs::path>& 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());

Expand All @@ -194,23 +195,7 @@ vector<fs::path> Narc::InputIterator(const std::vector<fs::path>& 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) {
Expand Down

0 comments on commit 2e46f9b

Please sign in to comment.