forked from qt-creator/qt-creator
Utils: use Text::Position instead of LineColumn in textutils
Change-Id: I606b0b4f8106bdb2f97383d6c81ac065e7e61858 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -47,6 +47,15 @@ Position Position::fromFileName(QStringView fileName, int &postfixPos)
|
||||
return pos;
|
||||
}
|
||||
|
||||
Position Position::fromPositionInDocument(const QTextDocument *document, int pos)
|
||||
{
|
||||
const QTextBlock block = document->findBlock(pos);
|
||||
if (block.isValid())
|
||||
return {block.blockNumber() + 1, pos - block.position()};
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
int Range::length(const QString &text) const
|
||||
{
|
||||
if (begin.line == end.line)
|
||||
@@ -87,15 +96,6 @@ bool convertPosition(const QTextDocument *document, int pos, int *line, int *col
|
||||
}
|
||||
}
|
||||
|
||||
LineColumn convertPosition(const QTextDocument *document, int pos)
|
||||
{
|
||||
const QTextBlock block = document->findBlock(pos);
|
||||
if (block.isValid())
|
||||
return {block.blockNumber() + 1, pos - block.position()};
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
int positionInText(const QTextDocument *textDocument, int line, int column)
|
||||
{
|
||||
// Deduct 1 from line and column since they are 1-based.
|
||||
@@ -201,20 +201,6 @@ int utf8NthLineOffset(const QTextDocument *textDocument, const QByteArray &buffe
|
||||
return utf8Offset;
|
||||
}
|
||||
|
||||
LineColumn utf16LineColumn(const QByteArray &utf8Buffer, int utf8Offset)
|
||||
{
|
||||
LineColumn lineColumn;
|
||||
lineColumn.line = static_cast<int>(
|
||||
std::count(utf8Buffer.begin(), utf8Buffer.begin() + utf8Offset, '\n'))
|
||||
+ 1;
|
||||
const int startOfLineOffset = utf8Offset ? (utf8Buffer.lastIndexOf('\n', utf8Offset - 1) + 1)
|
||||
: 0;
|
||||
lineColumn.column = QString::fromUtf8(
|
||||
utf8Buffer.mid(startOfLineOffset, utf8Offset - startOfLineOffset))
|
||||
.length();
|
||||
return lineColumn;
|
||||
}
|
||||
|
||||
QString utf16LineTextInUtf8Buffer(const QByteArray &utf8Buffer, int currentUtf8Offset)
|
||||
{
|
||||
const int lineStartUtf8Offset = currentUtf8Offset
|
||||
|
||||
Reference in New Issue
Block a user