diff --git a/src/Character.h b/src/Character.h --- a/src/Character.h +++ b/src/Character.h @@ -57,7 +57,7 @@ * detailed too be drawn cleanly at normal font scales without anti * -aliasing, so those are drawn as regular characters. */ -inline bool isSupportedLineChar(quint16 codePoint) +inline bool isSupportedLineChar(uint codePoint) { return (codePoint & 0xFF80) == 0x2500 // Unicode block: Mathematical Symbols - Box Drawing && !(0x2504 <= codePoint && codePoint <= 0x250B); // Triple and quadruple dash range @@ -82,7 +82,7 @@ * @param _real Indicate whether this character really exists, or exists * simply as place holder. */ - explicit inline Character(quint16 _c = ' ', + explicit inline Character(uint _c = ' ', CharacterColor _f = CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_FORE_COLOR), CharacterColor _b = CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_BACK_COLOR), RenditionFlags _r = DEFAULT_RENDITION, @@ -99,7 +99,7 @@ * look up the unicode character sequence in the ExtendedCharTable used to * create the sequence. */ - quint16 character; + uint character; /** A combination of RENDITION flags which specify options for drawing the character. */ RenditionFlags rendition; diff --git a/src/Emulation.h b/src/Emulation.h --- a/src/Emulation.h +++ b/src/Emulation.h @@ -451,7 +451,7 @@ * Processes an incoming character. See receiveData() * @p c A unicode character code. */ - virtual void receiveChar(int c); + virtual void receiveChar(uint c); /** * Sets the active screen. The terminal has two screens, primary and alternate. diff --git a/src/Emulation.cpp b/src/Emulation.cpp --- a/src/Emulation.cpp +++ b/src/Emulation.cpp @@ -188,7 +188,7 @@ // process application unicode input to terminal // this is a trivial scanner -void Emulation::receiveChar(int c) +void Emulation::receiveChar(uint c) { c &= 0xff; switch (c) { @@ -208,7 +208,7 @@ emit stateSet(NOTIFYBELL); break; default: - _currentScreen->displayCharacter(static_cast(c)); + _currentScreen->displayCharacter(c); break; } } @@ -240,11 +240,11 @@ bufferedUpdate(); - QString unicodeText = _decoder->toUnicode(text, length); + QVector unicodeText = _decoder->toUnicode(text, length).toUcs4(); //send characters to terminal emulator for (auto &&i : unicodeText) { - receiveChar(i.unicode()); + receiveChar(i); } //look for z-modem indicator diff --git a/src/ExtendedCharTable.h b/src/ExtendedCharTable.h --- a/src/ExtendedCharTable.h +++ b/src/ExtendedCharTable.h @@ -29,7 +29,7 @@ /** * A table which stores sequences of unicode characters, referenced * by hash keys. The hash key itself is the same size as a unicode - * character ( ushort ) so that it can occupy the same space in + * character ( uint ) so that it can occupy the same space in * a structure. */ class ExtendedCharTable @@ -50,7 +50,7 @@ * @param unicodePoints An array of unicode character points * @param length Length of @p unicodePoints */ - ushort createExtendedChar(const ushort *unicodePoints, ushort length); + uint createExtendedChar(const uint *unicodePoints, ushort length); /** * Looks up and returns a pointer to a sequence of unicode characters * which was added to the table using createExtendedChar(). @@ -61,20 +61,20 @@ * * @return A unicode character sequence of size @p length. */ - ushort *lookupExtendedChar(ushort hash, ushort &length) const; + uint *lookupExtendedChar(uint hash, ushort &length) const; /** The global ExtendedCharTable instance. */ static ExtendedCharTable instance; private: // calculates the hash key of a sequence of unicode points of size 'length' - ushort extendedCharHash(const ushort *unicodePoints, ushort length) const; + uint extendedCharHash(const uint *unicodePoints, ushort length) const; // tests whether the entry in the table specified by 'hash' matches the // character sequence 'unicodePoints' of size 'length' - bool extendedCharMatch(ushort hash, const ushort *unicodePoints, ushort length) const; - // internal, maps hash keys to character sequence buffers. The first ushort - // in each value is the length of the buffer, followed by the ushorts in the buffer + bool extendedCharMatch(uint hash, const uint *unicodePoints, ushort length) const; + // internal, maps hash keys to character sequence buffers. The first uint + // in each value is the length of the buffer, followed by the uints in the buffer // themselves. - QHash _extendedCharTable; + QHash _extendedCharTable; }; } #endif // end of EXTENDEDCHARTABLE_H diff --git a/src/ExtendedCharTable.cpp b/src/ExtendedCharTable.cpp --- a/src/ExtendedCharTable.cpp +++ b/src/ExtendedCharTable.cpp @@ -33,14 +33,14 @@ using namespace Konsole; ExtendedCharTable::ExtendedCharTable() : - _extendedCharTable(QHash()) + _extendedCharTable(QHash()) { } ExtendedCharTable::~ExtendedCharTable() { // free all allocated character buffers - QHashIterator iter(_extendedCharTable); + QHashIterator iter(_extendedCharTable); while (iter.hasNext()) { iter.next(); delete[] iter.value(); @@ -50,11 +50,11 @@ // global instance ExtendedCharTable ExtendedCharTable::instance; -ushort ExtendedCharTable::createExtendedChar(const ushort *unicodePoints, ushort length) +uint ExtendedCharTable::createExtendedChar(const uint *unicodePoints, ushort length) { // look for this sequence of points in the table - ushort hash = extendedCharHash(unicodePoints, length); - const ushort initialHash = hash; + uint hash = extendedCharHash(unicodePoints, length); + const uint initialHash = hash; bool triedCleaningSolution = false; // check existing entry for match @@ -73,16 +73,16 @@ triedCleaningSolution = true; // All the hashes are full, go to all Screens and try to free any // This is slow but should happen very rarely - QSet usedExtendedChars; + QSet usedExtendedChars; const SessionManager *sm = SessionManager::instance(); foreach (const Session *s, sm->sessions()) { foreach (const TerminalDisplay *td, s->views()) { usedExtendedChars += td->screenWindow()->screen()->usedExtendedChars(); } } - QHash::iterator it = _extendedCharTable.begin(); - QHash::iterator itEnd = _extendedCharTable.end(); + QHash::iterator it = _extendedCharTable.begin(); + QHash::iterator itEnd = _extendedCharTable.end(); while (it != itEnd) { if (usedExtendedChars.contains(it.key())) { ++it; @@ -100,7 +100,7 @@ // add the new sequence to the table and // return that index - auto buffer = new ushort[length + 1]; + auto buffer = new uint[length + 1]; buffer[0] = length; for (int i = 0; i < length; i++) { buffer[i + 1] = unicodePoints[i]; @@ -111,34 +111,34 @@ return hash; } -ushort *ExtendedCharTable::lookupExtendedChar(ushort hash, ushort &length) const +uint *ExtendedCharTable::lookupExtendedChar(uint hash, ushort &length) const { // look up index in table and if found, set the length // argument and return a pointer to the character sequence - ushort *buffer = _extendedCharTable[hash]; + uint *buffer = _extendedCharTable[hash]; if (buffer != nullptr) { - length = buffer[0]; + length = ushort(buffer[0]); return buffer + 1; } else { length = 0; return nullptr; } } -ushort ExtendedCharTable::extendedCharHash(const ushort *unicodePoints, ushort length) const +uint ExtendedCharTable::extendedCharHash(const uint *unicodePoints, ushort length) const { - ushort hash = 0; + uint hash = 0; for (ushort i = 0; i < length; i++) { hash = 31 * hash + unicodePoints[i]; } return hash; } -bool ExtendedCharTable::extendedCharMatch(ushort hash, const ushort *unicodePoints, +bool ExtendedCharTable::extendedCharMatch(uint hash, const uint *unicodePoints, ushort length) const { - ushort *entry = _extendedCharTable[hash]; + uint *entry = _extendedCharTable[hash]; // compare given length with stored sequence length ( given as the first ushort in the // stored buffer ) diff --git a/src/History.h b/src/History.h --- a/src/History.h +++ b/src/History.h @@ -306,7 +306,7 @@ CompactHistoryBlockList &_blockListRef; CharacterFormat *_formatArray; quint16 _length; - quint16 *_text; + uint *_text; quint16 _formatLength; bool _wrapped; }; diff --git a/src/History.cpp b/src/History.cpp --- a/src/History.cpp +++ b/src/History.cpp @@ -453,7 +453,7 @@ ////qDebug() << "number of different formats in string: " << _formatLength; _formatArray = static_cast(_blockListRef.allocate(sizeof(CharacterFormat) * _formatLength)); Q_ASSERT(_formatArray != nullptr); - _text = static_cast(_blockListRef.allocate(sizeof(quint16) * line.size())); + _text = static_cast(_blockListRef.allocate(sizeof(uint) * line.size())); Q_ASSERT(_text != nullptr); _length = line.size(); diff --git a/src/Screen.h b/src/Screen.h --- a/src/Screen.h +++ b/src/Screen.h @@ -360,7 +360,7 @@ * is inserted at the current cursor position, otherwise it will replace the * character already at the current cursor position. */ - void displayCharacter(unsigned short c); + void displayCharacter(uint c); /** * Resizes the image to a new fixed size of @p new_lines by @p new_columns. @@ -581,9 +581,9 @@ return _currentTerminalDisplay; } - QSet usedExtendedChars() const + QSet usedExtendedChars() const { - QSet result; + QSet result; for (int i = 0; i < _lines; ++i) { const ImageLine &il = _screenLines[i]; for (int j = 0; j < il.length(); ++j) { @@ -724,7 +724,7 @@ int _lastPos; // used in REP (repeating char) - unsigned short _lastDrawnChar; + quint32 _lastDrawnChar; }; Q_DECLARE_OPERATORS_FOR_FLAGS(Screen::DecodingOptions) diff --git a/src/Screen.cpp b/src/Screen.cpp --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -684,7 +684,7 @@ } } -void Screen::displayCharacter(unsigned short c) +void Screen::displayCharacter(uint c) { // Note that VT100 does wrapping BEFORE putting the character. // This has impact on the assumption of valid cursor positions. @@ -697,8 +697,8 @@ // Non-printable character return; } else if (w == 0) { - const QChar::Category category = QChar(c).category(); - if (category != QChar::Mark_NonSpacing && category != QChar::Letter_Other && !QChar::isLowSurrogate(c)) { + const QChar::Category category = QChar::category(c); + if (category != QChar::Mark_NonSpacing && category != QChar::Letter_Other) { return; } // Find previous "real character" to try to combine with @@ -723,18 +723,18 @@ Character& currentChar = _screenLines[charToCombineWithY][charToCombineWithX]; if ((currentChar.rendition & RE_EXTENDED_CHAR) == 0) { - const ushort chars[2] = { currentChar.character, c }; + const uint chars[2] = { currentChar.character, c }; currentChar.rendition |= RE_EXTENDED_CHAR; currentChar.character = ExtendedCharTable::instance.createExtendedChar(chars, 2); } else { ushort extendedCharLength; - const ushort* oldChars = ExtendedCharTable::instance.lookupExtendedChar(currentChar.character, extendedCharLength); + const uint* oldChars = ExtendedCharTable::instance.lookupExtendedChar(currentChar.character, extendedCharLength); Q_ASSERT(oldChars); if (((oldChars) != nullptr) && extendedCharLength < 3) { Q_ASSERT(extendedCharLength > 1); Q_ASSERT(extendedCharLength < 65535); - auto chars = new ushort[extendedCharLength + 1]; - memcpy(chars, oldChars, sizeof(ushort) * extendedCharLength); + auto chars = new uint[extendedCharLength + 1]; + memcpy(chars, oldChars, sizeof(uint) * extendedCharLength); chars[extendedCharLength] = c; currentChar.character = ExtendedCharTable::instance.createExtendedChar(chars, extendedCharLength + 1); delete[] chars; @@ -928,7 +928,7 @@ const int topLine = loca / _columns; const int bottomLine = loce / _columns; - Character clearCh(c, _currentForeground, _currentBackground, DEFAULT_RENDITION, false); + Character clearCh(uint(c), _currentForeground, _currentBackground, DEFAULT_RENDITION, false); //if the character being used to clear the area is the same as the //default character, the affected _lines can simply be shrunk. @@ -1093,7 +1093,7 @@ void Screen::setForeColor(int space, int color) { - _currentForeground = CharacterColor(space, color); + _currentForeground = CharacterColor(quint8(space), color); if (_currentForeground.isValid()) { updateEffectiveRendition(); @@ -1104,7 +1104,7 @@ void Screen::setBackColor(int space, int color) { - _currentBackground = CharacterColor(space, color); + _currentBackground = CharacterColor(quint8(space), color); if (_currentBackground.isValid()) { updateEffectiveRendition(); diff --git a/src/TerminalCharacterDecoder.cpp b/src/TerminalCharacterDecoder.cpp --- a/src/TerminalCharacterDecoder.cpp +++ b/src/TerminalCharacterDecoder.cpp @@ -136,9 +136,9 @@ for (int i = start; i < outputCount;) { if ((characters[i].rendition & RE_EXTENDED_CHAR) != 0) { ushort extendedCharLength = 0; - const ushort* chars = ExtendedCharTable::instance.lookupExtendedChar(characters[i].character, extendedCharLength); + const uint* chars = ExtendedCharTable::instance.lookupExtendedChar(characters[i].character, extendedCharLength); if (chars != nullptr) { - const QString s = QString::fromUtf16(chars, extendedCharLength); + const QString s = QString::fromUcs4(chars, extendedCharLength); plainText.append(s); i += qMax(1, string_width(s)); } else { @@ -153,7 +153,7 @@ // lost in some situation. One typical example is copying the result // of `dialog --infobox "qwe" 10 10` . if (characters[i].isRealCharacter || i <= realCharacterGuard) { - plainText.append(QChar(characters[i].character)); + plainText.append(QString::fromUcs4(&characters[i].character, 1)); i += qMax(1, konsole_wcwidth(characters[i].character)); } else { ++i; // should we 'break' directly here? @@ -257,9 +257,9 @@ if (spaceCount < 2) { if ((characters[i].rendition & RE_EXTENDED_CHAR) != 0) { ushort extendedCharLength = 0; - const ushort* chars = ExtendedCharTable::instance.lookupExtendedChar(characters[i].character, extendedCharLength); + const uint* chars = ExtendedCharTable::instance.lookupExtendedChar(characters[i].character, extendedCharLength); if (chars != nullptr) { - text.append(QString::fromUtf16(chars, extendedCharLength)); + text.append(QString::fromUcs4(chars, extendedCharLength)); } } else { //escape HTML tag characters and just display others as they are diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp --- a/src/TerminalDisplay.cpp +++ b/src/TerminalDisplay.cpp @@ -1619,12 +1619,12 @@ } inline static bool isRtl(const Character &chr) { - ushort c = 0; + uint c = 0; if ((chr.rendition & RE_EXTENDED_CHAR) == 0) { c = chr.character; } else { ushort extendedCharLength = 0; - const ushort* chars = ExtendedCharTable::instance.lookupExtendedChar(chr.character, extendedCharLength); + const uint* chars = ExtendedCharTable::instance.lookupExtendedChar(chr.character, extendedCharLength); if (chars != nullptr) { c = chars[0]; } @@ -1654,8 +1654,8 @@ const int rly = qMin(_usedLines - 1, qMax(0, (rect.bottom() - tLy - _contentRect.top()) / _fontHeight)); const int numberOfColumns = _usedColumns; - QString unistr; - unistr.reserve(numberOfColumns); + QVector univec; + univec.reserve(numberOfColumns); for (int y = luy; y <= rly; y++) { int x = lux; if ((_image[loc(lux, y)].character == 0u) && (x != 0)) { @@ -1667,30 +1667,30 @@ // reset our buffer to the number of columns int bufferSize = numberOfColumns; - unistr.resize(bufferSize); - QChar *disstrU = unistr.data(); + univec.resize(bufferSize); + uint *disstrU = univec.data(); // is this a single character or a sequence of characters ? if ((_image[loc(x, y)].rendition & RE_EXTENDED_CHAR) != 0) { // sequence of characters ushort extendedCharLength = 0; - const ushort* chars = ExtendedCharTable::instance.lookupExtendedChar(_image[loc(x, y)].character, extendedCharLength); + const uint* chars = ExtendedCharTable::instance.lookupExtendedChar(_image[loc(x, y)].character, extendedCharLength); if (chars != nullptr) { Q_ASSERT(extendedCharLength > 1); bufferSize += extendedCharLength - 1; - unistr.resize(bufferSize); - disstrU = unistr.data(); + univec.resize(bufferSize); + disstrU = univec.data(); for (int index = 0 ; index < extendedCharLength ; index++) { Q_ASSERT(p < bufferSize); disstrU[p++] = chars[index]; } } } else { // single character - const quint16 c = _image[loc(x, y)].character; + const uint c = _image[loc(x, y)].character; if (c != 0u) { Q_ASSERT(p < bufferSize); - disstrU[p++] = c; //fontMap(c); + disstrU[p++] = c; } } @@ -1709,16 +1709,16 @@ (_image[qMin(loc(x + len, y) + 1, _imageSize - 1)].character == 0) == doubleWidth && _image[loc(x + len, y)].isLineChar() == lineDraw && (_image[loc(x + len, y)].character <= 0x7e || rtl)) { - const quint16 c = _image[loc(x + len, y)].character; + const uint c = _image[loc(x + len, y)].character; if ((_image[loc(x + len, y)].rendition & RE_EXTENDED_CHAR) != 0) { // sequence of characters ushort extendedCharLength = 0; - const ushort* chars = ExtendedCharTable::instance.lookupExtendedChar(c, extendedCharLength); + const uint* chars = ExtendedCharTable::instance.lookupExtendedChar(c, extendedCharLength); if (chars != nullptr) { Q_ASSERT(extendedCharLength > 1); bufferSize += extendedCharLength - 1; - unistr.resize(bufferSize); - disstrU = unistr.data(); + univec.resize(bufferSize); + disstrU = univec.data(); for (int index = 0 ; index < extendedCharLength ; index++) { Q_ASSERT(p < bufferSize); disstrU[p++] = chars[index]; @@ -1728,7 +1728,7 @@ // single character if (c != 0u) { Q_ASSERT(p < bufferSize); - disstrU[p++] = c; //fontMap(c); + disstrU[p++] = c; } } @@ -1749,7 +1749,7 @@ if (doubleWidth) { _fixedFont = false; } - unistr.resize(p); + univec.resize(p); // Create a text scaling matrix for double width and double height lines. QMatrix textScale; @@ -1778,6 +1778,8 @@ //(instead of textArea.topLeft() * painter-scale) textArea.moveTopLeft(textScale.inverted().map(textArea.topLeft())); + QString unistr = QString::fromUcs4(univec.data(), univec.length()); + //paint text fragment if (_printerFriendly) { drawPrinterFriendlyTextFragment(paint, @@ -3150,9 +3152,9 @@ { if ((ch.rendition & RE_EXTENDED_CHAR) != 0) { ushort extendedCharLength = 0; - const ushort* chars = ExtendedCharTable::instance.lookupExtendedChar(ch.character, extendedCharLength); + const uint* chars = ExtendedCharTable::instance.lookupExtendedChar(ch.character, extendedCharLength); if ((chars != nullptr) && extendedCharLength > 0) { - const QString s = QString::fromUtf16(chars, extendedCharLength); + const QString s = QString::fromUcs4(chars, extendedCharLength); if (_wordCharacters.contains(s, Qt::CaseInsensitive)) { return QLatin1Char('a'); } diff --git a/src/Vt102Emulation.h b/src/Vt102Emulation.h --- a/src/Vt102Emulation.h +++ b/src/Vt102Emulation.h @@ -100,15 +100,15 @@ // reimplemented from Emulation void setMode(int mode) Q_DECL_OVERRIDE; void resetMode(int mode) Q_DECL_OVERRIDE; - void receiveChar(int cc) Q_DECL_OVERRIDE; + void receiveChar(uint cc) Q_DECL_OVERRIDE; private Q_SLOTS: //causes changeTitle() to be emitted for each (int,QString) pair in pendingTitleUpdates //used to buffer multiple title updates void updateTitle(); private: - unsigned short applyCharset(unsigned short c); + unsigned int applyCharset(uint c); void setCharset(int n, int cs); void useCharset(int n); void setAndUseCharset(int n, int cs); diff --git a/src/Vt102Emulation.cpp b/src/Vt102Emulation.cpp --- a/src/Vt102Emulation.cpp +++ b/src/Vt102Emulation.cpp @@ -352,7 +352,7 @@ const int SP = 32; // process an incoming unicode character -void Vt102Emulation::receiveChar(int cc) +void Vt102Emulation::receiveChar(uint cc) { if (cc == DEL) { return; //VT100: ignore. @@ -1258,7 +1258,7 @@ // Apply current character map. -unsigned short Vt102Emulation::applyCharset(unsigned short c) +unsigned int Vt102Emulation::applyCharset(uint c) { if (CHARSET.graphic && 0x5f <= c && c <= 0x7e) { return vt100_graphics[c - 0x5f]; diff --git a/src/autotests/CharacterWidthTest.cpp b/src/autotests/CharacterWidthTest.cpp --- a/src/autotests/CharacterWidthTest.cpp +++ b/src/autotests/CharacterWidthTest.cpp @@ -30,39 +30,39 @@ void CharacterWidthTest::testWidth_data() { - QTest::addColumn("character"); + QTest::addColumn("character"); QTest::addColumn("width"); /* This is a work in progress.... */ /* konsole_wcwidth uses -1 C0/C1 and DEL */ - QTest::newRow("0xE007F") << quint16(0xE007F) << -1; - - QTest::newRow("0x0300") << quint16(0x0300) << 0; - QTest::newRow("0x070F") << quint16(0x070F) << 0; - QTest::newRow("0x1160") << quint16(0x1160) << 0; - QTest::newRow("0x10300") << quint16(0x10300) << 0; - - QTest::newRow("a") << quint16('a') << 1; - QTest::newRow("0x00AD") << quint16(0x00AD) << 1; - QTest::newRow("0x00A0") << quint16(0x00A0) << 1; - QTest::newRow("0x10FB") << quint16(0x10FB) << 1; - QTest::newRow("0xFF76") << quint16(0xFF76) << 1; - QTest::newRow("0x103A0") << quint16(0x103A0) << 1; - QTest::newRow("0x10A06") << quint16(0x10A06) << 1; - - QTest::newRow("0x3000") << quint16(0x3000) << 2; - QTest::newRow("0x300a") << quint16(0x300a) << 2; - QTest::newRow("0x300b") << quint16(0x300b) << 2; - QTest::newRow("0xFF01") << quint16(0xFF01) << 2; - QTest::newRow("0xFF5F") << quint16(0xFF5F) << 2; - QTest::newRow("0xFF60") << quint16(0xFF60) << 2; - QTest::newRow("0xFFe0") << quint16(0xFFe6) << 2; + QTest::newRow("0x007F") << uint(0x007F) << -1; + + QTest::newRow("0x0300") << uint(0x0300) << 0; + QTest::newRow("0x070F") << uint(0x070F) << 0; + QTest::newRow("0x1160") << uint(0x1160) << 0; + QTest::newRow("0x10300") << uint(0x10300) << 1; + + QTest::newRow("a") << uint('a') << 1; + QTest::newRow("0x00AD") << uint(0x00AD) << 1; + QTest::newRow("0x00A0") << uint(0x00A0) << 1; + QTest::newRow("0x10FB") << uint(0x10FB) << 1; + QTest::newRow("0xFF76") << uint(0xFF76) << 1; + QTest::newRow("0x103A0") << uint(0x103A0) << 1; + QTest::newRow("0x10A06") << uint(0x10A06) << 0; + + QTest::newRow("0x3000") << uint(0x3000) << 2; + QTest::newRow("0x300a") << uint(0x300a) << 2; + QTest::newRow("0x300b") << uint(0x300b) << 2; + QTest::newRow("0xFF01") << uint(0xFF01) << 2; + QTest::newRow("0xFF5F") << uint(0xFF5F) << 2; + QTest::newRow("0xFF60") << uint(0xFF60) << 2; + QTest::newRow("0xFFe0") << uint(0xFFe6) << 2; } void CharacterWidthTest::testWidth() { - QFETCH(quint16, character); + QFETCH(uint, character); QTEST(konsole_wcwidth(character), "width"); } diff --git a/src/konsole_wcwidth.h b/src/konsole_wcwidth.h --- a/src/konsole_wcwidth.h +++ b/src/konsole_wcwidth.h @@ -9,7 +9,7 @@ // Qt #include -int konsole_wcwidth(quint16 oucs); +int konsole_wcwidth(uint ucs); int string_width(const QString &text); diff --git a/src/konsole_wcwidth.cpp b/src/konsole_wcwidth.cpp --- a/src/konsole_wcwidth.cpp +++ b/src/konsole_wcwidth.cpp @@ -73,6 +73,9 @@ #include "konsole_wcwidth.h" #include "konsoleprivate_export.h" +// Qt +#include + struct interval { unsigned long first; unsigned long last; @@ -130,12 +133,8 @@ * in ISO 10646. */ -int KONSOLEPRIVATE_EXPORT konsole_wcwidth(quint16 oucs) +int KONSOLEPRIVATE_EXPORT konsole_wcwidth(uint ucs) { - /* NOTE: It is not possible to compare quint16 with the new last four lines of characters, - * therefore this cast is now necessary. - */ - unsigned long ucs = static_cast(oucs); /* sorted list of non-overlapping intervals of non-spacing characters */ /* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */ static const struct interval combining[] = { @@ -230,8 +229,9 @@ int string_width(const QString& text) { int w = 0; - for (auto i : text) { - w += konsole_wcwidth(i.unicode()); + auto ucs4 = text.toUcs4(); + for (auto i : ucs4) { + w += konsole_wcwidth(i); } return w; }