Frameworks/QStringView porting cheat sheet
According to this upstream Git repo, QStringRef will be moved to a qt5compat module in Qt6, which means KDE code needs to be ported away from it. The candidate replacement is QStringView. Since the latter's API is apparently still being modified upstream, not all methods are available in Qt 5.13 (which is the version that KDE Frameworks require at the time of writing this), this is a "cheat sheet" of sorts, listing all the QStringView methods that aren't available in Qt 5.13, or that have a different behaviour than the QString counterpart.
See the relevant discussion in https://phabricator.kde.org/T13913 (some of those methods introduced in Qt 5.15 as porting aid may be slow/ugly).
Method | Notes |
---|---|
QString arg(Args &&... args) const | Since Qt5.14 |
int compare(QLatin1String l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | Since Qt5.14 |
int compare(QChar ch) const | Since Qt5.14 |
int compare(QChar ch, Qt::CaseSensitivity cs) const | Since Qt5.14 |
bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | Since Qt5.14 |
bool contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | Since Qt5.14 |
bool contains(QLatin1String l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | Since Qt5.14 |
qsizetype count(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | Since Qt5.15.2 |
qsizetype count(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | Since Qt5.15.2 |
qsizetype indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | Since Qt5.14 |
qsizetype indexOf(QStringView str, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | Since Qt5.14 |
qsizetype indexOf(QLatin1String l1, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | Since Qt5.14 |
bool isValidUtf16() const | Since Qt5.15 |
qsizetype lastIndexOf(QChar c, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | Since Qt5.14 |
qsizetype lastIndexOf(QStringView str, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | Since Qt5.14 |
qsizetype lastIndexOf(QLatin1String l1, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | Since Qt5.14 |
QStringView left(qsizetype length) const | Until 5.15.1, the behavior was undefined when length < 0 or length > size(). Since 5.15.2, the behavior is compatible with QString::left(). |
QStringView mid(qsizetype start) const | Until 5.15.1, the behavior was undefined when start < 0 or start > size(). Since 5.15.2, the behavior is compatible with QString::mid(). |
QStringView mid(qsizetype start, qsizetype length) const | Until 5.15.1, the behavior was undefined when start < 0 or start > size(). Since 5.15.2, the behavior is compatible with QString::mid() |
QStringView right(qsizetype length) const | Until 5.15.1, the behavior was undefined when length < 0 or length > size(). Since 5.15.2, the behavior is compatible with QString::right() |
QList<QStringView> split(QStringView sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | Since Qt5.15.2 |
QList<QStringView> split(QChar sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | Since Qt5.15.2 |
QList<QStringView> split(const QRegularExpression &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const | Since Qt5.15.2 |
double toDouble(bool *ok = nullptr) const | Since Qt5.15.2 |
float toFloat(bool *ok = nullptr) const | Since Qt5.15.2 |
int toInt(bool *ok = nullptr, int base = 10) const | Since Qt5.15.2 |
long toLong(bool *ok = nullptr, int base = 10) const | Since Qt5.15.2 |
qlonglong toLongLong(bool *ok = nullptr, int base = 10) const | Since Qt5.15.2 |
short toShort(bool *ok = nullptr, int base = 10) const | Since Qt5.15.2 |
uint toUInt(bool *ok = nullptr, int base = 10) const | Since Qt5.15.2 |
ulong toULong(bool *ok = nullptr, int base = 10) const | Since Qt5.15.2 |
qulonglong toULongLong(bool *ok = nullptr, int base = 10) const | Since Qt5.15.2 |
ushort toUShort(bool *ok = nullptr, int base = 10) const | Since Qt5.15.2 |
int toWCharArray(wchar_t *array) const | Since Qt5.14 |