From 3d21634fb693634b7d41a152287d29afb80ac5e2 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 12 May 2016 20:38:54 +0200 Subject: 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: Leena Miettinen Reviewed-by: Joerg Bornemann Reviewed-by: Lars Knoll --- qmake/doc/src/qmake-manual.qdoc | 26 ++++++++++++++++++++++++-- qmake/library/qmakebuiltins.cpp | 19 ++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) (limited to 'qmake') diff --git a/qmake/doc/src/qmake-manual.qdoc b/qmake/doc/src/qmake-manual.qdoc index 5c6afcf191..c196cb841a 100644 --- a/qmake/doc/src/qmake-manual.qdoc +++ b/qmake/doc/src/qmake-manual.qdoc @@ -2847,6 +2847,7 @@ MY_VAR2 will contain '-Lone -Ltwo -Lthree -Lfour -Lfive', and MY_VAR3 will contain 'three two three'. + \target fn_first \section2 first(variablename) Returns the first value of \c variablename. @@ -2855,7 +2856,7 @@ \snippet code/doc_src_qmake-manual.pro 161 - See also \l{last(variablename)}{last()}. + See also \l{take_first()}, \l{fn_last}{last()}. \section2 format_number(number[, options...]) @@ -2903,6 +2904,7 @@ to empty strings. If you need to encode spaces in \c glue, \c before, or \c after, you must quote them. + \target fn_last \section2 last(variablename) Returns the last value of \c variablename. @@ -2911,7 +2913,7 @@ \snippet code/doc_src_qmake-manual.pro 162 - See also \l{first(variablename)}{first()}. + See also \l{take_last()}, \l{fn_first}{first()}. \section2 list(arg1 [, arg2 ..., argn]) @@ -3063,6 +3065,26 @@ See also \l{shell_quote(arg)}{shell_quote()}. + \target take_first() + \section2 take_first(variablename) + + Returns the first value of \c variablename and removes it from the + source variable. + + This provides convenience for implementing queues, for example. + + See also \l{take_last()}, \l{fn_first}{first()}. + + \target take_last() + \section2 take_last(variablename) + + Returns the last value of \c variablename and removes it from the + source variable. + + This provides convenience for implementing stacks, for example. + + See also \l{take_first()}, \l{fn_last}{last()}. + \target unique \section2 unique(variablename) diff --git a/qmake/library/qmakebuiltins.cpp b/qmake/library/qmakebuiltins.cpp index 12c272db7d..e919f1a77e 100644 --- a/qmake/library/qmakebuiltins.cpp +++ b/qmake/library/qmakebuiltins.cpp @@ -80,7 +80,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, @@ -105,7 +106,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 }, @@ -690,6 +693,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.")); -- cgit v1.2.3