forked from qt-creator/qt-creator
ClangFormat: Replace an explicit use of TextCodec with QStringEncoder
Change-Id: I91d7112f614baa3ad76a4cd6139b345bca9ccaa1 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -394,16 +394,17 @@ void ClangFormat::formatAtPosition(const int pos, const int length)
|
|||||||
if (!widget)
|
if (!widget)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const TextCodec codec = widget->textDocument()->codec();
|
const TextEncoding encoding = widget->textDocument()->encoding();
|
||||||
if (!codec.isValid()) {
|
if (!encoding.isValid()) {
|
||||||
formatCurrentFile(textCommand(pos, length));
|
formatCurrentFile(textCommand(pos, length));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString &text = widget->textAt(0, pos + length);
|
const QString &text = widget->textAt(0, pos + length);
|
||||||
const QStringView buffer(text);
|
const QStringView buffer(text);
|
||||||
const int encodedOffset = codec.fromUnicode(buffer.left(pos)).size();
|
QStringEncoder encoder(encoding);
|
||||||
const int encodedLength = codec.fromUnicode(buffer.mid(pos, length)).size();
|
const int encodedOffset = QByteArray(encoder.encode(buffer.left(pos))).size();
|
||||||
|
const int encodedLength = QByteArray(encoder.encode(buffer.mid(pos, length))).size();
|
||||||
formatCurrentFile(textCommand(encodedOffset, encodedLength));
|
formatCurrentFile(textCommand(encodedOffset, encodedLength));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user