1 /****************************************************************************
2 **
3 ** Copyright (C) 2019 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the tools applications of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 /*
30   codechunk.h
31 */
32 
33 #ifndef CODECHUNK_H
34 #define CODECHUNK_H
35 
36 #include <QtCore/qstring.h>
37 
38 QT_BEGIN_NAMESPACE
39 
40 // ### get rid of that class
41 
42 class CodeChunk
43 {
44 public:
CodeChunk()45     CodeChunk() : hotspot(-1) {}
CodeChunk(const QString & str)46     CodeChunk(const QString &str) : s(str), hotspot(-1) {}
47 
48     void append(const QString &lexeme);
appendHotspot()49     void appendHotspot()
50     {
51         if (hotspot == -1)
52             hotspot = s.length();
53     }
54 
isEmpty()55     bool isEmpty() const { return s.isEmpty(); }
clear()56     void clear() { s.clear(); }
toString()57     QString toString() const { return s; }
58     QStringList toPath() const;
left()59     QString left() const { return s.left(hotspot == -1 ? s.length() : hotspot); }
right()60     QString right() const { return s.mid(hotspot == -1 ? s.length() : hotspot); }
61 
62 private:
63     QString s;
64     int hotspot;
65 };
66 
67 inline bool operator==(const CodeChunk &c, const CodeChunk &d)
68 {
69     return c.toString() == d.toString();
70 }
71 
72 inline bool operator!=(const CodeChunk &c, const CodeChunk &d)
73 {
74     return !(c == d);
75 }
76 
77 inline bool operator<(const CodeChunk &c, const CodeChunk &d)
78 {
79     return c.toString() < d.toString();
80 }
81 
82 inline bool operator>(const CodeChunk &c, const CodeChunk &d)
83 {
84     return d < c;
85 }
86 
87 inline bool operator<=(const CodeChunk &c, const CodeChunk &d)
88 {
89     return !(c > d);
90 }
91 
92 inline bool operator>=(const CodeChunk &c, const CodeChunk &d)
93 {
94     return !(c < d);
95 }
96 
97 QT_END_NAMESPACE
98 
99 #endif
100