diff options
author | David Schulz <david.schulz@qt.io> | 2023-05-09 13:49:57 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2023-05-10 09:32:39 +0000 |
commit | 3f2832289de7a1069937275d22b02c03aabe8776 (patch) | |
tree | ba346c128bc44bc83984893173e22cfc61cd747e /src/libs/utils/textutils.h | |
parent | fc95d7a73730f67584891471d912dfd7f65a9cc2 (diff) |
Utils: move TextPosition/Range to textutils
Change-Id: Id94a7a96f3b0f978e94850d67eb4b8fba6c18fe2
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'src/libs/utils/textutils.h')
-rw-r--r-- | src/libs/utils/textutils.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libs/utils/textutils.h b/src/libs/utils/textutils.h index e214f74659..ce8a450302 100644 --- a/src/libs/utils/textutils.h +++ b/src/libs/utils/textutils.h @@ -17,6 +17,34 @@ QT_END_NAMESPACE namespace Utils { namespace Text { +class QTCREATOR_UTILS_EXPORT Position +{ +public: + int line = 0; // 1-based + int column = -1; // 0-based + + bool operator<(const Position &other) const + { return line < other.line || (line == other.line && column < other.column); } + bool operator==(const Position &other) const; + + bool operator!=(const Position &other) const { return !(operator==(other)); } +}; + +class QTCREATOR_UTILS_EXPORT Range +{ +public: + QString mid(const QString &text) const { return text.mid(begin.column, length(text)); } + int length(const QString &text) const; + + Position begin; + Position end; + + bool operator<(const Range &other) const { return begin < other.begin; } + bool operator==(const Range &other) const; + + bool operator!=(const Range &other) const { return !(operator==(other)); } +}; + struct Replacement { Replacement() = default; @@ -66,3 +94,5 @@ QTCREATOR_UTILS_EXPORT QString utf16LineTextInUtf8Buffer(const QByteArray &utf8B } // Text } // Utils + +Q_DECLARE_METATYPE(Utils::Text::Position) |