forked from qt-creator/qt-creator
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: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -283,6 +283,12 @@ Id Id::withSuffix(const char *suffix) const
|
|||||||
return Id(ba.constData());
|
return Id(ba.constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\overload
|
||||||
|
|
||||||
|
\sa stringSuffix()
|
||||||
|
*/
|
||||||
|
|
||||||
Id Id::withSuffix(const QString &suffix) const
|
Id Id::withSuffix(const QString &suffix) const
|
||||||
{
|
{
|
||||||
const QByteArray ba = name() + suffix.toUtf8();
|
const QByteArray ba = name() + suffix.toUtf8();
|
||||||
@@ -340,4 +346,20 @@ bool Id::alphabeticallyBefore(Id other) const
|
|||||||
return toString().compare(other.toString(), Qt::CaseInsensitive) < 0;
|
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
|
} // namespace Core
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ public:
|
|||||||
QByteArray name() const;
|
QByteArray name() const;
|
||||||
QString toString() const; // Avoid.
|
QString toString() const; // Avoid.
|
||||||
QVariant toSetting() const; // Good to use.
|
QVariant toSetting() const; // Good to use.
|
||||||
|
QString suffixAfter(Id baseId) const;
|
||||||
bool isValid() const { return m_id; }
|
bool isValid() const { return m_id; }
|
||||||
bool operator==(Id id) const { return m_id == id.m_id; }
|
bool operator==(Id id) const { return m_id == id.m_id; }
|
||||||
bool operator==(const char *name) const;
|
bool operator==(const char *name) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user