diff options
author | Jan Arne Petersen <jan.petersen@kdab.com> | 2016-04-18 21:44:57 +0200 |
---|---|---|
committer | Jan Arne Petersen <jan.petersen@kdab.com> | 2016-04-19 08:44:50 +0000 |
commit | c5ab939aa4f2683c7be61e9b788d50526b811ab8 (patch) | |
tree | 168241f2366ce9c74510a91e984a3c219c2f8b47 /src/shared/qwaylandinputmethodeventbuilder.cpp | |
parent | bc9eac9800811417697bebf35c5f11b0e852d123 (diff) | |
download | qtwayland-c5ab939aa4f2683c7be61e9b788d50526b811ab8.tar.gz |
Use function to convert indices for text protocol
Use a proper function instead of left/midRef(index).toUtf8().size().
Makes it more clear what is happening and makes it easier when wayland
text protocol switches from byte-based to unicode character-based indices.
Also rename parameters of existing indexFromWayland() function to be the
same as in the new function.
Change-Id: Ie90abdcb264b74a024e96e041d5daf651920e9e4
Reviewed-by: Giulio Camuffo <giulio.camuffo@kdab.com>
Diffstat (limited to 'src/shared/qwaylandinputmethodeventbuilder.cpp')
-rw-r--r-- | src/shared/qwaylandinputmethodeventbuilder.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/shared/qwaylandinputmethodeventbuilder.cpp b/src/shared/qwaylandinputmethodeventbuilder.cpp index eb527c15..fe93f514 100644 --- a/src/shared/qwaylandinputmethodeventbuilder.cpp +++ b/src/shared/qwaylandinputmethodeventbuilder.cpp @@ -268,19 +268,24 @@ QWaylandInputMethodContentType QWaylandInputMethodContentType::convert(Qt::Input return QWaylandInputMethodContentType{hint, purpose}; } -int QWaylandInputMethodEventBuilder::indexFromWayland(const QString &str, int utf8Index, int baseIndex) +int QWaylandInputMethodEventBuilder::indexFromWayland(const QString &text, int length, int base) { - if (utf8Index == 0) - return baseIndex; + if (length == 0) + return base; - if (utf8Index < 0) { - const QByteArray &utf8 = str.leftRef(baseIndex).toUtf8(); - return QString::fromUtf8(utf8.left(qMax(utf8.length() + utf8Index, 0))).length(); + if (length < 0) { + const QByteArray &utf8 = text.leftRef(base).toUtf8(); + return QString::fromUtf8(utf8.left(qMax(utf8.length() + length, 0))).length(); } else { - const QByteArray &utf8 = str.midRef(baseIndex).toUtf8(); - return QString::fromUtf8(utf8.left(utf8Index)).length() + baseIndex; + const QByteArray &utf8 = text.midRef(base).toUtf8(); + return QString::fromUtf8(utf8.left(length)).length() + base; } } +int QWaylandInputMethodEventBuilder::indexToWayland(const QString &text, int length, int base) +{ + return text.midRef(base, length).toUtf8().size(); +} + QT_END_NAMESPACE |