Qt6: Port QtWayland from QStringRef to QStringView
Task-number: QTBUG-84319 Change-Id: I5dc2f4506c149e5f2793cd7cab083278b93a980e Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
9ef67d0769
commit
132579d38c
@ -307,7 +307,7 @@ void QWaylandWindow::setWindowTitle(const QString &title)
|
|||||||
// three bytes when converted to utf-8 (which is what libwayland uses), so divide by three.
|
// three bytes when converted to utf-8 (which is what libwayland uses), so divide by three.
|
||||||
const int maxLength = libwaylandMaxBufferSize / 3 - 100;
|
const int maxLength = libwaylandMaxBufferSize / 3 - 100;
|
||||||
|
|
||||||
auto truncated = QStringRef(&formatted).left(maxLength);
|
auto truncated = QStringView{formatted}.left(maxLength);
|
||||||
if (truncated.length() < formatted.length()) {
|
if (truncated.length() < formatted.length()) {
|
||||||
qCWarning(lcQpaWayland) << "Window titles longer than" << maxLength << "characters are not supported."
|
qCWarning(lcQpaWayland) << "Window titles longer than" << maxLength << "characters are not supported."
|
||||||
<< "Truncating window title (from" << formatted.length() << "chars)";
|
<< "Truncating window title (from" << formatted.length() << "chars)";
|
||||||
|
@ -265,17 +265,17 @@ int QWaylandInputMethodEventBuilder::indexFromWayland(const QString &text, int l
|
|||||||
return base;
|
return base;
|
||||||
|
|
||||||
if (length < 0) {
|
if (length < 0) {
|
||||||
const QByteArray &utf8 = text.leftRef(base).toUtf8();
|
const QByteArray &utf8 = QStringView{text}.left(base).toUtf8();
|
||||||
return QString::fromUtf8(utf8.left(qMax(utf8.length() + length, 0))).length();
|
return QString::fromUtf8(utf8.left(qMax(utf8.length() + length, 0))).length();
|
||||||
} else {
|
} else {
|
||||||
const QByteArray &utf8 = text.midRef(base).toUtf8();
|
const QByteArray &utf8 = QStringView{text}.mid(base).toUtf8();
|
||||||
return QString::fromUtf8(utf8.left(length)).length() + base;
|
return QString::fromUtf8(utf8.left(length)).length() + base;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int QWaylandInputMethodEventBuilder::indexToWayland(const QString &text, int length, int base)
|
int QWaylandInputMethodEventBuilder::indexToWayland(const QString &text, int length, int base)
|
||||||
{
|
{
|
||||||
return text.midRef(base, length).toUtf8().size();
|
return QStringView{text}.mid(base, length).toUtf8().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user