Utils: move TextPosition/Range to textutils

Change-Id: Id94a7a96f3b0f978e94850d67eb4b8fba6c18fe2
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
David Schulz
2023-05-09 13:49:57 +02:00
parent fc95d7a737
commit 3f2832289d
11 changed files with 76 additions and 91 deletions

View File

@@ -6,8 +6,37 @@
#include <QTextDocument>
#include <QTextBlock>
namespace Utils {
namespace Text {
namespace Utils::Text {
bool Position::operator==(const Position &other) const
{
return line == other.line && column == other.column;
}
int Range::length(const QString &text) const
{
if (begin.line == end.line)
return end.column - begin.column;
const int lineCount = end.line - begin.line;
int index = text.indexOf(QChar::LineFeed);
int currentLine = 1;
while (index > 0 && currentLine < lineCount) {
++index;
index = text.indexOf(QChar::LineFeed, index);
++currentLine;
}
if (index < 0)
return 0;
return index - begin.column + end.column;
}
bool Range::operator==(const Range &other) const
{
return begin == other.begin && end == other.end;
}
bool convertPosition(const QTextDocument *document, int pos, int *line, int *column)
{
@@ -211,5 +240,4 @@ void applyReplacements(QTextDocument *doc, const Replacements &replacements)
editCursor.endEditBlock();
}
} // Text
} // Utils
} // namespace Utils::Text