summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-04-14 13:42:50 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-04-14 13:45:55 (GMT)
commit734238d64f292af9d3f68742c18b0ac96b78ac06 (patch)
tree8137fd572a13853a2c913c33048bbda58aeb6bce /Source
parentb54d80b29344d3544f4d51a4ae466fb3d8a5e0f0 (diff)
parentda99eca1e7956e42e88df1b52c322f9c571acddd (diff)
downloadCMake-734238d64f292af9d3f68742c18b0ac96b78ac06.zip
CMake-734238d64f292af9d3f68742c18b0ac96b78ac06.tar.gz
CMake-734238d64f292af9d3f68742c18b0ac96b78ac06.tar.bz2
Merge topic 'sort_list_natural_20563'
da99eca1e7 list: add NATURAL sorting on SORT sub-command Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !4602
Diffstat (limited to 'Source')
-rw-r--r--Source/cmListCommand.cxx23
1 files changed, 21 insertions, 2 deletions
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx
index 5200a16..860b4da 100644
--- a/Source/cmListCommand.cxx
+++ b/Source/cmListCommand.cxx
@@ -1051,6 +1051,7 @@ public:
UNINITIALIZED,
STRING,
FILE_BASENAME,
+ NATURAL,
};
enum class CaseSensitivity
{
@@ -1074,10 +1075,25 @@ protected:
: 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:
cmStringSorter(Compare compare, CaseSensitivity caseSensitivity,
Order desc = Order::ASCENDING)
: filters{ GetCompareFilter(compare), GetCaseFilter(caseSensitivity) }
+ , sortMethod(GetComparisonFunction(compare))
, descending(desc == Order::DESCENDING)
{
}
@@ -1099,15 +1115,16 @@ public:
std::string bf = ApplyFilter(b);
bool result;
if (descending) {
- result = bf < af;
+ result = sortMethod(bf, af);
} else {
- result = af < bf;
+ result = sortMethod(af, bf);
}
return result;
}
protected:
StringFilter filters[2] = { nullptr, nullptr };
+ ComparisonFunction sortMethod;
bool descending;
};
@@ -1142,6 +1159,8 @@ bool HandleSortCommand(std::vector<std::string> const& args,
sortCompare = cmStringSorter::Compare::STRING;
} else if (argument == "FILE_BASENAME") {
sortCompare = cmStringSorter::Compare::FILE_BASENAME;
+ } else if (argument == "NATURAL") {
+ sortCompare = cmStringSorter::Compare::NATURAL;
} else {
std::string error =
cmStrCat(messageHint, "value \"", argument, "\" for option \"",