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:
hjk
2013-03-21 16:19:09 +01:00
parent e14bbccb04
commit 090638c241
2 changed files with 23 additions and 0 deletions

View File

@@ -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