add $$sorted() function.

[ChangeLog][qmake] Added $$sorted() function.

Change-Id: Ic069d3ef7c0b7a260c714c76eecc71c41417d01f
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: Martin Smith <martin.smith@theqtcompany.com>
This commit is contained in:
Oswald Buddenhagen 2016-05-13 16:53:01 +02:00
parent e70330f99e
commit 50e22c7653
4 changed files with 32 additions and 1 deletions

View File

@ -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

View File

@ -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; }

View File

@ -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."));

View File

@ -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"