aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/textutils.cpp
diff options
context:
space:
mode:
authorDavid Schulz <[email protected]>2023-05-09 13:49:57 +0200
committerDavid Schulz <[email protected]>2023-05-10 09:32:39 +0000
commit3f2832289de7a1069937275d22b02c03aabe8776 (patch)
treeba346c128bc44bc83984893173e22cfc61cd747e /src/libs/utils/textutils.cpp
parentfc95d7a73730f67584891471d912dfd7f65a9cc2 (diff)
Utils: move TextPosition/Range to textutils
Change-Id: Id94a7a96f3b0f978e94850d67eb4b8fba6c18fe2 Reviewed-by: Jarek Kobus <[email protected]>
Diffstat (limited to 'src/libs/utils/textutils.cpp')
-rw-r--r--src/libs/utils/textutils.cpp36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/libs/utils/textutils.cpp b/src/libs/utils/textutils.cpp
index 1222038039f..ec440a8902a 100644
--- a/src/libs/utils/textutils.cpp
+++ b/src/libs/utils/textutils.cpp
@@ -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