add $$val_escape() function

this quotes the elements of a variable in a way suitable for re-parsing
as qmake code.

Change-Id: I0e6ea2478c43b5aeff45f485a48ac8c86705dd4a
Reviewed-by: Marius Storm-Olsen <marius.storm-olsen@nokia.com>
This commit is contained in:
Oswald Buddenhagen 2012-03-13 17:15:27 +01:00
parent ade089907b
commit 6a66fef520
2 changed files with 22 additions and 1 deletions

View File

@ -80,7 +80,7 @@ QT_BEGIN_NAMESPACE
enum ExpandFunc { E_MEMBER=1, E_FIRST, E_LAST, E_CAT, E_FROMFILE, E_EVAL, E_LIST,
E_SPRINTF, E_JOIN, E_SPLIT, E_BASENAME, E_DIRNAME, E_SECTION,
E_FIND, E_SYSTEM, E_UNIQUE, E_QUOTE, E_ESCAPE_EXPAND,
E_UPPER, E_LOWER, E_FILES, E_PROMPT, E_RE_ESCAPE, E_REPLACE,
E_UPPER, E_LOWER, E_FILES, E_PROMPT, E_RE_ESCAPE, E_VAL_ESCAPE, E_REPLACE,
E_SIZE, E_SORT_DEPENDS, E_RESOLVE_DEPENDS, E_ENUMERATE_VARS };
QHash<QString, ExpandFunc> qmake_expandFunctions()
{
@ -109,6 +109,7 @@ QHash<QString, ExpandFunc> qmake_expandFunctions()
qmake_expand_functions->insert("upper", E_UPPER);
qmake_expand_functions->insert("lower", E_LOWER);
qmake_expand_functions->insert("re_escape", E_RE_ESCAPE);
qmake_expand_functions->insert("val_escape", E_VAL_ESCAPE);
qmake_expand_functions->insert("files", E_FILES);
qmake_expand_functions->insert("prompt", E_PROMPT);
qmake_expand_functions->insert("replace", E_REPLACE);
@ -2361,6 +2362,17 @@ QMakeProject::doProjectExpand(QString func, QList<QStringList> args_list,
for(int i = 0; i < args.size(); ++i)
ret += QRegExp::escape(args[i]);
break; }
case E_VAL_ESCAPE:
if (args.count() != 1) {
fprintf(stderr, "%s:%d val_escape(var) requires one argument.\n",
parser.file.toLatin1().constData(), parser.line_no);
} else {
QStringList vals = values(args.at(0), place);
ret.reserve(vals.length());
foreach (const QString &str, vals)
ret += quoteValue(str);
}
break;
case E_UPPER:
case E_LOWER: {
for(int i = 0; i < args.size(); ++i) {

View File

@ -1,5 +1,9 @@
CONFIG = qt thread
defineTest(testReplace) {
!isEqual(1, $$2):message("FAILED: $$3: got $$1, expected $${2}.")
}
#count
!count( CONFIG, 2 ) {
message( "FAILED: count function: $$CONFIG" )
@ -103,3 +107,8 @@ equals(moo, $$mooout)|message("FAILED: write_file() wrote something wrong when a
pn = $$OUT_PWD/testpath/subdir
mkpath($$pn)|message("FAILED: mkpath() failed")
exists($$pn)|message("FAILED: mkpath() didn't create anything")
in = easy "less easy" sca$${LITERAL_HASH}ry crazy$$escape_expand(\\t\\r\\n) $$escape_expand(\\t)shit \'no\"way\\here
out = "easy \"less easy\" sca\$\${LITERAL_HASH}ry crazy\$\$escape_expand(\\\\t\\\\r\\\\n) \$\$escape_expand(\\\\t)shit \\\'no\\\"way\\\\here"
testReplace($$val_escape(in), $$out, "val_escape")