MCPcopy Create free account
hub / github.com/KDE/kdevelop / replaceVariables

Function replaceVariables

plugins/customscript/customscript_plugin.cpp:43–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41
42// Replaces ${KEY} in command with variables[KEY]
43static QString replaceVariables(QString command, const QMap<QString, QString>& variables)
44{
45 while (command.contains(QLatin1String("${"))) {
46 int pos = command.indexOf(QLatin1String("${"));
47 int end = command.indexOf(QLatin1Char('}'), pos + 2);
48 if (end == -1) {
49 break;
50 }
51 QString key = command.mid(pos + 2, end - pos - 2);
52
53 const auto variableIt = variables.constFind(key);
54 if (variableIt != variables.constEnd()) {
55 command.replace(pos, 1 + end - pos, *variableIt );
56 } else {
57 qCDebug(CUSTOMSCRIPT) << "found no variable while replacing in shell-command" << command << "key" << key << "available:" << variables;
58 command.remove(pos, 1 + end - pos);
59 }
60 }
61 return command;
62}
63
64CustomScriptPlugin::CustomScriptPlugin(QObject* parent, const KPluginMetaData& metaData, const QVariantList&)
65 : IPlugin(QStringLiteral("kdevcustomscript"), parent, metaData)

Callers 1

formatSourceWithStyleMethod · 0.85

Calls 7

midMethod · 0.80
constEndMethod · 0.80
containsMethod · 0.45
indexOfMethod · 0.45
constFindMethod · 0.45
replaceMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected