|
@@ -1051,6 +1051,7 @@ public:
|
|
|
UNINITIALIZED,
|
|
UNINITIALIZED,
|
|
|
STRING,
|
|
STRING,
|
|
|
FILE_BASENAME,
|
|
FILE_BASENAME,
|
|
|
|
|
+ NATURAL,
|
|
|
};
|
|
};
|
|
|
enum class CaseSensitivity
|
|
enum class CaseSensitivity
|
|
|
{
|
|
{
|
|
@@ -1074,10 +1075,25 @@ protected:
|
|
|
: nullptr;
|
|
: nullptr;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ using ComparisonFunction =
|
|
|
|
|
+ std::function<bool(const std::string&, const std::string&)>;
|
|
|
|
|
+ ComparisonFunction GetComparisonFunction(Compare compare)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (compare == Compare::NATURAL) {
|
|
|
|
|
+ return std::function<bool(const std::string&, const std::string&)>(
|
|
|
|
|
+ [](const std::string& x, const std::string& y) {
|
|
|
|
|
+ return cmSystemTools::strverscmp(x, y) < 0;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ return std::function<bool(const std::string&, const std::string&)>(
|
|
|
|
|
+ [](const std::string& x, const std::string& y) { return x < y; });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public:
|
|
public:
|
|
|
cmStringSorter(Compare compare, CaseSensitivity caseSensitivity,
|
|
cmStringSorter(Compare compare, CaseSensitivity caseSensitivity,
|
|
|
Order desc = Order::ASCENDING)
|
|
Order desc = Order::ASCENDING)
|
|
|
: filters{ GetCompareFilter(compare), GetCaseFilter(caseSensitivity) }
|
|
: filters{ GetCompareFilter(compare), GetCaseFilter(caseSensitivity) }
|
|
|
|
|
+ , sortMethod(GetComparisonFunction(compare))
|
|
|
, descending(desc == Order::DESCENDING)
|
|
, descending(desc == Order::DESCENDING)
|
|
|
{
|
|
{
|
|
|
}
|
|
}
|
|
@@ -1099,15 +1115,16 @@ public:
|
|
|
std::string bf = ApplyFilter(b);
|
|
std::string bf = ApplyFilter(b);
|
|
|
bool result;
|
|
bool result;
|
|
|
if (descending) {
|
|
if (descending) {
|
|
|
- result = bf < af;
|
|
|
|
|
|
|
+ result = sortMethod(bf, af);
|
|
|
} else {
|
|
} else {
|
|
|
- result = af < bf;
|
|
|
|
|
|
|
+ result = sortMethod(af, bf);
|
|
|
}
|
|
}
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
protected:
|
|
|
StringFilter filters[2] = { nullptr, nullptr };
|
|
StringFilter filters[2] = { nullptr, nullptr };
|
|
|
|
|
+ ComparisonFunction sortMethod;
|
|
|
bool descending;
|
|
bool descending;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -1142,6 +1159,8 @@ bool HandleSortCommand(std::vector<std::string> const& args,
|
|
|
sortCompare = cmStringSorter::Compare::STRING;
|
|
sortCompare = cmStringSorter::Compare::STRING;
|
|
|
} else if (argument == "FILE_BASENAME") {
|
|
} else if (argument == "FILE_BASENAME") {
|
|
|
sortCompare = cmStringSorter::Compare::FILE_BASENAME;
|
|
sortCompare = cmStringSorter::Compare::FILE_BASENAME;
|
|
|
|
|
+ } else if (argument == "NATURAL") {
|
|
|
|
|
+ sortCompare = cmStringSorter::Compare::NATURAL;
|
|
|
} else {
|
|
} else {
|
|
|
std::string error =
|
|
std::string error =
|
|
|
cmStrCat(messageHint, "value \"", argument, "\" for option \"",
|
|
cmStrCat(messageHint, "value \"", argument, "\" for option \"",
|