add $$str_size() function

this is strlen(), but the name is matched to $$size(), just namespaced
to reflect that it operates on a string value rather than a list
variable.

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

Change-Id: I56c8b863da244e66bd283257a66b197aa73b0e57
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>
This commit is contained in:
Oswald Buddenhagen 2016-05-13 15:58:20 +02:00
parent d3cc25ef52
commit 22f3800cac
3 changed files with 31 additions and 2 deletions

View File

@ -3042,10 +3042,13 @@
See also \l{system_quote(arg)}{system_quote()}.
\target fn_size
\section2 size(variablename)
Returns the number of values of \c variablename.
See also \l{str_size()}.
\section2 sort_depends(variablename, prefix)
This is an internal function that you will typically not need.
@ -3059,6 +3062,13 @@
\snippet code/doc_src_qmake-manual.pro 168
\target str_size()
\section2 str_size(arg)
Returns the number of characters in the argument.
See also \l{fn_size}{size()}.
\section2 system(command[, mode])
You can use this variant of the \c system function to obtain stdout from the

View File

@ -80,8 +80,8 @@ QT_BEGIN_NAMESPACE
#define fL1S(s) QString::fromLatin1(s)
enum ExpandFunc {
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_INVALID = 0, E_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_UPPER, E_LOWER, E_TITLE, E_FILES, E_PROMPT, E_RE_ESCAPE, E_VAL_ESCAPE,
@ -110,6 +110,7 @@ void QMakeEvaluator::initFunctionStatics()
{ "last", E_LAST },
{ "take_last", E_TAKE_LAST },
{ "size", E_SIZE },
{ "str_size", E_STR_SIZE },
{ "cat", E_CAT },
{ "fromfile", E_FROMFILE },
{ "eval", E_EVAL },
@ -737,6 +738,12 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
else
ret.append(ProString(QString::number(values(map(args.at(0))).size())));
break;
case E_STR_SIZE:
if (args.count() != 1)
evalError(fL1S("str_size(str) requires one argument."));
else
ret.append(ProString(QString::number(args.at(0).size())));
break;
case E_CAT:
if (args.count() < 1 || args.count() > 2) {
evalError(fL1S("cat(file, singleline=true) requires one or two arguments."));

View File

@ -826,6 +826,18 @@ void tst_qmakelib::addReplaceFunctions(const QString &qindir)
<< "##:1: size(var) requires one argument."
<< true;
QTest::newRow("$$str_size()")
<< "VAR = $$str_size(one two three)"
<< "VAR = 13"
<< ""
<< true;
QTest::newRow("$$str_size(): bad number of arguments")
<< "VAR = $$str_size(1, 2)"
<< "VAR ="
<< "##:1: str_size(str) requires one argument."
<< true;
QTest::newRow("$$fromfile(): right var")
<< "VAR = $$fromfile(" + qindir + "/fromfile/infile.prx, DEFINES)"
<< "VAR = QT_DLL"