aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/namevalueitem.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2020-07-14 14:01:48 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2020-07-15 09:19:09 +0000
commitd2f478fc7b611d4376175507b495933300e5556e (patch)
treed00eaedbaaea7a3e90b006642ca60334b0023f5f /src/libs/utils/namevalueitem.cpp
parentf8636b85a86b8bc13046efdc3ec0f2bd35bd6c2e (diff)
Environment: Consider Append and Prepend operations
... when converting to and from string lists. Otherwise, such changes will be mis-stored/loaded as "Set" operations, resulting in unexpected environment values. Task-number: QTCREATORBUG-24105 Change-Id: I801f1e13028eef7575680a4da52e903adf07d3f8 Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/libs/utils/namevalueitem.cpp')
-rw-r--r--src/libs/utils/namevalueitem.cpp29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/libs/utils/namevalueitem.cpp b/src/libs/utils/namevalueitem.cpp
index 0ca80f8083..40a83ef4d8 100644
--- a/src/libs/utils/namevalueitem.cpp
+++ b/src/libs/utils/namevalueitem.cpp
@@ -41,7 +41,17 @@ NameValueItems NameValueItem::fromStringList(const QStringList &list)
{
NameValueItems result;
for (const QString &string : list) {
- int pos = string.indexOf('=', 1);
+ int pos = string.indexOf("+=");
+ if (pos != -1) {
+ result.append({string.left(pos), string.mid(pos + 2), NameValueItem::Append});
+ continue;
+ }
+ pos = string.indexOf("=+");
+ if (pos != -1) {
+ result.append({string.left(pos), string.mid(pos + 2), NameValueItem::Prepend});
+ continue;
+ }
+ pos = string.indexOf('=', 1);
if (pos == -1) {
result.append(NameValueItem(string, QString(), NameValueItem::Unset));
continue;
@@ -60,10 +70,19 @@ NameValueItems NameValueItem::fromStringList(const QStringList &list)
QStringList NameValueItem::toStringList(const NameValueItems &list)
{
return Utils::transform<QStringList>(list, [](const NameValueItem &item) {
- if (item.operation == NameValueItem::Unset)
- return QString(item.name);
- return QString((item.operation == NameValueItem::SetDisabled ? "#" : "")
- + item.name + '=' + item.value);
+ switch (item.operation) {
+ case NameValueItem::Unset:
+ return item.name;
+ case NameValueItem::Append:
+ return QString(item.name + "+=" + item.value);
+ case NameValueItem::Prepend:
+ return QString(item.name + "=+" + item.value);
+ case NameValueItem::SetDisabled:
+ return QString('#' + item.name + '=' + item.value);
+ case NameValueItem::SetEnabled:
+ return QString(item.name + '=' + item.value);
+ }
+ return QString();
});
}