| 1 | // Copyright (C) 2019 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
| 3 | |
| 4 | #ifndef CODECHUNK_H |
| 5 | #define CODECHUNK_H |
| 6 | |
| 7 | #include <QtCore/qstring.h> |
| 8 | |
| 9 | QT_BEGIN_NAMESPACE |
| 10 | |
| 11 | // ### get rid of that class |
| 12 | |
| 13 | class CodeChunk |
| 14 | { |
| 15 | public: |
| 16 | CodeChunk() : m_hotspot(-1) { } |
| 17 | |
| 18 | void append(const QString &lexeme); |
| 19 | void appendHotspot() |
| 20 | { |
| 21 | if (m_hotspot == -1) |
| 22 | m_hotspot = m_str.size(); |
| 23 | } |
| 24 | |
| 25 | [[nodiscard]] bool isEmpty() const { return m_str.isEmpty(); } |
| 26 | void clear() { m_str.clear(); } |
| 27 | [[nodiscard]] QString toString() const { return m_str; } |
| 28 | [[nodiscard]] QString left() const |
| 29 | { |
| 30 | return m_str.left(n: m_hotspot == -1 ? m_str.size() : m_hotspot); |
| 31 | } |
| 32 | [[nodiscard]] QString right() const |
| 33 | { |
| 34 | return m_str.mid(position: m_hotspot == -1 ? m_str.size() : m_hotspot); |
| 35 | } |
| 36 | |
| 37 | private: |
| 38 | QString m_str {}; |
| 39 | qsizetype m_hotspot {}; |
| 40 | }; |
| 41 | |
| 42 | inline bool operator==(const CodeChunk &c, const CodeChunk &d) |
| 43 | { |
| 44 | return c.toString() == d.toString(); |
| 45 | } |
| 46 | |
| 47 | inline bool operator!=(const CodeChunk &c, const CodeChunk &d) |
| 48 | { |
| 49 | return !(c == d); |
| 50 | } |
| 51 | |
| 52 | inline bool operator<(const CodeChunk &c, const CodeChunk &d) |
| 53 | { |
| 54 | return c.toString() < d.toString(); |
| 55 | } |
| 56 | |
| 57 | inline bool operator>(const CodeChunk &c, const CodeChunk &d) |
| 58 | { |
| 59 | return d < c; |
| 60 | } |
| 61 | |
| 62 | inline bool operator<=(const CodeChunk &c, const CodeChunk &d) |
| 63 | { |
| 64 | return !(c > d); |
| 65 | } |
| 66 | |
| 67 | inline bool operator>=(const CodeChunk &c, const CodeChunk &d) |
| 68 | { |
| 69 | return !(c < d); |
| 70 | } |
| 71 | |
| 72 | QT_END_NAMESPACE |
| 73 | |
| 74 | #endif |
| 75 |
