From 6a66fef520d0fb2b8d507c3e91e03338fc39a57e Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 13 Mar 2012 17:15:27 +0100 Subject: [PATCH] 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 --- qmake/project.cpp | 14 +++++++++++++- tests/auto/tools/qmake/testdata/functions/functions.pro | 9 +++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/qmake/project.cpp b/qmake/project.cpp index 85ba72a..1df4bf0 100644 --- a/qmake/project.cpp +++ b/qmake/project.cpp @@ -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 qmake_expandFunctions() { @@ -109,6 +109,7 @@ QHash 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 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) { diff --git a/tests/auto/tools/qmake/testdata/functions/functions.pro b/tests/auto/tools/qmake/testdata/functions/functions.pro index 219e683..7792859 100644 --- a/tests/auto/tools/qmake/testdata/functions/functions.pro +++ b/tests/auto/tools/qmake/testdata/functions/functions.pro @@ -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") + -- 2.7.4