Commit 52374997 authored by Oswald Buddenhagen's avatar Oswald Buddenhagen

add $$take_first() and $$take_last() functions

while implementing stacks and queues was possible before with the help
of $$member(), these functions make it much more straight-forward.

[ChangeLog][qmake] Added $$take_first() and $$take_last() functions.

Change-Id: I4922a5331780e468a42c663c9ad3c6456a95a6bf
Reviewed-by: Riitta-Leena Miettinen's avatarLeena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Joerg Bornemann's avatarJoerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: default avatarLars Knoll <lars.knoll@theqtcompany.com>
(cherry picked from qtbase/3d21634fb693634b7d41a152287d29afb80ac5e2)
Reviewed-by: Jake Petroules's avatarJake Petroules <jake.petroules@qt.io>
parent 1d8ae55a
......@@ -81,7 +81,8 @@ QT_BEGIN_NAMESPACE
#define fL1S(s) QString::fromLatin1(s)
enum ExpandFunc {
E_INVALID = 0, E_MEMBER, E_FIRST, E_LAST, E_SIZE, E_CAT, E_FROMFILE, E_EVAL, E_LIST,
E_INVALID = 0, E_MEMBER, E_FIRST, E_TAKE_FIRST, E_LAST, E_TAKE_LAST, E_SIZE,
E_CAT, E_FROMFILE, E_EVAL, E_LIST,
E_SPRINTF, E_FORMAT_NUMBER, E_JOIN, E_SPLIT, E_BASENAME, E_DIRNAME, E_SECTION,
E_FIND, E_SYSTEM, E_UNIQUE, E_REVERSE, E_QUOTE, E_ESCAPE_EXPAND,
E_UPPER, E_LOWER, E_TITLE, E_FILES, E_PROMPT, E_RE_ESCAPE, E_VAL_ESCAPE,
......@@ -106,7 +107,9 @@ void QMakeEvaluator::initFunctionStatics()
} expandInits[] = {
{ "member", E_MEMBER },
{ "first", E_FIRST },
{ "take_first", E_TAKE_FIRST },
{ "last", E_LAST },
{ "take_last", E_TAKE_LAST },
{ "size", E_SIZE },
{ "cat", E_CAT },
{ "fromfile", E_FROMFILE },
......@@ -697,6 +700,20 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
}
}
break;
case E_TAKE_FIRST:
case E_TAKE_LAST:
if (args.count() != 1) {
evalError(fL1S("%1(var) requires one argument.").arg(func.toQString(m_tmp1)));
} else {
ProStringList &var = valuesRef(map(args.at(0)));
if (!var.isEmpty()) {
if (func_t == E_TAKE_FIRST)
ret.append(var.takeFirst());
else
ret.append(var.takeLast());
}
}
break;
case E_SIZE:
if (args.count() != 1)
evalError(fL1S("size(var) requires one argument."));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment