summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qmake/doc/src/qmake-manual.qdoc9
-rw-r--r--qmake/library/proitems.h1
-rw-r--r--qmake/library/qmakebuiltins.cpp11
-rw-r--r--tests/auto/tools/qmakelib/evaltest.cpp12
4 files changed, 32 insertions, 1 deletions
diff --git a/qmake/doc/src/qmake-manual.qdoc b/qmake/doc/src/qmake-manual.qdoc
index 5828d515e5..a173979117 100644
--- a/qmake/doc/src/qmake-manual.qdoc
+++ b/qmake/doc/src/qmake-manual.qdoc
@@ -2858,6 +2858,7 @@
See also \l{take_first()}, \l{fn_last}{last()}.
+ \target format_number()
\section2 format_number(number[, options...])
Returns \c number in the format specified by \c options. You can specify the
@@ -3074,6 +3075,14 @@
This is an internal function that you will typically not need.
+ \section2 sorted(variablename)
+
+ Returns the list of values in \c variablename with entries sorted
+ in ascending ASCII order.
+
+ Numerical sorting can be accomplished by zero-padding the values to
+ a fixed length with the help of the \l{format_number()} function.
+
\section2 split(variablename, separator)
Splits the value of \c variablename into separate values, and returns them
diff --git a/qmake/library/proitems.h b/qmake/library/proitems.h
index db5ad7c82b..16dd9386c8 100644
--- a/qmake/library/proitems.h
+++ b/qmake/library/proitems.h
@@ -100,6 +100,7 @@ public:
bool operator!=(const QString &other) const { return !(*this == other); }
bool operator!=(QLatin1String other) const { return !(*this == other); }
bool operator!=(const char *other) const { return !(*this == other); }
+ bool operator<(const ProString &other) const { return toQStringRef() < other.toQStringRef(); }
bool isNull() const { return m_string.isNull(); }
bool isEmpty() const { return !m_length; }
int length() const { return m_length; }
diff --git a/qmake/library/qmakebuiltins.cpp b/qmake/library/qmakebuiltins.cpp
index 6c8a079faf..6f93b655b4 100644
--- a/qmake/library/qmakebuiltins.cpp
+++ b/qmake/library/qmakebuiltins.cpp
@@ -83,7 +83,7 @@ enum ExpandFunc {
E_INVALID = 0, E_MEMBER, E_STR_MEMBER, E_FIRST, E_TAKE_FIRST, E_LAST, E_TAKE_LAST,
E_SIZE, E_STR_SIZE, E_CAT, E_FROMFILE, E_EVAL, E_LIST, E_SPRINTF, E_FORMAT_NUMBER,
E_NUM_ADD, E_JOIN, E_SPLIT, E_BASENAME, E_DIRNAME, E_SECTION,
- E_FIND, E_SYSTEM, E_UNIQUE, E_REVERSE, E_QUOTE, E_ESCAPE_EXPAND,
+ E_FIND, E_SYSTEM, E_UNIQUE, E_SORTED, E_REVERSE, E_QUOTE, E_ESCAPE_EXPAND,
E_UPPER, E_LOWER, E_TITLE, E_FILES, E_PROMPT, E_RE_ESCAPE, E_VAL_ESCAPE,
E_REPLACE, E_SORT_DEPENDS, E_RESOLVE_DEPENDS, E_ENUMERATE_VARS,
E_SHADOWED, E_ABSOLUTE_PATH, E_RELATIVE_PATH, E_CLEAN_PATH,
@@ -127,6 +127,7 @@ void QMakeEvaluator::initFunctionStatics()
{ "find", E_FIND },
{ "system", E_SYSTEM },
{ "unique", E_UNIQUE },
+ { "sorted", E_SORTED },
{ "reverse", E_REVERSE },
{ "quote", E_QUOTE },
{ "escape_expand", E_ESCAPE_EXPAND },
@@ -899,6 +900,14 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
ret.removeDuplicates();
}
break;
+ case E_SORTED:
+ if (args.count() != 1) {
+ evalError(fL1S("sorted(var) requires one argument."));
+ } else {
+ ret = values(map(args.at(0)));
+ std::sort(ret.begin(), ret.end());
+ }
+ break;
case E_REVERSE:
if (args.count() != 1) {
evalError(fL1S("reverse(var) requires one argument."));
diff --git a/tests/auto/tools/qmakelib/evaltest.cpp b/tests/auto/tools/qmakelib/evaltest.cpp
index 03fbf96a9f..4cefa906d3 100644
--- a/tests/auto/tools/qmakelib/evaltest.cpp
+++ b/tests/auto/tools/qmakelib/evaltest.cpp
@@ -1246,6 +1246,18 @@ void tst_qmakelib::addReplaceFunctions(const QString &qindir)
<< "##:1: unique(var) requires one argument."
<< true;
+ QTest::newRow("$$sorted()")
+ << "IN = one two three\nVAR = $$sorted(IN)"
+ << "VAR = one three two"
+ << ""
+ << true;
+
+ QTest::newRow("$$sorted(): bad number of arguments")
+ << "VAR = $$sorted(1, 2)"
+ << "VAR ="
+ << "##:1: sorted(var) requires one argument."
+ << true;
+
QTest::newRow("$$reverse()")
<< "IN = one two three\nVAR = $$reverse(IN)"
<< "VAR = three two one"