diff options
author | Tobias Hunger <[email protected]> | 2015-09-14 10:56:10 +0200 |
---|---|---|
committer | Tobias Hunger <[email protected]> | 2015-09-22 09:16:48 +0000 |
commit | af7f098366ce0d039bbff24ad9560eca9e49ae02 (patch) | |
tree | 726b860c46514bbd7d49ad0fb323226853e7dc48 /src/plugins/cpptools/cppfilesettingspage.cpp | |
parent | 61e590a9716bcbb9621ed9f82452b3590a783c91 (diff) |
LicenseTemplate: Use macro expansion
Convert existing licensetemplate syntax to macro expansion. That
is way more powerful than what we used to have.
Do return the (converted) license template and do not try to fill
in information since that is not available when querying the
template.
Change-Id: Ia4f45ccf055772b21b0c2ce3c083cf49c45ae7d8
Reviewed-by: Orgad Shaneh <[email protected]>
Diffstat (limited to 'src/plugins/cpptools/cppfilesettingspage.cpp')
-rw-r--r-- | src/plugins/cpptools/cppfilesettingspage.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/plugins/cpptools/cppfilesettingspage.cpp b/src/plugins/cpptools/cppfilesettingspage.cpp index f0af6904cce..f6766dbd76d 100644 --- a/src/plugins/cpptools/cppfilesettingspage.cpp +++ b/src/plugins/cpptools/cppfilesettingspage.cpp @@ -145,28 +145,26 @@ bool CppFileSettings::equals(const CppFileSettings &rhs) const // Replacements of special license template keywords. static bool keyWordReplacement(const QString &keyWord, - const QString &file, - const QString &className, QString *value) { if (keyWord == QLatin1String("%YEAR%")) { - *value = QString::number(QDate::currentDate().year()); + *value = QLatin1String("%{CurrentDate:yyyy}"); return true; } if (keyWord == QLatin1String("%MONTH%")) { - *value = QString::number(QDate::currentDate().month()); + *value = QLatin1String("%{CurrentDate:M}"); return true; } if (keyWord == QLatin1String("%DAY%")) { - *value = QString::number(QDate::currentDate().day()); + *value = QLatin1String("%{CurrentDate:d}"); return true; } if (keyWord == QLatin1String("%CLASS%")) { - *value = className; + *value = QLatin1String("%{Cpp:License:ClassName}"); return true; } if (keyWord == QLatin1String("%FILENAME%")) { - *value = Utils::FileName::fromString(file).fileName(); + *value = QLatin1String("%{Cpp:License:FileName}"); return true; } if (keyWord == QLatin1String("%DATE%")) { @@ -179,17 +177,17 @@ static bool keyWordReplacement(const QString &keyWord, if (format.count(ypsilon) == 2) format.insert(format.indexOf(ypsilon), QString(2, ypsilon)); } - *value = QDate::currentDate().toString(format); + *value = QString::fromLatin1("%{CurrentDate:") + format + QLatin1Char('}'); return true; } if (keyWord == QLatin1String("%USER%")) { - *value = Utils::Environment::systemEnvironment().userName(); + *value = QLatin1String("%{Env:USER}"); return true; } // Environment variables (for example '%$EMAIL%'). if (keyWord.startsWith(QLatin1String("%$"))) { const QString varName = keyWord.mid(2, keyWord.size() - 3); - *value = QString::fromLocal8Bit(qgetenv(varName.toLocal8Bit())); + *value = QString::fromLatin1("%{Env:") + varName + QLatin1Char('}'); return true; } return false; @@ -197,10 +195,11 @@ static bool keyWordReplacement(const QString &keyWord, // Parse a license template, scan for %KEYWORD% and replace if known. // Replace '%%' by '%'. -static void parseLicenseTemplatePlaceholders(QString *t, const QString &file, const QString &className) +static void parseLicenseTemplatePlaceholders(QString *t) { int pos = 0; const QChar placeHolder = QLatin1Char('%'); + bool isCompatibilityStyle = false; do { const int placeHolderPos = t->indexOf(placeHolder, pos); if (placeHolderPos == -1) @@ -214,7 +213,8 @@ static void parseLicenseTemplatePlaceholders(QString *t, const QString &file, co } else { const QString keyWord = t->mid(placeHolderPos, endPlaceHolderPos + 1 - placeHolderPos); QString replacement; - if (keyWordReplacement(keyWord, file, className, &replacement)) { + if (keyWordReplacement(keyWord, &replacement)) { + isCompatibilityStyle = true; t->replace(placeHolderPos, keyWord.size(), replacement); pos = placeHolderPos + replacement.size(); } else { @@ -223,12 +223,14 @@ static void parseLicenseTemplatePlaceholders(QString *t, const QString &file, co } } } while (pos < t->size()); + + if (isCompatibilityStyle) + t->replace(QLatin1Char('\\'), QLatin1String("\\\\")); } // Convenience that returns the formatted license template. -QString CppFileSettings::licenseTemplate(const QString &fileName, const QString &className) +QString CppFileSettings::licenseTemplate() { - const QSettings *s = Core::ICore::settings(); QString key = QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP); key += QLatin1Char('/'); @@ -247,7 +249,7 @@ QString CppFileSettings::licenseTemplate(const QString &fileName, const QString licenseStream.setAutoDetectUnicode(true); QString license = licenseStream.readAll(); - parseLicenseTemplatePlaceholders(&license, fileName, className); + parseLicenseTemplatePlaceholders(&license); // Ensure at least one newline at the end of the license template to separate it from the code const QChar newLine = QLatin1Char('\n'); |