Commit fece99dd authored by Tobias Hunger's avatar Tobias Hunger
Browse files

SettingsAccessor: make FileAccessor::assignSuffix a static function



Also make sure the sanitization of the suffix happens for both
possible suffixes and not just for the first one.

Change-Id: I5d34582323ce147bdf4638e5ec3321227d329609
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent bc7b5796
......@@ -54,6 +54,19 @@
using namespace Utils;
namespace {
static QString generateSuffix(const QString &alt1, const QString &alt2)
{
QString suffix = alt1;
if (suffix.isEmpty())
suffix = alt2;
suffix.replace(QRegExp(QLatin1String("[^a-zA-Z0-9_.-]")), QString(QLatin1Char('_'))); // replace fishy characters:
if (!suffix.startsWith(QLatin1String(".")))
suffix.prepend(QLatin1Char('.'));
return suffix;
}
} // end namespace
namespace ProjectExplorer {
namespace Internal {
......@@ -877,7 +890,7 @@ SettingsAccessor::FileAccessor::FileAccessor(const QString &defaultSuffix,
, m_accessor(accessor)
, m_writer(0)
{
assignSuffix(defaultSuffix, environmentSuffix);
m_suffix = generateSuffix(environmentSuffix, defaultSuffix);
}
SettingsAccessor::FileAccessor::~FileAccessor()
......@@ -885,18 +898,6 @@ SettingsAccessor::FileAccessor::~FileAccessor()
delete m_writer;
}
void SettingsAccessor::FileAccessor::assignSuffix(const QString &defaultSuffix,
const QString &environmentSuffix)
{
if (!environmentSuffix.isEmpty()) {
m_suffix = environmentSuffix;
m_suffix.replace(QRegExp(QLatin1String("[^a-zA-Z0-9_.-]")), QString(QLatin1Char('_'))); // replace fishy characters:
m_suffix.prepend(QLatin1Char('.'));
} else {
m_suffix = defaultSuffix;
}
}
bool SettingsAccessor::FileAccessor::readFile(SettingsData *settings) const
{
if (settings->fileName().isEmpty()) {
......
......@@ -104,8 +104,6 @@ private:
QString suffix() const { return m_suffix; }
private:
void assignSuffix(const QString &defaultSuffix, const QString &environmentSuffix);
QString m_suffix;
bool m_environmentSpecific;
SettingsAccessor *m_accessor;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment