forked from qt-creator/qt-creator
Utils: Add stringutils splitAtFirst
Change-Id: I221d6c6086f53ec5f94c1157ea533d862db38d52 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user