1// Copyright (C) 2021 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 TEXT_H
5#define TEXT_H
6
7#include "atom.h"
8
9QT_BEGIN_NAMESPACE
10
11class Text
12{
13public:
14 Text();
15 explicit Text(const QString &str);
16 Text(const Text &text);
17 ~Text();
18
19 Text &operator=(const Text &text);
20
21 Atom *firstAtom() { return m_first; }
22 Atom *lastAtom() { return m_last; }
23 Text &operator<<(Atom::AtomType atomType);
24 Text &operator<<(const QString &string);
25 Text &operator<<(const Atom &atom);
26 Text &operator<<(const LinkAtom &atom);
27 Text &operator<<(const Text &text);
28 void stripFirstAtom();
29 void stripLastAtom();
30
31 [[nodiscard]] bool isEmpty() const { return m_first == nullptr; }
32 [[nodiscard]] bool contains(const QString &str) const;
33 [[nodiscard]] QString toString() const;
34 [[nodiscard]] const Atom *firstAtom() const { return m_first; }
35 [[nodiscard]] const Atom *lastAtom() const { return m_last; }
36 Text subText(Atom::AtomType left, Atom::AtomType right, const Atom *from = nullptr,
37 bool inclusive = false) const;
38 void dump() const;
39 void clear();
40
41 static Text subText(const Atom *begin, const Atom *end = nullptr);
42 static Text sectionHeading(const Atom *sectionBegin);
43 static int compare(const Text &text1, const Text &text2);
44
45private:
46 Atom *m_first { nullptr };
47 Atom *m_last { nullptr };
48};
49
50inline bool operator==(const Text &text1, const Text &text2)
51{
52 return Text::compare(text1, text2) == 0;
53}
54inline bool operator!=(const Text &text1, const Text &text2)
55{
56 return Text::compare(text1, text2) != 0;
57}
58inline bool operator<(const Text &text1, const Text &text2)
59{
60 return Text::compare(text1, text2) < 0;
61}
62inline bool operator<=(const Text &text1, const Text &text2)
63{
64 return Text::compare(text1, text2) <= 0;
65}
66inline bool operator>(const Text &text1, const Text &text2)
67{
68 return Text::compare(text1, text2) > 0;
69}
70inline bool operator>=(const Text &text1, const Text &text2)
71{
72 return Text::compare(text1, text2) >= 0;
73}
74
75QT_END_NAMESPACE
76
77#endif
78

source code of qttools/src/qdoc/qdoc/text.h