Utils: Add stringutils splitAtFirst

Change-Id: I221d6c6086f53ec5f94c1157ea533d862db38d52
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-03-12 20:26:25 +01:00
parent c7e94d80c7
commit 9f1afb0318
3 changed files with 57 additions and 0 deletions

View File

@@ -527,4 +527,23 @@ QTCREATOR_UTILS_EXPORT FilePath appendHelper(const FilePath &base, int n)
return base.stringAppended(QString::number(n));
}
QTCREATOR_UTILS_EXPORT QPair<QStringView, QStringView> splitAtFirst(const QStringView &stringView,
QChar ch)
{
int splitIdx = stringView.indexOf(ch);
if (splitIdx == -1)
return {stringView, {}};
QStringView left = stringView.mid(0, splitIdx);
QStringView right = stringView.mid(splitIdx + 1);
return {left, right};
}
QTCREATOR_UTILS_EXPORT QPair<QStringView, QStringView> splitAtFirst(const QString &string, QChar ch)
{
QStringView view = string;
return splitAtFirst(view, ch);
}
} // namespace Utils