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