Commit 090638c2 authored by hjk's avatar hjk
Browse files

Core: add a 'suffixAfter' function



Pure convenience for the decomposition of ids constructed wit suffix().
This will help centralizing repeated code in the qnx, blackberry, android
and cmake plugins.

Change-Id: Ibc9ca21f8da1d15578f4553da97212cc99a5c5b9
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent e14bbccb
......@@ -283,6 +283,12 @@ Id Id::withSuffix(const char *suffix) const
return Id(ba.constData());
}
/*!
\overload
\sa stringSuffix()
*/
Id Id::withSuffix(const QString &suffix) const
{
const QByteArray ba = name() + suffix.toUtf8();
......@@ -340,4 +346,20 @@ bool Id::alphabeticallyBefore(Id other) const
return toString().compare(other.toString(), Qt::CaseInsensitive) < 0;
}
/*!
Convenience function to extract a part of the id string
representation. This can be used to split off the base
part used when generating an id with \c{withSuffix()}.
\sa withSuffix()
*/
QString Id::suffixAfter(Id baseId) const
{
const QByteArray b = baseId.name();
const QByteArray n = name();
return n.startsWith(b) ? QString::fromUtf8(n.mid(b.size())) : QString();
}
} // namespace Core
......@@ -57,6 +57,7 @@ public:
QByteArray name() const;
QString toString() const; // Avoid.
QVariant toSetting() const; // Good to use.
QString suffixAfter(Id baseId) const;
bool isValid() const { return m_id; }
bool operator==(Id id) const { return m_id == id.m_id; }
bool operator==(const char *name) const;
......
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