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   text.h
31 */
32 
33 #ifndef TEXT_H
34 #define TEXT_H
35 
36 #include "atom.h"
37 
38 QT_BEGIN_NAMESPACE
39 
40 class Text
41 {
42 public:
43     Text();
44     explicit Text(const QString &str);
45     Text(const Text &text);
46     ~Text();
47 
48     Text &operator=(const Text &text);
49 
firstAtom()50     Atom *firstAtom() { return first; }
lastAtom()51     Atom *lastAtom() { return last; }
52     Text &operator<<(Atom::AtomType atomType);
53     Text &operator<<(const QString &string);
54     Text &operator<<(const Atom &atom);
55     Text &operator<<(const LinkAtom &atom);
56     Text &operator<<(const Text &text);
57     void stripFirstAtom();
58     void stripLastAtom();
59 
isEmpty()60     bool isEmpty() const { return first == nullptr; }
61     bool contains(const QString &str) const;
62     QString toString() const;
firstAtom()63     const Atom *firstAtom() const { return first; }
lastAtom()64     const Atom *lastAtom() const { return last; }
65     Text subText(Atom::AtomType left, Atom::AtomType right, const Atom *from = nullptr,
66                  bool inclusive = false) const;
67     void dump() const;
68     void clear();
69 
70     static Text subText(const Atom *begin, const Atom *end = nullptr);
71     static Text sectionHeading(const Atom *sectionBegin);
72     static const Atom *sectionHeadingAtom(const Atom *sectionLeft);
73     static int compare(const Text &text1, const Text &text2);
74 
75 private:
76     Atom *first;
77     Atom *last;
78 };
79 
80 inline bool operator==(const Text &text1, const Text &text2)
81 {
82     return Text::compare(text1, text2) == 0;
83 }
84 inline bool operator!=(const Text &text1, const Text &text2)
85 {
86     return Text::compare(text1, text2) != 0;
87 }
88 inline bool operator<(const Text &text1, const Text &text2)
89 {
90     return Text::compare(text1, text2) < 0;
91 }
92 inline bool operator<=(const Text &text1, const Text &text2)
93 {
94     return Text::compare(text1, text2) <= 0;
95 }
96 inline bool operator>(const Text &text1, const Text &text2)
97 {
98     return Text::compare(text1, text2) > 0;
99 }
100 inline bool operator>=(const Text &text1, const Text &text2)
101 {
102     return Text::compare(text1, text2) >= 0;
103 }
104 
105 QT_END_NAMESPACE
106 
107 #endif
108