diff options
author | hjk <[email protected]> | 2013-03-21 16:19:09 +0100 |
---|---|---|
committer | hjk <[email protected]> | 2013-03-22 08:33:47 +0100 |
commit | 090638c241af0a83a40cef7a812fc10f49305556 (patch) | |
tree | af38131443f9ca98b0f0101e6b732d675990047d /src/plugins | |
parent | e14bbccb043a07b2738fb047999a7f3e3e1bad27 (diff) |
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 <[email protected]>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/coreplugin/id.cpp | 22 | ||||
-rw-r--r-- | src/plugins/coreplugin/id.h | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/plugins/coreplugin/id.cpp b/src/plugins/coreplugin/id.cpp index 7a0e742b7de..a6161ddc444 100644 --- a/src/plugins/coreplugin/id.cpp +++ b/src/plugins/coreplugin/id.cpp @@ -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 diff --git a/src/plugins/coreplugin/id.h b/src/plugins/coreplugin/id.h index 1f8ae83bc71..827ffd9c374 100644 --- a/src/plugins/coreplugin/id.h +++ b/src/plugins/coreplugin/id.h @@ -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; |